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.

345 lines
8.2 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. btgen.cxx
  5. Abstract:
  6. code generation method implementations for the base type class.
  7. Notes:
  8. History:
  9. Sep-22-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. extern CMD_ARG * pCommand;
  27. CG_STATUS
  28. CG_BASETYPE::GenMarshall(
  29. CCB * pCCB )
  30. {
  31. pCCB;
  32. MIDL_ASSERT(0);
  33. return CG_OK;
  34. }
  35. CG_STATUS
  36. CG_BASETYPE::GenUnMarshall(
  37. CCB * pCCB )
  38. {
  39. pCCB;
  40. MIDL_ASSERT(0);
  41. return CG_OK;
  42. }
  43. CG_STATUS
  44. CG_BASETYPE::S_GenInitOutLocals(
  45. CCB * pCCB )
  46. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  47. Routine Description:
  48. Generate the init call for the locals.
  49. Arguments:
  50. pCCB - The ptr to code gen block.
  51. Return Value:
  52. Notes:
  53. ----------------------------------------------------------------------------*/
  54. {
  55. expr_node * pExpr;
  56. if( !pCCB->IsRefAllocDone() )
  57. {
  58. pExpr = new expr_sizeof( GetType() );
  59. Out_Alloc( pCCB, pCCB->GetSourceExpression(), 0, pExpr );
  60. }
  61. else
  62. {
  63. pExpr = MakeAddressExpressionNoMatterWhat( GetResource() );
  64. Out_Assign( pCCB, pCCB->GetSourceExpression(), pExpr );
  65. }
  66. return CG_OK;
  67. }
  68. FORMAT_CHARACTER
  69. CG_BASETYPE::GetFormatChar( CCB *)
  70. {
  71. switch ( GetType()->GetBasicType()->NodeKind() )
  72. {
  73. case NODE_BYTE :
  74. return FC_BYTE;
  75. case NODE_CHAR :
  76. return FC_CHAR;
  77. case NODE_SMALL :
  78. case NODE_BOOLEAN :
  79. return FC_SMALL;
  80. case NODE_WCHAR_T :
  81. return FC_WCHAR;
  82. case NODE_SHORT :
  83. return FC_SHORT;
  84. case NODE_LONG :
  85. case NODE_INT32 :
  86. case NODE_INT :
  87. return FC_LONG;
  88. case NODE_FLOAT :
  89. return FC_FLOAT;
  90. case NODE_HYPER :
  91. case NODE_INT64 :
  92. case NODE_LONGLONG :
  93. return FC_HYPER;
  94. case NODE_DOUBLE :
  95. return FC_DOUBLE;
  96. case NODE_INT3264:
  97. {
  98. BOOL IsUnsigned;
  99. IsUnsigned = ((node_base_type *)(GetType()->GetBasicType()))->IsUnsigned();
  100. if ( pCommand->IsNDR64Run() || pCommand->Is64BitEnv() )
  101. return (IsUnsigned ? FC_UINT3264 : FC_INT3264);
  102. else
  103. return FC_LONG;
  104. }
  105. break;
  106. case NODE_INT128:
  107. return FC_INT128;
  108. case NODE_FLOAT80:
  109. return FC_FLOAT80;
  110. case NODE_FLOAT128:
  111. return FC_FLOAT128;
  112. default:
  113. // remove FC_BLKHOLE & HookOLE
  114. MIDL_ASSERT(0);
  115. return FC_ZERO;
  116. }
  117. // unreachable code
  118. // return FC_ZERO;
  119. }
  120. NDR64_FORMAT_CHARACTER
  121. CG_BASETYPE::GetNDR64FormatChar( CCB *)
  122. {
  123. switch ( GetType()->GetBasicType()->NodeKind() )
  124. {
  125. case NODE_BYTE :
  126. return FC64_INT8;
  127. case NODE_CHAR :
  128. return FC64_CHAR;
  129. case NODE_SMALL :
  130. case NODE_BOOLEAN :
  131. return FC64_INT8;
  132. case NODE_WCHAR_T :
  133. return FC64_WCHAR;
  134. case NODE_SHORT :
  135. return FC64_INT16;
  136. case NODE_LONG :
  137. case NODE_INT32 :
  138. case NODE_INT :
  139. return FC64_INT32;
  140. case NODE_FLOAT :
  141. return FC64_FLOAT32;
  142. case NODE_HYPER :
  143. case NODE_INT64 :
  144. case NODE_LONGLONG :
  145. return FC64_INT64;
  146. case NODE_DOUBLE :
  147. return FC64_FLOAT64;
  148. case NODE_INT3264:
  149. return pCommand->Is64BitEnv() ? FC64_INT64 : FC64_INT32;
  150. case NODE_INT128:
  151. return FC64_INT128;
  152. case NODE_FLOAT80:
  153. return FC64_FLOAT80;
  154. case NODE_FLOAT128:
  155. return FC64_FLOAT128;
  156. default:
  157. // remove FC_BLKHOLE & HookOLE
  158. MIDL_ASSERT(0);
  159. return FC64_ZERO;
  160. }
  161. // unreachable code
  162. // return FC_ZERO;
  163. }
  164. FORMAT_CHARACTER
  165. CG_BASETYPE::GetSignedFormatChar()
  166. {
  167. BOOL IsUnsigned;
  168. IsUnsigned = ((node_base_type *)(GetType()->GetBasicType()))->IsUnsigned();
  169. switch ( GetFormatChar() )
  170. {
  171. case FC_BYTE :
  172. // return FC_USMALL;
  173. case FC_SMALL :
  174. case FC_CHAR :
  175. return (IsUnsigned ? FC_USMALL : FC_SMALL);
  176. case FC_WCHAR :
  177. // return FC_USHORT;
  178. case FC_SHORT :
  179. return (IsUnsigned ? FC_USHORT : FC_SHORT);
  180. case FC_LONG :
  181. return (IsUnsigned ? FC_ULONG : FC_LONG);
  182. case FC_INT3264 :
  183. case FC_UINT3264 :
  184. return (IsUnsigned ? FC_UINT3264 : FC_INT3264);
  185. case FC_HYPER :
  186. return (IsUnsigned ? FC_HYPER : FC_HYPER);
  187. case FC_INT128 :
  188. return (IsUnsigned ? FC_UINT128 : FC_INT128);
  189. default :
  190. MIDL_ASSERT(0);
  191. }
  192. return FC_ZERO;
  193. }
  194. NDR64_FORMAT_CHARACTER
  195. CG_BASETYPE::GetNDR64SignedFormatChar()
  196. {
  197. BOOL IsUnsigned;
  198. IsUnsigned = ((node_base_type *)(GetType()->GetBasicType()))->IsUnsigned();
  199. switch ( GetNDR64FormatChar() )
  200. {
  201. case FC64_INT8 :
  202. case FC64_CHAR :
  203. return (IsUnsigned ? FC64_UINT8 : FC64_INT8);
  204. case FC64_WCHAR :
  205. // return FC_USHORT;
  206. case FC64_INT16 :
  207. return (IsUnsigned ? FC64_UINT16 : FC64_INT16 );
  208. case FC64_INT32 :
  209. return (IsUnsigned ? FC64_UINT32 : FC64_INT32 );
  210. case FC64_INT64 :
  211. return (IsUnsigned ? FC64_UINT64 : FC64_INT64);
  212. case FC64_INT128 :
  213. return (IsUnsigned ? FC64_UINT128 : FC64_INT128);
  214. default :
  215. MIDL_ASSERT(0);
  216. }
  217. return FC64_ZERO;
  218. }
  219. char *
  220. CG_BASETYPE::GetTypeName()
  221. {
  222. return GetType()->GetSymName();
  223. }
  224. void
  225. CG_BASETYPE::IncrementStackOffset( long * pOffset )
  226. {
  227. if ( pCommand->Is64BitEnv() )
  228. {
  229. *pOffset = (*pOffset + 7) & ~ 0x7;
  230. *pOffset += 8;
  231. }
  232. else
  233. {
  234. unsigned short Env;
  235. Env = pCommand->GetEnv();
  236. switch ( GetFormatChar() )
  237. {
  238. case FC_HYPER :
  239. case FC_DOUBLE :
  240. *pOffset = (*pOffset + 3) & ~ 0x3;
  241. *pOffset += 8;
  242. break;
  243. case FC_LONG :
  244. case FC_FLOAT :
  245. *pOffset = (*pOffset + 3) & ~ 0x3;
  246. *pOffset += 4;
  247. break;
  248. case FC_INT128:
  249. case FC_FLOAT80:
  250. case FC_FLOAT128:
  251. // Check calling convention for these
  252. // once VC implements them.
  253. *pOffset = (*pOffset + 3) & ~ 0x3;
  254. *pOffset += 16;
  255. break;
  256. default :
  257. *pOffset += 4;
  258. break;
  259. }
  260. }
  261. }
  262. FORMAT_CHARACTER
  263. CG_ENUM::GetFormatChar( CCB * )
  264. {
  265. return ( IsEnumLong() ? FC_ENUM32 : FC_ENUM16 );
  266. }
  267. NDR64_FORMAT_CHARACTER
  268. CG_ENUM::GetNDR64FormatChar( CCB * )
  269. {
  270. MIDL_ASSERT( IsEnumLong() );
  271. return FC64_INT32;
  272. }
  273. FORMAT_CHARACTER
  274. CG_ENUM::GetSignedFormatChar()
  275. {
  276. return ( IsEnumLong() ? FC_LONG : FC_SHORT );
  277. }
  278. NDR64_FORMAT_CHARACTER
  279. CG_ENUM::GetNDR64SignedFormatChar()
  280. {
  281. MIDL_ASSERT( IsEnumLong() );
  282. return FC64_INT32;
  283. }
  284. FORMAT_CHARACTER
  285. CG_ERROR_STATUS_T::GetFormatChar( CCB * )
  286. {
  287. return FC_ERROR_STATUS_T;
  288. }
  289. NDR64_FORMAT_CHARACTER
  290. CG_ERROR_STATUS_T::GetNDR64FormatChar( CCB * )
  291. {
  292. return FC64_ERROR_STATUS_T;
  293. }