Windows NT 4.0 source code leak
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.

253 lines
5.7 KiB

4 years ago
  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. stgen.cxx
  5. Abstract:
  6. structure marshalling / unmarshalling stuff.
  7. Notes:
  8. History:
  9. Dec-15-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_STRUCT::GenMarshall(
  28. CCB * pCCB )
  29. {
  30. expr_node * pSrc = pCCB->GetSourceExpression();
  31. expr_node * pDest = pCCB->GetDestExpression();
  32. STM_ACTION Action;
  33. CG_NDR * pCG;
  34. if( !pCCB->IsRefAllocDone() )
  35. {
  36. pSrc = MakeAddressExpressionNoMatterWhat( pSrc );
  37. }
  38. if( IsOffline() )
  39. {
  40. // Generate a call to the structure marshall off line rtn.
  41. expr_node * pStubMsg = pCCB->GetStandardResource(
  42. ST_RES_STUB_MESSAGE_VARIABLE );
  43. pStubMsg = MakeAddressExpressionNoMatterWhat( pStubMsg );
  44. PNAME pProcName = MakeRtnName(
  45. 0, GetType()->GetSymName(), NC_MARSHALL_RTN_NAME );
  46. expr_proc_call * pProc = new expr_proc_call( pProcName, 0 );
  47. // Make the call.
  48. pCCB->GetStream()->NewLine();
  49. pProc->SetParam( new expr_param( pStubMsg ) );
  50. pProc->SetParam( new expr_param( pSrc ));
  51. pProc->PrintCall( pCCB->GetStream(), 0, 0);
  52. }
  53. else
  54. {
  55. pCCB->Position( GetWireAlignment(), &Action );
  56. Out_AlignmentOrAddAction( pCCB, pDest, Action );
  57. Out_Copy( pCCB,
  58. pDest,
  59. pSrc,
  60. new expr_constant( GetMemorySize() ),
  61. pDest );
  62. // Get to the actual final alignment by walking thru each of the fields
  63. // of the structure.
  64. pCG = (CG_NDR *) GetChild();
  65. while( pCG )
  66. {
  67. pCCB->Advance( pCG->GetWireAlignment(),0,0,0 );
  68. pCG = (CG_NDR *)pCG->GetSibling();
  69. }
  70. // FOR NOW:: The state machine needs to be modified to recognize
  71. // an intermediate align by 2, which the machine will enter when
  72. // current alignment is 4 and next marshall is a 2. For now, A
  73. // structure will result in worst case alignment state.
  74. pCCB->SetCurAlignmentState( MAKE_WC_ALIGNMENT( AL_1 ) );
  75. }
  76. return CG_OK;
  77. }
  78. CG_STATUS
  79. CG_STRUCT::GenSizing(
  80. CCB * pCCB )
  81. {
  82. char * pProcName;
  83. // if the structure needs to be sized off line, call the sizing
  84. // routine.
  85. if( IsOffline() )
  86. {
  87. expr_node * pSrc = pCCB->GetSourceExpression();
  88. expr_node * pLengthResource =
  89. pCCB->GetStandardResource( ST_RES_LENGTH_VARIABLE );
  90. // If a pointer to the structure is not avlbl, make an address
  91. // expression.
  92. if( !pCCB->IsRefAllocDone() )
  93. {
  94. pSrc = MakeAddressExpressionNoMatterWhat( pSrc );
  95. }
  96. // Generate a procedure call for the aux routine.
  97. pProcName = MakeRtnName( 0, GetType()->GetSymName(), NC_SIZE_RTN_NAME );
  98. expr_proc_call * pProc = new expr_proc_call( pProcName, 0 );
  99. pProc->SetParam( new expr_param( pSrc) );
  100. pProc->SetParam( new expr_param( pLengthResource ) );
  101. Out_PlusEquals( pCCB, pLengthResource, pProc );
  102. }
  103. return CG_OK;
  104. }
  105. CG_STATUS
  106. CG_STRUCT::GenFree(
  107. CCB * pCCB )
  108. {
  109. return CG_OK;
  110. }
  111. CG_STATUS
  112. CG_STRUCT::GenUnMarshall(
  113. CCB * pCCB )
  114. {
  115. return CG_OK;
  116. }
  117. CG_STATUS
  118. CG_COMP::S_GenInitOutLocals(
  119. CCB * pCCB )
  120. {
  121. char Buffer[ 256 ];
  122. RESOURCE * pResource;
  123. PNAME p;
  124. CG_NDR * pLPC = pCCB->GetLastPlaceholderClass();
  125. sprintf( Buffer, "%s", pLPC->GetType()->GetSymName() );
  126. p = pCCB->GenTRNameOffLastParam( Buffer );
  127. pResource = pCCB->GetLocalResource( p );
  128. // There is a pointer for the top level structure.
  129. Out_Assign( pCCB,
  130. pCCB->GetSourceExpression(),
  131. MakeAddressExpressionNoMatterWhat( pResource )
  132. );
  133. // Go zero out the pointers in the structure, for now.
  134. if( HasPointer() )
  135. {
  136. ITERATOR I;
  137. CG_FIELD * pCG;
  138. expr_node * pSrc = pCCB->GetSourceExpression();
  139. // Get all the members in the struct which contain pointers. If the
  140. // structure has been unrolled by the format string generator, the
  141. // print prefix contains the proper prefixed part of the unrolled path,
  142. // we just have to add the field name to it.
  143. GetPointerMembers( I );
  144. while( ITERATOR_GETNEXT( I, pCG ) )
  145. {
  146. char * pVarName =
  147. new char[ strlen( ((CG_FIELD *)pCG)->GetPrintPrefix())+
  148. strlen( pCG->GetType()->GetSymName()) +
  149. 1
  150. ];
  151. strcpy( pVarName, ((CG_FIELD *)pCG)->GetPrintPrefix() );
  152. strcat( pVarName, pCG->GetType()->GetSymName() );
  153. expr_node * pExpr = new expr_pointsto(
  154. pSrc,
  155. new expr_variable( pVarName, 0 ));
  156. expr_node * pAss = new expr_assign(pExpr, new expr_constant(0L));
  157. pCCB->GetStream()->NewLine();
  158. pAss->PrintCall( pCCB->GetStream(), 0, 0 );
  159. pCCB->GetStream()->Write(';');
  160. // this memory area is no longer useful.
  161. delete pVarName;
  162. }
  163. }
  164. return CG_OK;
  165. }
  166. short
  167. CG_COMP::GetPointerMembers(
  168. ITERATOR& I )
  169. {
  170. CG_ITERATOR M;
  171. CG_FIELD * pField;
  172. short Count = 0;
  173. if( HasPointer() )
  174. {
  175. GetMembers( M );
  176. while( ITERATOR_GETNEXT( M, pField ) )
  177. {
  178. if( pField->GetChild()->IsPointer() )
  179. {
  180. ITERATOR_INSERT( I, pField );
  181. Count++;
  182. }
  183. }
  184. }
  185. return Count;
  186. }