PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsify.pl

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Perl | 483 lines | 393 code | 56 blank | 34 comment | 13 complexity | f75cc52453d93a7771970068171282a2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. #!/usr/local/bin/perl
  2. # This script modifies C code to use the hijacked NSPR routines that are
  3. # now baked into the JavaScript engine rather than using the NSPR
  4. # routines that they were based on, i.e. types like PRArenaPool are changed
  5. # to JSArenaPool.
  6. #
  7. # This script was used in 9/98 to facilitate the incorporation of some NSPR
  8. # code into the JS engine so as to minimize dependency on NSPR.
  9. #
  10. # Command-line: jsify.pl [options] [filename]*
  11. #
  12. # Options:
  13. # -r Reverse direction of transformation, i.e. JS ==> NSPR2
  14. # -outdir Directory in which to place output files
  15. # NSPR2 symbols that will be modified to JS symbols, e.g.
  16. # PRArena <==> JSArena
  17. @NSPR_symbols = (
  18. "PRArena",
  19. "PRArenaPool",
  20. "PRArenaStats",
  21. "PR_ARENAMETER",
  22. "PR_ARENA_",
  23. "PR_ARENA_ALIGN",
  24. "PR_ARENA_ALLOCATE",
  25. "PR_ARENA_CONST_ALIGN_MASK",
  26. "PR_ARENA_DEFAULT_ALIGN",
  27. "PR_ARENA_DESTROY",
  28. "PR_ARENA_GROW",
  29. "PR_ARENA_MARK",
  30. "PR_ARENA_RELEASE",
  31. "PR_smprintf",
  32. "PR_smprintf_free",
  33. "PR_snprintf",
  34. "PR_sprintf_append",
  35. "PR_sscanf",
  36. "PR_sxprintf",
  37. "PR_vsmprintf",
  38. "PR_vsnprintf",
  39. "PR_vsprintf_append",
  40. "PR_vsxprintf",
  41. "PRCList",
  42. "PRCListStr",
  43. "PRCLists",
  44. "PRDestroyEventProc",
  45. "PREvent",
  46. "PREventFunProc",
  47. "PREventQueue",
  48. "PRHandleEventProc",
  49. "PR_PostEvent",
  50. "PR_PostSynchronousEvent",
  51. "PR_ProcessPendingEvents",
  52. "PR_CreateEventQueue",
  53. "PR_DequeueEvent",
  54. "PR_DestroyEvent",
  55. "PR_DestroyEventQueue",
  56. "PR_EventAvailable",
  57. "PR_EventLoop",
  58. "PR_GetEvent",
  59. "PR_GetEventOwner",
  60. "PR_GetEventQueueMonitor",
  61. "PR_GetEventQueueSelectFD",
  62. "PR_GetMainEventQueue",
  63. "PR_HandleEvent",
  64. "PR_InitEvent",
  65. "PR_ENTER_EVENT_QUEUE_MONITOR",
  66. "PR_EXIT_EVENT_QUEUE_MONITOR",
  67. "PR_MapEvents",
  68. "PR_RevokeEvents",
  69. "PR_cnvtf",
  70. "PR_dtoa",
  71. "PR_strtod",
  72. "PRFileDesc",
  73. "PR_HASH_BITS",
  74. "PR_GOLDEN_RATIO",
  75. "PRHashAllocOps",
  76. "PRHashComparator",
  77. "PRHashEntry",
  78. "PRHashEnumerator",
  79. "PRHashFunction",
  80. "PRHashNumber",
  81. "PRHashTable",
  82. "PR_HashString",
  83. "PR_HashTableAdd",
  84. "PR_HashTableDestroy",
  85. "PR_HashTableDump",
  86. "PR_HashTableEnumerateEntries",
  87. "PR_HashTableLookup",
  88. "PR_HashTableRawAdd",
  89. "PR_HashTableRawLookup",
  90. "PR_HashTableRawRemove",
  91. "PR_HashTableRemove",
  92. "PRBool",
  93. "PRFloat64",
  94. "PRInt16",
  95. "PRInt32",
  96. "PRInt64",
  97. "PRInt8",
  98. "PRIntn",
  99. "PRUint16",
  100. "PRUint32",
  101. "PRUint64",
  102. "PRUint8",
  103. "PRUintn",
  104. "PRPtrDiff",
  105. "PRPtrdiff",
  106. "PRUptrdiff",
  107. "PRUword",
  108. "PRWord",
  109. "PRPackedBool",
  110. "PRSize",
  111. "PRStatus",
  112. "pruword",
  113. "prword",
  114. "prword_t",
  115. "PR_ALIGN_OF_DOUBLE",
  116. "PR_ALIGN_OF_FLOAT",
  117. "PR_ALIGN_OF_INT",
  118. "PR_ALIGN_OF_INT64",
  119. "PR_ALIGN_OF_LONG",
  120. "PR_ALIGN_OF_POINTER",
  121. "PR_ALIGN_OF_SHORT",
  122. "PR_ALIGN_OF_WORD",
  123. "PR_BITS_PER_BYTE",
  124. "PR_BITS_PER_BYTE_LOG2",
  125. "PR_BITS_PER_DOUBLE",
  126. "PR_BITS_PER_DOUBLE_LOG2",
  127. "PR_BITS_PER_FLOAT",
  128. "PR_BITS_PER_FLOAT_LOG2",
  129. "PR_BITS_PER_INT",
  130. "PR_BITS_PER_INT64",
  131. "PR_BITS_PER_INT64_LOG2",
  132. "PR_BITS_PER_INT_LOG2",
  133. "PR_BITS_PER_LONG",
  134. "PR_BITS_PER_LONG_LOG2",
  135. "PR_BITS_PER_SHORT",
  136. "PR_BITS_PER_SHORT_LOG2",
  137. "PR_BITS_PER_WORD",
  138. "PR_BITS_PER_WORD_LOG2",
  139. "PR_BYTES_PER_BYTE",
  140. "PR_BYTES_PER_DOUBLE",
  141. "PR_BYTES_PER_DWORD",
  142. "PR_BYTES_PER_DWORD_LOG2",
  143. "PR_BYTES_PER_FLOAT",
  144. "PR_BYTES_PER_INT",
  145. "PR_BYTES_PER_INT64",
  146. "PR_BYTES_PER_LONG",
  147. "PR_BYTES_PER_SHORT",
  148. "PR_BYTES_PER_WORD",
  149. "PR_BYTES_PER_WORD_LOG2",
  150. "PRSegment",
  151. "PRSegmentAccess",
  152. "PRStuffFunc",
  153. "PRThread",
  154. "PR_APPEND_LINK",
  155. "PR_ASSERT",
  156. "PR_ATOMIC_DWORD_LOAD",
  157. "PR_ATOMIC_DWORD_STORE",
  158. "PR_Abort",
  159. "PR_ArenaAllocate",
  160. "PR_ArenaCountAllocation",
  161. "PR_ArenaCountGrowth",
  162. "PR_ArenaCountInplaceGrowth",
  163. "PR_ArenaCountRelease",
  164. "PR_ArenaCountRetract",
  165. "PR_ArenaFinish",
  166. "PR_ArenaGrow",
  167. "PR_ArenaRelease",
  168. "PR_CompactArenaPool",
  169. "PR_DumpArenaStats",
  170. "PR_FinishArenaPool",
  171. "PR_FreeArenaPool",
  172. "PR_InitArenaPool",
  173. "PR_Assert",
  174. "PR_AttachThread",
  175. "PR_BEGIN_EXTERN_C",
  176. "PR_BEGIN_MACRO",
  177. "PR_BIT",
  178. "PR_BITMASK",
  179. "PR_BUFFER_OVERFLOW_ERROR",
  180. "PR_CALLBACK",
  181. "PR_CALLBACK_DECL",
  182. "PR_CALLOC",
  183. "PR_CEILING_LOG2",
  184. "PR_CLEAR_ARENA",
  185. "PR_CLEAR_BIT",
  186. "PR_CLEAR_UNUSED",
  187. "PR_CLIST_IS_EMPTY",
  188. "PR_COUNT_ARENA",
  189. "PR_CURRENT_THREAD",
  190. "PR_GetSegmentAccess",
  191. "PR_GetSegmentSize",
  192. "PR_GetSegmentVaddr",
  193. "PR_GrowSegment",
  194. "PR_DestroySegment",
  195. "PR_MapSegment",
  196. "PR_NewSegment",
  197. "PR_Segment",
  198. "PR_Seg",
  199. "PR_SEGMENT_NONE",
  200. "PR_SEGMENT_RDONLY",
  201. "PR_SEGMENT_RDWR",
  202. "PR_Calloc",
  203. "PR_CeilingLog2",
  204. "PR_CompareStrings",
  205. "PR_CompareValues",
  206. "PR_DELETE",
  207. "PR_END_EXTERN_C",
  208. "PR_END_MACRO",
  209. "PR_ENUMERATE_STOP",
  210. "PR_FAILURE",
  211. "PR_FALSE",
  212. "PR_FLOOR_LOG2",
  213. "PR_FREEIF",
  214. "PR_FREE_PATTERN",
  215. "PR_FloorLog2",
  216. "PR_FormatTime",
  217. "PR_Free",
  218. "PR_GetEnv",
  219. "PR_GetError",
  220. "PR_INIT_ARENA_POOL",
  221. "PR_INIT_CLIST",
  222. "PR_INIT_STATIC_CLIST",
  223. "PR_INLINE",
  224. "PR_INSERT_AFTER",
  225. "PR_INSERT_BEFORE",
  226. "PR_INSERT_LINK",
  227. "PR_INT32",
  228. "PR_INTERVAL_NO_TIMEOUT",
  229. "PR_INTERVAL_NO_WAIT",
  230. "PR_Init",
  231. "PR_LIST_HEAD",
  232. "PR_LIST_TAIL",
  233. "PR_LOG",
  234. "PR_LOGGING",
  235. "PR_LOG_ALWAYS",
  236. "PR_LOG_BEGIN",
  237. "PR_LOG_DEBUG",
  238. "PR_LOG_DEFINE",
  239. "PR_LOG_END",
  240. "PR_LOG_ERROR",
  241. "PR_LOG_MAX",
  242. "PR_LOG_MIN",
  243. "PR_LOG_NONE",
  244. "PR_LOG_NOTICE",
  245. "PR_LOG_TEST",
  246. "PR_LOG_WARN",
  247. "PR_LOG_WARNING",
  248. "PR_LogFlush",
  249. "PR_LogPrint",
  250. "PR_MALLOC",
  251. "PR_MAX",
  252. "PR_MD_calloc",
  253. "PR_MD_free",
  254. "PR_MD_malloc",
  255. "PR_MD_realloc",
  256. "PR_MIN",
  257. "PR_Malloc",
  258. "PR_NEW",
  259. "PR_NEWZAP",
  260. "PR_NEXT_LINK",
  261. "PR_NOT_REACHED",
  262. "PR_NewCondVar",
  263. "PR_NewHashTable",
  264. "PR_NewLogModule",
  265. "PR_PREV_LINK",
  266. "PR_PUBLIC_API",
  267. "PR_PUBLIC_DATA",
  268. "PR_RANGE_ERROR",
  269. "PR_REALLOC",
  270. "PR_REMOVE_AND_INIT_LINK",
  271. "PR_REMOVE_LINK",
  272. "PR_ROUNDUP",
  273. "PR_Realloc",
  274. "PR_SET_BIT",
  275. "PR_STATIC_CALLBACK",
  276. "PR_SUCCESS",
  277. "PR_SetError",
  278. "PR_SetLogBuffering",
  279. "PR_SetLogFile",
  280. "PR_TEST_BIT",
  281. "PR_TRUE",
  282. "PR_UINT32",
  283. "PR_UPTRDIFF",
  284. "prarena_h___",
  285. "prbit_h___",
  286. "prclist_h___",
  287. "prdtoa_h___",
  288. "prlog_h___",
  289. "prlong_h___",
  290. "prmacos_h___",
  291. "prmem_h___",
  292. "prprf_h___",
  293. "prtypes_h___",
  294. "prarena",
  295. "prbit",
  296. "prbitmap_t",
  297. "prclist",
  298. "prcpucfg",
  299. "prdtoa",
  300. "prhash",
  301. "plhash",
  302. "prlong",
  303. "prmacos",
  304. "prmem",
  305. "prosdep",
  306. "protypes",
  307. "prprf",
  308. "prtypes"
  309. );
  310. while ($ARGV[0] =~ /^-/) {
  311. if ($ARGV[0] eq "-r") {
  312. shift;
  313. $reverse_conversion = 1;
  314. } elsif ($ARGV[0] eq "-outdir") {
  315. shift;
  316. $outdir = shift;
  317. }
  318. }
  319. # Given an NSPR symbol compute the JS equivalent or
  320. # vice-versa
  321. sub subst {
  322. local ($replacement);
  323. local ($sym) = @_;
  324. $replacement = substr($sym,0,2) eq "pr" ? "js" : "JS";
  325. $replacement .= substr($sym, 2);
  326. return $replacement;
  327. }
  328. # Build the regular expression that will convert between the NSPR
  329. # types and the JS types
  330. if ($reverse_conversion) {
  331. die "Not implemented yet";
  332. } else {
  333. foreach $sym (@NSPR_symbols) {
  334. $regexp .= $sym . "|"
  335. }
  336. # Get rid of the last "!"
  337. chop $regexp;
  338. # Replace PR* with JS* and replace pr* with js*
  339. $regexp = 's/(^|\\W)(' . $regexp . ')/$1 . &subst($2)/eg';
  340. # print $regexp;
  341. }
  342. # Pre-compile a little subroutine to perform the regexp substitution
  343. # between NSPR types and JS types
  344. eval('sub convert_from_NSPR {($line) = @_; $line =~ ' . $regexp . ';}');
  345. sub convert_mallocs {
  346. ($line) = @_;
  347. $line =~ s/PR_MALLOC/malloc/g;
  348. $line =~ s/PR_REALLOC/realloc/g;
  349. $line =~ s/PR_FREE/free/g;
  350. return $line;
  351. }
  352. sub convert_includes {
  353. ($line) = @_;
  354. if ($line !~ /include/) {
  355. return $line;
  356. }
  357. if ($line =~ /prlog\.h/) {
  358. $line = '#include "jsutil.h"'. " /* Added by JSIFY */\n";
  359. } elsif ($line =~ /plhash\.h/) {
  360. $line = '#include "jshash.h"'. " /* Added by JSIFY */\n";
  361. } elsif ($line =~ /plarena\.h/) {
  362. $line = '#include "jsarena.h"'. " /* Added by JSIFY */\n";
  363. } elsif ($line =~ /prmem\.h/) {
  364. $line = "";
  365. } elsif ($line =~ /jsmsg\.def/) {
  366. $line = '#include "js.msg"' . "\n";
  367. } elsif ($line =~ /shellmsg\.def/) {
  368. $line = '#include "jsshell.msg"' . "\n";
  369. } elsif ($line =~ /jsopcode\.def/) {
  370. $line = '#include "jsopcode.tbl"' . "\n";
  371. }
  372. return $line;
  373. }
  374. sub convert_declarations {
  375. ($line) = @_;
  376. $line =~ s/PR_EXTERN/JS_EXTERN_API/g;
  377. $line =~ s/PR_IMPLEMENT_DATA/JS_EXPORT_DATA/g;
  378. $line =~ s/PR_IMPLEMENT/JS_EXPORT_API/g;
  379. $line =~ s/PR_IMPORT/JS_IMPORT/g;
  380. $line =~ s/PR_PUBLIC_API/JS_EXPORT_API/g;
  381. $line =~ s/PR_PUBLIC_DATA/JS_EXPORT_DATA/g;
  382. return $line;
  383. }
  384. sub convert_long_long_macros {
  385. ($line) = @_;
  386. $line =~ s/\b(LL_)/JSLL_/g;
  387. return $line;
  388. }
  389. sub convert_asserts {
  390. ($line) = @_;
  391. $line =~ s/\bPR_ASSERT/JS_ASSERT/g;
  392. return $line;
  393. }
  394. while ($#ARGV >= 0) {
  395. $infile = shift;
  396. # Change filename, e.g. prtime.h to jsprtime.h, except for legacy
  397. # files that start with 'prmj', like prmjtime.h.
  398. $outfile = $infile;
  399. if ($infile !~ /^prmj/) {
  400. $outfile =~ s/^pr/js/;
  401. $outfile =~ s/^pl/js/;
  402. }
  403. if ($outdir) {
  404. $outfile = $outdir . '/' . $outfile;
  405. }
  406. if ($infile eq $outfile) {
  407. die "Error: refuse to overwrite $outfile, use -outdir option."
  408. }
  409. die "Can't open $infile" if !open(INFILE, "<$infile");
  410. die "Can't open $outfile for writing" if !open(OUTFILE, ">$outfile");
  411. while (<INFILE>) {
  412. $line = $_;
  413. #Get rid of #include "prlog.h"
  414. &convert_includes($line);
  415. # Rename PR_EXTERN, PR_IMPORT, etc.
  416. &convert_declarations($line);
  417. # Convert from PR_MALLOC to malloc, etc.
  418. &convert_mallocs($line);
  419. # Convert from PR_ASSERT to JS_ASSERT
  420. # &convert_asserts($line);
  421. # Convert from, e.g. PRArena to JSPRArena
  422. &convert_from_NSPR($line);
  423. # Change LL_* macros to JSLL_*
  424. &convert_long_long_macros($line);
  425. print OUTFILE $line;
  426. }
  427. }