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.

359 lines
17 KiB

  1. /*****************************************************************************
  2. * Copyright (c) 1990-1999 Microsoft Corporation
  3. *
  4. * RPC compiler: Pass1 handler
  5. *
  6. * Author : Vibhas Chandorkar
  7. * Created : 01st-Sep-1990
  8. *
  9. ****************************************************************************/
  10. #pragma warning ( disable : 4514 4214 )
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "nulldefs.h"
  15. #include "midldebug.h"
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include "grammar.h"
  20. #include "lex.h"
  21. /****************************************************************************
  22. * local definitions and macros
  23. ***************************************************************************/
  24. const struct _keytable
  25. {
  26. const char * pString;
  27. token_t Token : 16;
  28. short flag : 16;
  29. } KeywordTable[] =
  30. {
  31. {"FALSE", TOKENFALSE, UNCONDITIONAL }
  32. ,{"ISO_LATIN_1", KWISOLATIN1, UNCONDITIONAL }
  33. ,{"ISO_UCS", KWISOUCS, UNCONDITIONAL }
  34. ,{"ISO_MULTI_LINGUAL", KWISOMULTILINGUAL, UNCONDITIONAL }
  35. ,{"NULL", KWTOKENNULL, UNCONDITIONAL }
  36. ,{"SAFEARRAY", KWSAFEARRAY, UNCONDITIONAL }
  37. ,{"TRUE", TOKENTRUE, UNCONDITIONAL }
  38. ,{"__alignof", KWALIGNOF, UNCONDITIONAL }
  39. ,{"__asm", MSCASM, UNCONDITIONAL }
  40. ,{"__cdecl", MSCCDECL, UNCONDITIONAL }
  41. ,{"__declspec", KWMSCDECLSPEC, UNCONDITIONAL }
  42. ,{"__export", MSCEXPORT, UNCONDITIONAL }
  43. ,{"__far", MSCFAR, UNCONDITIONAL }
  44. ,{"__fastcall", MSCFASTCALL, UNCONDITIONAL }
  45. ,{"__float128", KWFLOAT128, UNCONDITIONAL }
  46. ,{"__float80", KWFLOAT80, UNCONDITIONAL }
  47. ,{"__fortran", MSCFORTRAN, UNCONDITIONAL }
  48. ,{"__huge", MSCHUGE, UNCONDITIONAL }
  49. ,{"__inline", KW_C_INLINE, UNCONDITIONAL }
  50. ,{"__int128", KWINT128, UNCONDITIONAL }
  51. ,{"__int32", KWINT32, UNCONDITIONAL }
  52. ,{"__int3264", KWINT3264, UNCONDITIONAL }
  53. ,{"__int64", KWINT64, UNCONDITIONAL }
  54. ,{"__loadds", MSCLOADDS, UNCONDITIONAL }
  55. ,{"__near", MSCNEAR, UNCONDITIONAL }
  56. ,{"__pascal", MSCPASCAL, UNCONDITIONAL }
  57. ,{"__ptr32", MSCPTR32, UNCONDITIONAL }
  58. ,{"__ptr64", MSCPTR64, UNCONDITIONAL }
  59. ,{"__saveregs", MSCSAVEREGS, UNCONDITIONAL }
  60. ,{"__segment", MSCSEGMENT, UNCONDITIONAL }
  61. ,{"__self", MSCSELF, UNCONDITIONAL }
  62. ,{"__stdcall", MSCSTDCALL, UNCONDITIONAL }
  63. ,{"__unaligned", MSCUNALIGNED, UNCONDITIONAL }
  64. ,{"__w64", MSCW64, UNCONDITIONAL }
  65. ,{"_asm", MSCASM, UNCONDITIONAL }
  66. ,{"_cdecl", MSCCDECL, UNCONDITIONAL }
  67. ,{"_declspec", KWMSCDECLSPEC, UNCONDITIONAL }
  68. ,{"_export", MSCEXPORT, UNCONDITIONAL }
  69. ,{"_far", MSCFAR, UNCONDITIONAL }
  70. ,{"_fastcall", MSCFASTCALL, UNCONDITIONAL }
  71. ,{"_fortran", MSCFORTRAN, UNCONDITIONAL }
  72. ,{"_huge", MSCHUGE, UNCONDITIONAL }
  73. ,{"_inline", KW_C_INLINE, UNCONDITIONAL }
  74. ,{"_loadds", MSCLOADDS, UNCONDITIONAL }
  75. ,{"_near", MSCNEAR, UNCONDITIONAL }
  76. ,{"_pascal", MSCPASCAL, UNCONDITIONAL }
  77. ,{"_saveregs", MSCSAVEREGS, UNCONDITIONAL }
  78. ,{"_segment", MSCSEGMENT, UNCONDITIONAL }
  79. ,{"_self", MSCSELF, UNCONDITIONAL }
  80. ,{"_stdcall", MSCSTDCALL, UNCONDITIONAL }
  81. ,{"aggregatable", KWAGGREGATABLE, INBRACKET }
  82. ,{"align", KWALIGN, INBRACKET }
  83. ,{"allocate", KWALLOCATE, INBRACKET }
  84. ,{"appobject", KWAPPOBJECT, INBRACKET }
  85. ,{"async", KWASYNC, INBRACKET }
  86. ,{"async_uuid", KWASYNCUUID, INBRACKET }
  87. ,{"auto", KWAUTO, UNCONDITIONAL }
  88. ,{"auto_handle", KWAUTOHANDLE, INBRACKET }
  89. ,{"bindable", KWBINDABLE, INBRACKET }
  90. ,{"boolean", KWBOOLEAN, UNCONDITIONAL }
  91. ,{"broadcast", KWBROADCAST, INBRACKET }
  92. ,{"bstring", KWBSTRING, INBRACKET }
  93. ,{"byte", KWBYTE, UNCONDITIONAL }
  94. ,{"byte_count", KWBYTECOUNT, INBRACKET }
  95. ,{"call_as", KWCALLAS, INBRACKET }
  96. ,{"callback", KWCALLBACK, INBRACKET }
  97. ,{"case", KWCASE, UNCONDITIONAL }
  98. ,{"cdecl", MSCCDECL, UNCONDITIONAL }
  99. ,{"char", KWCHAR, UNCONDITIONAL }
  100. ,{"coclass", KWCOCLASS, UNCONDITIONAL }
  101. ,{"code", KWCODE, INBRACKET }
  102. ,{"comm_status", KWCOMMSTATUS, INBRACKET }
  103. ,{"const", KWCONST, UNCONDITIONAL }
  104. ,{"context_handle", KWCONTEXTHANDLE, INBRACKET }
  105. ,{"context_handle_noserialize",KWNOSERIALIZE, INBRACKET }
  106. ,{"context_handle_serialize", KWSERIALIZE, INBRACKET }
  107. ,{"control", KWCONTROL, INBRACKET }
  108. ,{"cpp_quote", KWCPPQUOTE, UNCONDITIONAL }
  109. ,{"cs_char", KWCSCHAR, INBRACKET }
  110. ,{"cs_drtag", KWCSDRTAG, INBRACKET }
  111. ,{"cs_rtag", KWCSRTAG, INBRACKET }
  112. ,{"cs_stag", KWCSSTAG, INBRACKET }
  113. ,{"cs_tag_rtn", KWCSTAGRTN, INBRACKET }
  114. ,{"custom", KWCUSTOM, INBRACKET }
  115. ,{"declare_guid", KWDECLGUID, UNCONDITIONAL }
  116. ,{"decode", KWDECODE, INBRACKET }
  117. ,{"default", KWDEFAULT, UNCONDITIONAL }
  118. ,{"defaultbind", KWDEFAULTBIND, INBRACKET }
  119. ,{"defaultcollelem", KWDEFAULTCOLLELEM, INBRACKET }
  120. ,{"defaultvalue", KWDEFAULTVALUE, INBRACKET }
  121. ,{"defaultvtable", KWDEFAULTVTABLE, INBRACKET }
  122. ,{"dispinterface", KWDISPINTERFACE, UNCONDITIONAL }
  123. ,{"displaybind", KWDISPLAYBIND, INBRACKET }
  124. ,{"dllname", KWDLLNAME, INBRACKET }
  125. ,{"double", KWDOUBLE, UNCONDITIONAL }
  126. ,{"dual", KWDUAL, INBRACKET }
  127. ,{"enable_allocate", KWENABLEALLOCATE, INBRACKET }
  128. ,{"encode", KWENCODE, INBRACKET }
  129. ,{"endpoint", KWENDPOINT, INBRACKET }
  130. ,{"entry", KWENTRY, INBRACKET}
  131. ,{"enum", KWENUM, UNCONDITIONAL }
  132. ,{"explicit_handle", KWEXPLICITHANDLE, INBRACKET }
  133. ,{"extern", KWEXTERN, UNCONDITIONAL }
  134. ,{"far", MSCFAR, UNCONDITIONAL }
  135. ,{"fault_status", KWFAULTSTATUS, INBRACKET }
  136. ,{"first_is", KWFIRSTIS, INBRACKET }
  137. ,{"float", KWFLOAT, UNCONDITIONAL }
  138. ,{"force_allocate", KWFORCEALLOCATE, INBRACKET }
  139. ,{"funcdescattr", KWFUNCDESCATTR, INBRACKET }
  140. ,{"handle", KWHANDLE, INBRACKET }
  141. ,{"handle_t", KWHANDLET, UNCONDITIONAL }
  142. ,{"heap", KWHEAP, INBRACKET }
  143. ,{"helpcontext", KWHC, INBRACKET }
  144. ,{"helpfile", KWHELPFILE, INBRACKET }
  145. ,{"helpstring", KWHELPSTR, INBRACKET }
  146. ,{"helpstringcontext", KWHSC, INBRACKET }
  147. ,{"helpstringdll", KWHELPSTRINGDLL, INBRACKET }
  148. ,{"hidden", KWHIDDEN, INBRACKET }
  149. ,{"hyper", KWHYPER, UNCONDITIONAL }
  150. ,{"id", KWID, INBRACKET }
  151. ,{"idempotent", KWIDEMPOTENT, INBRACKET }
  152. ,{"idldescattr", KWIDLDESCATTR, INBRACKET }
  153. ,{"ignore", KWIGNORE, INBRACKET }
  154. ,{"iid_is", KWIIDIS, INBRACKET }
  155. ,{"immediatebind", KWIMMEDIATEBIND, INBRACKET }
  156. ,{"implicit_handle", KWIMPLICITHANDLE, INBRACKET }
  157. ,{"import", KWIMPORT, UNCONDITIONAL }
  158. ,{"importlib", KWIMPORTLIB, UNCONDITIONAL }
  159. ,{"in", KWIN, INBRACKET }
  160. ,{"in_line", KWINLINE, INBRACKET }
  161. ,{"include", KWINCLUDE, UNCONDITIONAL }
  162. ,{"inline", KW_C_INLINE, UNCONDITIONAL }
  163. ,{"input_sync", KWINPUTSYNC, INBRACKET }
  164. ,{"int", KWINT, UNCONDITIONAL }
  165. ,{"interface", KWINTERFACE, UNCONDITIONAL }
  166. ,{"interpret", KWINTERPRET, INBRACKET }
  167. ,{"last_is", KWLASTIS, INBRACKET }
  168. ,{"lcid", KWLCID, INBRACKET}
  169. ,{"length_is", KWLENGTHIS, INBRACKET }
  170. ,{"library", KWLIBRARY, UNCONDITIONAL }
  171. ,{"licensed", KWLICENSED, INBRACKET }
  172. ,{"local", KWLOCAL, INBRACKET }
  173. ,{"local_call", KWLOCAL, INBRACKET }
  174. ,{"long", KWLONG, UNCONDITIONAL }
  175. ,{"long_enum", KWLONGENUM, INBRACKET }
  176. ,{"manual", KWMANUAL, INBRACKET }
  177. ,{"max_is", KWMAXIS, INBRACKET }
  178. ,{"maybe", KWMAYBE, INBRACKET }
  179. ,{"message", KWMESSAGE, INBRACKET }
  180. ,{"methods", KWMETHODS, UNCONDITIONAL }
  181. ,{"midl_pragma", KWMIDLPRAGMA, UNCONDITIONAL }
  182. ,{"min_is", KWMINIS, INBRACKET }
  183. ,{"module", KWMODULE, UNCONDITIONAL }
  184. ,{"ms_conf_struct", KWMS_CONF_STRUCT, INBRACKET }
  185. ,{"ms_union", KWMSUNION, INBRACKET }
  186. ,{"near", MSCNEAR, UNCONDITIONAL }
  187. ,{"nocode", KWNOCODE, INBRACKET }
  188. ,{"nointerpret", KWNOINTERPRET, INBRACKET }
  189. ,{"nonbrowsable", KWNONBROWSABLE, INBRACKET }
  190. ,{"noncreatable", KWNONCREATABLE, INBRACKET }
  191. ,{"nonextensible", KWNONEXTENSIBLE, INBRACKET }
  192. ,{"notify", KWNOTIFY, INBRACKET }
  193. ,{"notify_flag", KWNOTIFYFLAG, INBRACKET }
  194. ,{"object", KWOBJECT, INBRACKET }
  195. ,{"odl", KWODL, INBRACKET }
  196. ,{"off_line", KWOFFLINE, INBRACKET }
  197. ,{"oleautomation", KWOLEAUTOMATION, INBRACKET }
  198. ,{"optimize", KWOPTIMIZE, INBRACKET }
  199. ,{"optional", KWOPTIONAL, INBRACKET }
  200. ,{"out", KWOUT, INBRACKET }
  201. ,{"out_of_line", KWOUTOFLINE, INBRACKET }
  202. ,{"partial_ignore", KWPARTIALIGNORE, INBRACKET }
  203. ,{"pascal", MSCPASCAL, UNCONDITIONAL }
  204. ,{"pipe", KWPIPE, UNCONDITIONAL }
  205. ,{"pointer_default", KWDEFAULTPOINTER, INBRACKET }
  206. ,{"predeclid", KWPREDECLID, INBRACKET }
  207. ,{"private_char_16", KWPRIVATECHAR16, UNCONDITIONAL }
  208. ,{"private_char_8", KWPRIVATECHAR8, UNCONDITIONAL }
  209. ,{"properties", KWPROPERTIES, UNCONDITIONAL }
  210. ,{"propget", KWPROPGET, INBRACKET }
  211. ,{"propput", KWPROPPUT, INBRACKET }
  212. ,{"propputref", KWPROPPUTREF, INBRACKET }
  213. ,{"proxy", KWPROXY, INBRACKET }
  214. ,{"ptr", KWPTR, INBRACKET }
  215. ,{"public", KWPUBLIC, INBRACKET }
  216. ,{"range", KWRANGE, INBRACKET }
  217. ,{"readonly", KWREADONLY, INBRACKET }
  218. ,{"ref", KWREF, INBRACKET }
  219. ,{"register", KWREGISTER, UNCONDITIONAL }
  220. ,{"replaceable", KWREPLACEABLE, INBRACKET }
  221. ,{"represent_as", KWREPRESENTAS, INBRACKET }
  222. ,{"requestedit", KWREQUESTEDIT, INBRACKET }
  223. ,{"restricted", KWRESTRICTED, INBRACKET }
  224. ,{"retval", KWRETVAL, INBRACKET }
  225. ,{"shape", KWSHAPE, INBRACKET }
  226. ,{"short", KWSHORT, UNCONDITIONAL }
  227. ,{"short_enum", KWSHORTENUM, INBRACKET }
  228. ,{"signed", KWSIGNED, UNCONDITIONAL }
  229. ,{"size_is", KWSIZEIS, INBRACKET }
  230. ,{"sizeof", KWSIZEOF, UNCONDITIONAL }
  231. ,{"small", KWSMALL, UNCONDITIONAL }
  232. ,{"source", KWSOURCE, INBRACKET }
  233. ,{"static", KWSTATIC, UNCONDITIONAL }
  234. ,{"stdcall", MSCSTDCALL, UNCONDITIONAL }
  235. ,{"strict_context_handle", KWSTRICTCONTEXTHANDLE, INBRACKET }
  236. ,{"string", KWSTRING, INBRACKET }
  237. ,{"struct", KWSTRUCT, UNCONDITIONAL }
  238. ,{"switch", KWSWITCH, UNCONDITIONAL }
  239. ,{"switch_is", KWSWITCHIS, INBRACKET }
  240. ,{"switch_type", KWSWITCHTYPE, INBRACKET }
  241. ,{"transmit_as", KWTRANSMITAS, INBRACKET }
  242. ,{"typedef", KWTYPEDEF, UNCONDITIONAL }
  243. ,{"typedescattr", KWTYPEDESCATTR, INBRACKET }
  244. ,{"uidefault", KWUIDEFAULT, INBRACKET }
  245. ,{"unaligned", KWUNALIGNED, INBRACKET }
  246. ,{"union", KWUNION, UNCONDITIONAL }
  247. ,{"unique", KWUNIQUE, INBRACKET }
  248. ,{"unsigned", KWUNSIGNED, UNCONDITIONAL }
  249. ,{"user_marshal", KWUSERMARSHAL, INBRACKET }
  250. ,{"usesgetlasterror", KWUSESGETLASTERROR, INBRACKET }
  251. ,{"uuid", KWUUID, INBRACKET }
  252. ,{"v1_array", KWV1ARRAY, INBRACKET }
  253. ,{"v1_enum", KWV1ENUM, INBRACKET }
  254. ,{"v1_string", KWV1STRING, INBRACKET }
  255. ,{"v1_struct", KWV1STRUCT, INBRACKET }
  256. ,{"vararg", KWVARARG, INBRACKET }
  257. ,{"vardescattr", KWVARDESCATTR, INBRACKET }
  258. ,{"version", KWVERSION, INBRACKET }
  259. ,{"void", KWVOID, UNCONDITIONAL }
  260. ,{"volatile", KWVOLATILE, UNCONDITIONAL }
  261. ,{"wire_marshal", KWWIREMARSHAL, INBRACKET }
  262. };
  263. #define SIZE_OF_KEYWORD_TABLE \
  264. ( sizeof( KeywordTable ) / sizeof(struct _keytable ) )
  265. /****************************************************************************
  266. * local data
  267. ***************************************************************************/
  268. /****************************************************************************
  269. * local procedure prototypes
  270. ***************************************************************************/
  271. /****************************************************************************
  272. * external data
  273. ***************************************************************************/
  274. /****************************************************************************
  275. * external procedures/prototypes/etc
  276. ***************************************************************************/
  277. /**************************************************************************
  278. is_keyword:
  279. Is the given string a keyword ? if yes, return the token value of
  280. the token. Else return IDENTIFIER.
  281. **************************************************************************/
  282. token_t
  283. is_keyword(
  284. char * pID,
  285. short InBracket
  286. )
  287. {
  288. short cmp;
  289. short low = 0;
  290. short high = SIZE_OF_KEYWORD_TABLE - 1;
  291. short mid;
  292. while ( low <= high )
  293. {
  294. mid = (short)( (low + high) / 2 );
  295. cmp = (short) strcmp( pID, KeywordTable[mid].pString );
  296. if( cmp < 0 )
  297. {
  298. high = (short)( mid - 1 );
  299. }
  300. else if (cmp > 0)
  301. {
  302. low = (short)( mid + 1 );
  303. }
  304. else
  305. {
  306. // since InBracket is the only flag, this check is enough
  307. if (KeywordTable[mid].flag <= InBracket)
  308. return KeywordTable[mid].Token;
  309. else
  310. return IDENTIFIER;
  311. }
  312. }
  313. return IDENTIFIER;
  314. }
  315. // The final return from KeywordToString is unreachable because of the
  316. // MIDL_ASSERT.
  317. #pragma warning(push)
  318. #pragma warning(disable:4702)
  319. char *
  320. KeywordToString(
  321. token_t Token )
  322. {
  323. struct _keytable * pTable = (struct _keytable *) KeywordTable;
  324. struct _keytable * pTableEnd = pTable + SIZE_OF_KEYWORD_TABLE;
  325. while( pTable < pTableEnd )
  326. {
  327. if( pTable->Token == Token )
  328. return (char*) pTable->pString;
  329. pTable++;
  330. }
  331. MIDL_ASSERT( 0 );
  332. return "";
  333. }
  334. #pragma warning(pop)