ObjectiveCAtKeywords.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. #include "Lexer.h"
  2. #include "Token.h"
  3. using namespace CPlusPlus;
  4. static inline int classify3(const char *s) {
  5. if (s[0] == 'e') {
  6. if (s[1] == 'n') {
  7. if (s[2] == 'd') {
  8. return T_AT_END;
  9. }
  10. }
  11. }
  12. else if (s[0] == 't') {
  13. if (s[1] == 'r') {
  14. if (s[2] == 'y') {
  15. return T_AT_TRY;
  16. }
  17. }
  18. }
  19. return T_ERROR;
  20. }
  21. static inline int classify4(const char *s) {
  22. if (s[0] == 'd') {
  23. if (s[1] == 'e') {
  24. if (s[2] == 'f') {
  25. if (s[3] == 's') {
  26. return T_AT_DEFS;
  27. }
  28. }
  29. }
  30. }
  31. return T_ERROR;
  32. }
  33. static inline int classify5(const char *s) {
  34. if (s[0] == 'c') {
  35. if (s[1] == 'a') {
  36. if (s[2] == 't') {
  37. if (s[3] == 'c') {
  38. if (s[4] == 'h') {
  39. return T_AT_CATCH;
  40. }
  41. }
  42. }
  43. }
  44. else if (s[1] == 'l') {
  45. if (s[2] == 'a') {
  46. if (s[3] == 's') {
  47. if (s[4] == 's') {
  48. return T_AT_CLASS;
  49. }
  50. }
  51. }
  52. }
  53. }
  54. else if (s[0] == 't') {
  55. if (s[1] == 'h') {
  56. if (s[2] == 'r') {
  57. if (s[3] == 'o') {
  58. if (s[4] == 'w') {
  59. return T_AT_THROW;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. return T_ERROR;
  66. }
  67. static inline int classify6(const char *s) {
  68. if (s[0] == 'e') {
  69. if (s[1] == 'n') {
  70. if (s[2] == 'c') {
  71. if (s[3] == 'o') {
  72. if (s[4] == 'd') {
  73. if (s[5] == 'e') {
  74. return T_AT_ENCODE;
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. else if (s[0] == 'p') {
  82. if (s[1] == 'u') {
  83. if (s[2] == 'b') {
  84. if (s[3] == 'l') {
  85. if (s[4] == 'i') {
  86. if (s[5] == 'c') {
  87. return T_AT_PUBLIC;
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. return T_ERROR;
  95. }
  96. static inline int classify7(const char *s) {
  97. if (s[0] == 'd') {
  98. if (s[1] == 'y') {
  99. if (s[2] == 'n') {
  100. if (s[3] == 'a') {
  101. if (s[4] == 'm') {
  102. if (s[5] == 'i') {
  103. if (s[6] == 'c') {
  104. return T_AT_DYNAMIC;
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. else if (s[0] == 'f') {
  113. if (s[1] == 'i') {
  114. if (s[2] == 'n') {
  115. if (s[3] == 'a') {
  116. if (s[4] == 'l') {
  117. if (s[5] == 'l') {
  118. if (s[6] == 'y') {
  119. return T_AT_FINALLY;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. else if (s[0] == 'p') {
  128. if (s[1] == 'a') {
  129. if (s[2] == 'c') {
  130. if (s[3] == 'k') {
  131. if (s[4] == 'a') {
  132. if (s[5] == 'g') {
  133. if (s[6] == 'e') {
  134. return T_AT_PACKAGE;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. else if (s[1] == 'r') {
  142. if (s[2] == 'i') {
  143. if (s[3] == 'v') {
  144. if (s[4] == 'a') {
  145. if (s[5] == 't') {
  146. if (s[6] == 'e') {
  147. return T_AT_PRIVATE;
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. return T_ERROR;
  156. }
  157. static inline int classify8(const char *s) {
  158. if (s[0] == 'o') {
  159. if (s[1] == 'p') {
  160. if (s[2] == 't') {
  161. if (s[3] == 'i') {
  162. if (s[4] == 'o') {
  163. if (s[5] == 'n') {
  164. if (s[6] == 'a') {
  165. if (s[7] == 'l') {
  166. return T_AT_OPTIONAL;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }
  175. else if (s[0] == 'p') {
  176. if (s[1] == 'r') {
  177. if (s[2] == 'o') {
  178. if (s[3] == 'p') {
  179. if (s[4] == 'e') {
  180. if (s[5] == 'r') {
  181. if (s[6] == 't') {
  182. if (s[7] == 'y') {
  183. return T_AT_PROPERTY;
  184. }
  185. }
  186. }
  187. }
  188. }
  189. else if (s[3] == 't') {
  190. if (s[4] == 'o') {
  191. if (s[5] == 'c') {
  192. if (s[6] == 'o') {
  193. if (s[7] == 'l') {
  194. return T_AT_PROTOCOL;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. else if (s[0] == 'r') {
  204. if (s[1] == 'e') {
  205. if (s[2] == 'q') {
  206. if (s[3] == 'u') {
  207. if (s[4] == 'i') {
  208. if (s[5] == 'r') {
  209. if (s[6] == 'e') {
  210. if (s[7] == 'd') {
  211. return T_AT_REQUIRED;
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. else if (s[0] == 's') {
  221. if (s[1] == 'e') {
  222. if (s[2] == 'l') {
  223. if (s[3] == 'e') {
  224. if (s[4] == 'c') {
  225. if (s[5] == 't') {
  226. if (s[6] == 'o') {
  227. if (s[7] == 'r') {
  228. return T_AT_SELECTOR;
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235. }
  236. }
  237. return T_ERROR;
  238. }
  239. static inline int classify9(const char *s) {
  240. if (s[0] == 'i') {
  241. if (s[1] == 'n') {
  242. if (s[2] == 't') {
  243. if (s[3] == 'e') {
  244. if (s[4] == 'r') {
  245. if (s[5] == 'f') {
  246. if (s[6] == 'a') {
  247. if (s[7] == 'c') {
  248. if (s[8] == 'e') {
  249. return T_AT_INTERFACE;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. else if (s[0] == 'p') {
  260. if (s[1] == 'r') {
  261. if (s[2] == 'o') {
  262. if (s[3] == 't') {
  263. if (s[4] == 'e') {
  264. if (s[5] == 'c') {
  265. if (s[6] == 't') {
  266. if (s[7] == 'e') {
  267. if (s[8] == 'd') {
  268. return T_AT_PROTECTED;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. return T_ERROR;
  279. }
  280. static inline int classify10(const char *s) {
  281. if (s[0] == 's') {
  282. if (s[1] == 'y') {
  283. if (s[2] == 'n') {
  284. if (s[3] == 't') {
  285. if (s[4] == 'h') {
  286. if (s[5] == 'e') {
  287. if (s[6] == 's') {
  288. if (s[7] == 'i') {
  289. if (s[8] == 'z') {
  290. if (s[9] == 'e') {
  291. return T_AT_SYNTHESIZE;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. return T_ERROR;
  303. }
  304. static inline int classify11(const char *s) {
  305. if (s[0] == 'n') {
  306. if (s[1] == 'o') {
  307. if (s[2] == 't') {
  308. if (s[3] == '_') {
  309. if (s[4] == 'k') {
  310. if (s[5] == 'e') {
  311. if (s[6] == 'y') {
  312. if (s[7] == 'w') {
  313. if (s[8] == 'o') {
  314. if (s[9] == 'r') {
  315. if (s[10] == 'd') {
  316. return T_AT_NOT_KEYWORD;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. }
  328. return T_ERROR;
  329. }
  330. static inline int classify12(const char *s) {
  331. if (s[0] == 's') {
  332. if (s[1] == 'y') {
  333. if (s[2] == 'n') {
  334. if (s[3] == 'c') {
  335. if (s[4] == 'h') {
  336. if (s[5] == 'r') {
  337. if (s[6] == 'o') {
  338. if (s[7] == 'n') {
  339. if (s[8] == 'i') {
  340. if (s[9] == 'z') {
  341. if (s[10] == 'e') {
  342. if (s[11] == 'd') {
  343. return T_AT_SYNCHRONIZED;
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. return T_ERROR;
  357. }
  358. static inline int classify14(const char *s) {
  359. if (s[0] == 'i') {
  360. if (s[1] == 'm') {
  361. if (s[2] == 'p') {
  362. if (s[3] == 'l') {
  363. if (s[4] == 'e') {
  364. if (s[5] == 'm') {
  365. if (s[6] == 'e') {
  366. if (s[7] == 'n') {
  367. if (s[8] == 't') {
  368. if (s[9] == 'a') {
  369. if (s[10] == 't') {
  370. if (s[11] == 'i') {
  371. if (s[12] == 'o') {
  372. if (s[13] == 'n') {
  373. return T_AT_IMPLEMENTATION;
  374. }
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. return T_ERROR;
  389. }
  390. static inline int classify19(const char *s) {
  391. if (s[0] == 'c') {
  392. if (s[1] == 'o') {
  393. if (s[2] == 'm') {
  394. if (s[3] == 'p') {
  395. if (s[4] == 'a') {
  396. if (s[5] == 't') {
  397. if (s[6] == 'i') {
  398. if (s[7] == 'b') {
  399. if (s[8] == 'i') {
  400. if (s[9] == 'l') {
  401. if (s[10] == 'i') {
  402. if (s[11] == 't') {
  403. if (s[12] == 'y') {
  404. if (s[13] == '_') {
  405. if (s[14] == 'a') {
  406. if (s[15] == 'l') {
  407. if (s[16] == 'i') {
  408. if (s[17] == 'a') {
  409. if (s[18] == 's') {
  410. return T_AT_COMPATIBILITY_ALIAS;
  411. }
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. }
  421. }
  422. }
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. return T_ERROR;
  431. }
  432. int Lexer::classifyObjCAtKeyword(const char *s, int n) {
  433. switch (n) {
  434. case 3: return classify3(s);
  435. case 4: return classify4(s);
  436. case 5: return classify5(s);
  437. case 6: return classify6(s);
  438. case 7: return classify7(s);
  439. case 8: return classify8(s);
  440. case 9: return classify9(s);
  441. case 10: return classify10(s);
  442. case 11: return classify11(s);
  443. case 12: return classify12(s);
  444. case 14: return classify14(s);
  445. case 19: return classify19(s);
  446. default: return T_ERROR;
  447. } // switch
  448. }