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.

130 lines
3.3 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 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_COMP::S_GenInitOutLocals(
  28. CCB * pCCB )
  29. {
  30. char Buffer[ 256 ];
  31. RESOURCE * pResource;
  32. PNAME p;
  33. CG_NDR * pLPC = pCCB->GetLastPlaceholderClass();
  34. strcpy( Buffer, pLPC->GetType()->GetSymName() );
  35. p = pCCB->GenTRNameOffLastParam( Buffer );
  36. pResource = pCCB->GetLocalResource( p );
  37. // There is a pointer for the top level structure.
  38. Out_Assign( pCCB,
  39. pCCB->GetSourceExpression(),
  40. MakeAddressExpressionNoMatterWhat( pResource )
  41. );
  42. // Go zero out the pointers in the structure, for now.
  43. if( HasPointer() )
  44. {
  45. ITERATOR I;
  46. CG_FIELD * pCG;
  47. expr_node * pSrc = pCCB->GetSourceExpression();
  48. // Get all the members in the struct which contain pointers. If the
  49. // structure has been unrolled by the format string generator, the
  50. // print prefix contains the proper prefixed part of the unrolled path,
  51. // we just have to add the field name to it.
  52. GetPointerMembers( I );
  53. while( ITERATOR_GETNEXT( I, pCG ) )
  54. {
  55. char * pVarName =
  56. new char[ strlen( ((CG_FIELD *)pCG)->GetPrintPrefix())+
  57. strlen( pCG->GetType()->GetSymName()) +
  58. 1
  59. ];
  60. strcpy( pVarName, ((CG_FIELD *)pCG)->GetPrintPrefix() );
  61. strcat( pVarName, pCG->GetType()->GetSymName() );
  62. expr_node * pExpr = new expr_pointsto(
  63. pSrc,
  64. new expr_variable( pVarName, 0 ));
  65. expr_node * pAss = new expr_assign(pExpr, new expr_constant(0L));
  66. pCCB->GetStream()->NewLine();
  67. pAss->PrintCall( pCCB->GetStream(), 0, 0 );
  68. pCCB->GetStream()->Write(';');
  69. // this memory area is no longer useful.
  70. delete []pVarName;
  71. }
  72. }
  73. return CG_OK;
  74. }
  75. short
  76. CG_COMP::GetPointerMembers(
  77. ITERATOR& I )
  78. {
  79. CG_ITERATOR M;
  80. CG_FIELD * pField;
  81. short Count = 0;
  82. if( HasPointer() )
  83. {
  84. GetMembers( M );
  85. while( ITERATOR_GETNEXT( M, pField ) )
  86. {
  87. if( pField->GetChild()->IsPointer() )
  88. {
  89. ITERATOR_INSERT( I, pField );
  90. Count++;
  91. }
  92. }
  93. }
  94. return Count;
  95. }