PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Source/CParse/cscanner.c

#
C | 847 lines | 650 code | 84 blank | 113 comment | 294 complexity | ae919fd7b3f210c4c53863c252123848 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * This file is part of SWIG, which is licensed as a whole under version 3
  3. * (or any later version) of the GNU General Public License. Some additional
  4. * terms also apply to certain portions of SWIG. The full details of the SWIG
  5. * license and copyrights can be found in the LICENSE and COPYRIGHT files
  6. * included with the SWIG source code as distributed by the SWIG developers
  7. * and at http://www.swig.org/legal.html.
  8. *
  9. * scanner.c
  10. *
  11. * SWIG tokenizer. This file is a wrapper around the generic C scanner
  12. * found in Swig/scanner.c. Extra logic is added both to accomodate the
  13. * bison-based grammar and certain peculiarities of C++ parsing (e.g.,
  14. * operator overloading, typedef resolution, etc.). This code also splits
  15. * C identifiers up into keywords and SWIG directives.
  16. * ----------------------------------------------------------------------------- */
  17. char cvsroot_cscanner_c[] = "$Id: cscanner.c 12924 2012-03-15 20:32:14Z wsfulton $";
  18. #include "cparse.h"
  19. #include "parser.h"
  20. #include <string.h>
  21. #include <ctype.h>
  22. /* Scanner object */
  23. static Scanner *scan = 0;
  24. /* Global string containing C code. Used by the parser to grab code blocks */
  25. String *scanner_ccode = 0;
  26. /* The main file being parsed */
  27. static String *main_input_file = 0;
  28. /* Error reporting/location information */
  29. int cparse_line = 1;
  30. String *cparse_file = 0;
  31. int cparse_start_line = 0;
  32. /* C++ mode */
  33. int cparse_cplusplus = 0;
  34. /* Private vars */
  35. static int scan_init = 0;
  36. static int num_brace = 0;
  37. static int last_brace = 0;
  38. static int last_id = 0;
  39. static int rename_active = 0;
  40. /* -----------------------------------------------------------------------------
  41. * Swig_cparse_cplusplus()
  42. * ----------------------------------------------------------------------------- */
  43. void Swig_cparse_cplusplus(int v) {
  44. cparse_cplusplus = v;
  45. }
  46. /* ----------------------------------------------------------------------------
  47. * scanner_init()
  48. *
  49. * Initialize buffers
  50. * ------------------------------------------------------------------------- */
  51. void scanner_init() {
  52. scan = NewScanner();
  53. Scanner_idstart(scan,"%");
  54. scan_init = 1;
  55. scanner_ccode = NewStringEmpty();
  56. }
  57. /* ----------------------------------------------------------------------------
  58. * scanner_file(DOHFile *f)
  59. *
  60. * Start reading from new file
  61. * ------------------------------------------------------------------------- */
  62. void scanner_file(DOHFile * f) {
  63. if (!scan_init) scanner_init();
  64. Scanner_clear(scan);
  65. Scanner_push(scan,f);
  66. }
  67. /* ----------------------------------------------------------------------------
  68. * start_inline(char *text, int line)
  69. *
  70. * Take a chunk of text and recursively feed it back into the scanner. Used
  71. * by the %inline directive.
  72. * ------------------------------------------------------------------------- */
  73. void start_inline(char *text, int line) {
  74. String *stext = NewString(text);
  75. Seek(stext,0,SEEK_SET);
  76. Setfile(stext,cparse_file);
  77. Setline(stext,line);
  78. Scanner_push(scan,stext);
  79. Delete(stext);
  80. }
  81. /* -----------------------------------------------------------------------------
  82. * skip_balanced()
  83. *
  84. * Skips a piece of code enclosed in begin/end symbols such as '{...}' or
  85. * (...). Ignores symbols inside comments or strings.
  86. * ----------------------------------------------------------------------------- */
  87. void skip_balanced(int startchar, int endchar) {
  88. Clear(scanner_ccode);
  89. if (Scanner_skip_balanced(scan,startchar,endchar) < 0) {
  90. Swig_error(Scanner_file(scan),Scanner_errline(scan), "Missing '%c'. Reached end of input.\n", endchar);
  91. return;
  92. }
  93. cparse_line = Scanner_line(scan);
  94. cparse_file = Scanner_file(scan);
  95. Append(scanner_ccode, Scanner_text(scan));
  96. if (endchar == '}')
  97. num_brace--;
  98. return;
  99. }
  100. /* ----------------------------------------------------------------------------
  101. * void skip_decl(void)
  102. *
  103. * This tries to skip over an entire declaration. For example
  104. *
  105. * friend ostream& operator<<(ostream&, const char *s);
  106. *
  107. * or
  108. * friend ostream& operator<<(ostream&, const char *s) { };
  109. *
  110. * ------------------------------------------------------------------------- */
  111. void skip_decl(void) {
  112. int tok;
  113. int done = 0;
  114. int start_line = Scanner_line(scan);
  115. while (!done) {
  116. tok = Scanner_token(scan);
  117. if (tok == 0) {
  118. if (!Swig_error_count()) {
  119. Swig_error(cparse_file, start_line, "Missing semicolon. Reached end of input.\n");
  120. }
  121. return;
  122. }
  123. if (tok == SWIG_TOKEN_LBRACE) {
  124. if (Scanner_skip_balanced(scan,'{','}') < 0) {
  125. Swig_error(cparse_file, start_line, "Missing '}'. Reached end of input.\n");
  126. }
  127. break;
  128. }
  129. if (tok == SWIG_TOKEN_SEMI) {
  130. done = 1;
  131. }
  132. }
  133. cparse_file = Scanner_file(scan);
  134. cparse_line = Scanner_line(scan);
  135. }
  136. /* ----------------------------------------------------------------------------
  137. * int yylook()
  138. *
  139. * Lexical scanner.
  140. * ------------------------------------------------------------------------- */
  141. static int yylook(void) {
  142. int tok = 0;
  143. while (1) {
  144. if ((tok = Scanner_token(scan)) == 0)
  145. return 0;
  146. if (tok == SWIG_TOKEN_ERROR)
  147. return 0;
  148. cparse_start_line = Scanner_start_line(scan);
  149. cparse_line = Scanner_line(scan);
  150. cparse_file = Scanner_file(scan);
  151. switch(tok) {
  152. case SWIG_TOKEN_ID:
  153. return ID;
  154. case SWIG_TOKEN_LPAREN:
  155. return LPAREN;
  156. case SWIG_TOKEN_RPAREN:
  157. return RPAREN;
  158. case SWIG_TOKEN_SEMI:
  159. return SEMI;
  160. case SWIG_TOKEN_COMMA:
  161. return COMMA;
  162. case SWIG_TOKEN_STAR:
  163. return STAR;
  164. case SWIG_TOKEN_RBRACE:
  165. num_brace--;
  166. if (num_brace < 0) {
  167. Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '}'\n");
  168. num_brace = 0;
  169. } else {
  170. return RBRACE;
  171. }
  172. break;
  173. case SWIG_TOKEN_LBRACE:
  174. last_brace = num_brace;
  175. num_brace++;
  176. return LBRACE;
  177. case SWIG_TOKEN_EQUAL:
  178. return EQUAL;
  179. case SWIG_TOKEN_EQUALTO:
  180. return EQUALTO;
  181. case SWIG_TOKEN_PLUS:
  182. return PLUS;
  183. case SWIG_TOKEN_MINUS:
  184. return MINUS;
  185. case SWIG_TOKEN_SLASH:
  186. return SLASH;
  187. case SWIG_TOKEN_AND:
  188. return AND;
  189. case SWIG_TOKEN_LAND:
  190. return LAND;
  191. case SWIG_TOKEN_OR:
  192. return OR;
  193. case SWIG_TOKEN_LOR:
  194. return LOR;
  195. case SWIG_TOKEN_XOR:
  196. return XOR;
  197. case SWIG_TOKEN_NOT:
  198. return NOT;
  199. case SWIG_TOKEN_LNOT:
  200. return LNOT;
  201. case SWIG_TOKEN_NOTEQUAL:
  202. return NOTEQUALTO;
  203. case SWIG_TOKEN_LBRACKET:
  204. return LBRACKET;
  205. case SWIG_TOKEN_RBRACKET:
  206. return RBRACKET;
  207. case SWIG_TOKEN_QUESTION:
  208. return QUESTIONMARK;
  209. case SWIG_TOKEN_LESSTHAN:
  210. return LESSTHAN;
  211. case SWIG_TOKEN_LTEQUAL:
  212. return LESSTHANOREQUALTO;
  213. case SWIG_TOKEN_LSHIFT:
  214. return LSHIFT;
  215. case SWIG_TOKEN_GREATERTHAN:
  216. return GREATERTHAN;
  217. case SWIG_TOKEN_GTEQUAL:
  218. return GREATERTHANOREQUALTO;
  219. case SWIG_TOKEN_RSHIFT:
  220. return RSHIFT;
  221. case SWIG_TOKEN_PERIOD:
  222. return PERIOD;
  223. case SWIG_TOKEN_MODULO:
  224. return MODULO;
  225. case SWIG_TOKEN_COLON:
  226. return COLON;
  227. case SWIG_TOKEN_DCOLONSTAR:
  228. return DSTAR;
  229. case SWIG_TOKEN_DCOLON:
  230. {
  231. int nexttok = Scanner_token(scan);
  232. if (nexttok == SWIG_TOKEN_STAR) {
  233. return DSTAR;
  234. } else if (nexttok == SWIG_TOKEN_NOT) {
  235. return DCNOT;
  236. } else {
  237. Scanner_pushtoken(scan,nexttok,Scanner_text(scan));
  238. if (!last_id) {
  239. scanner_next_token(DCOLON);
  240. return NONID;
  241. } else {
  242. return DCOLON;
  243. }
  244. }
  245. }
  246. break;
  247. /* Look for multi-character sequences */
  248. case SWIG_TOKEN_RSTRING:
  249. yylval.type = NewString(Scanner_text(scan));
  250. return TYPE_RAW;
  251. case SWIG_TOKEN_STRING:
  252. yylval.id = Swig_copy_string(Char(Scanner_text(scan)));
  253. return STRING;
  254. case SWIG_TOKEN_CHAR:
  255. yylval.str = NewString(Scanner_text(scan));
  256. if (Len(yylval.str) == 0) {
  257. Swig_error(cparse_file, cparse_line, "Empty character constant\n");
  258. Printf(stdout,"%d\n", Len(Scanner_text(scan)));
  259. }
  260. return CHARCONST;
  261. /* Numbers */
  262. case SWIG_TOKEN_INT:
  263. return NUM_INT;
  264. case SWIG_TOKEN_UINT:
  265. return NUM_UNSIGNED;
  266. case SWIG_TOKEN_LONG:
  267. return NUM_LONG;
  268. case SWIG_TOKEN_ULONG:
  269. return NUM_ULONG;
  270. case SWIG_TOKEN_LONGLONG:
  271. return NUM_LONGLONG;
  272. case SWIG_TOKEN_ULONGLONG:
  273. return NUM_ULONGLONG;
  274. case SWIG_TOKEN_DOUBLE:
  275. case SWIG_TOKEN_FLOAT:
  276. return NUM_FLOAT;
  277. case SWIG_TOKEN_BOOL:
  278. return NUM_BOOL;
  279. case SWIG_TOKEN_POUND:
  280. Scanner_skip_line(scan);
  281. yylval.id = Swig_copy_string(Char(Scanner_text(scan)));
  282. return POUND;
  283. break;
  284. case SWIG_TOKEN_CODEBLOCK:
  285. yylval.str = NewString(Scanner_text(scan));
  286. return HBLOCK;
  287. case SWIG_TOKEN_COMMENT:
  288. {
  289. String *cmt = Scanner_text(scan);
  290. char *loc = Char(cmt);
  291. if ((strncmp(loc,"/*@SWIG",7) == 0) && (loc[Len(cmt)-3] == '@')) {
  292. Scanner_locator(scan, cmt);
  293. }
  294. }
  295. break;
  296. case SWIG_TOKEN_ENDLINE:
  297. break;
  298. case SWIG_TOKEN_BACKSLASH:
  299. break;
  300. default:
  301. Swig_error(cparse_file, cparse_line, "Illegal token '%s'.\n", Scanner_text(scan));
  302. return (ILLEGAL);
  303. }
  304. }
  305. }
  306. static int check_typedef = 0;
  307. void scanner_set_location(String *file, int line) {
  308. Scanner_set_location(scan,file,line-1);
  309. }
  310. void scanner_check_typedef() {
  311. check_typedef = 1;
  312. }
  313. void scanner_ignore_typedef() {
  314. check_typedef = 0;
  315. }
  316. void scanner_last_id(int x) {
  317. last_id = x;
  318. }
  319. void scanner_clear_rename() {
  320. rename_active = 0;
  321. }
  322. /* Used to push a ficticious token into the scanner */
  323. static int next_token = 0;
  324. void scanner_next_token(int tok) {
  325. next_token = tok;
  326. }
  327. void scanner_set_main_input_file(String *file) {
  328. main_input_file = file;
  329. }
  330. String *scanner_get_main_input_file() {
  331. return main_input_file;
  332. }
  333. /* ----------------------------------------------------------------------------
  334. * int yylex()
  335. *
  336. * Gets the lexene and returns tokens.
  337. * ------------------------------------------------------------------------- */
  338. int yylex(void) {
  339. int l;
  340. char *yytext;
  341. if (!scan_init) {
  342. scanner_init();
  343. }
  344. if (next_token) {
  345. l = next_token;
  346. next_token = 0;
  347. return l;
  348. }
  349. l = yylook();
  350. /* Swig_diagnostic(cparse_file, cparse_line, ":::%d: '%s'\n", l, Scanner_text(scan)); */
  351. if (l == NONID) {
  352. last_id = 1;
  353. } else {
  354. last_id = 0;
  355. }
  356. /* We got some sort of non-white space object. We set the start_line
  357. variable unless it has already been set */
  358. if (!cparse_start_line) {
  359. cparse_start_line = cparse_line;
  360. }
  361. /* Copy the lexene */
  362. switch (l) {
  363. case NUM_INT:
  364. case NUM_FLOAT:
  365. case NUM_ULONG:
  366. case NUM_LONG:
  367. case NUM_UNSIGNED:
  368. case NUM_LONGLONG:
  369. case NUM_ULONGLONG:
  370. case NUM_BOOL:
  371. if (l == NUM_INT)
  372. yylval.dtype.type = T_INT;
  373. if (l == NUM_FLOAT)
  374. yylval.dtype.type = T_DOUBLE;
  375. if (l == NUM_ULONG)
  376. yylval.dtype.type = T_ULONG;
  377. if (l == NUM_LONG)
  378. yylval.dtype.type = T_LONG;
  379. if (l == NUM_UNSIGNED)
  380. yylval.dtype.type = T_UINT;
  381. if (l == NUM_LONGLONG)
  382. yylval.dtype.type = T_LONGLONG;
  383. if (l == NUM_ULONGLONG)
  384. yylval.dtype.type = T_ULONGLONG;
  385. if (l == NUM_BOOL)
  386. yylval.dtype.type = T_BOOL;
  387. yylval.dtype.val = NewString(Scanner_text(scan));
  388. yylval.dtype.bitfield = 0;
  389. yylval.dtype.throws = 0;
  390. return (l);
  391. case ID:
  392. yytext = Char(Scanner_text(scan));
  393. if (yytext[0] != '%') {
  394. /* Look for keywords now */
  395. if (strcmp(yytext, "int") == 0) {
  396. yylval.type = NewSwigType(T_INT);
  397. return (TYPE_INT);
  398. }
  399. if (strcmp(yytext, "double") == 0) {
  400. yylval.type = NewSwigType(T_DOUBLE);
  401. return (TYPE_DOUBLE);
  402. }
  403. if (strcmp(yytext, "void") == 0) {
  404. yylval.type = NewSwigType(T_VOID);
  405. return (TYPE_VOID);
  406. }
  407. if (strcmp(yytext, "char") == 0) {
  408. yylval.type = NewSwigType(T_CHAR);
  409. return (TYPE_CHAR);
  410. }
  411. if (strcmp(yytext, "wchar_t") == 0) {
  412. yylval.type = NewSwigType(T_WCHAR);
  413. return (TYPE_WCHAR);
  414. }
  415. if (strcmp(yytext, "short") == 0) {
  416. yylval.type = NewSwigType(T_SHORT);
  417. return (TYPE_SHORT);
  418. }
  419. if (strcmp(yytext, "long") == 0) {
  420. yylval.type = NewSwigType(T_LONG);
  421. return (TYPE_LONG);
  422. }
  423. if (strcmp(yytext, "float") == 0) {
  424. yylval.type = NewSwigType(T_FLOAT);
  425. return (TYPE_FLOAT);
  426. }
  427. if (strcmp(yytext, "signed") == 0) {
  428. yylval.type = NewSwigType(T_INT);
  429. return (TYPE_SIGNED);
  430. }
  431. if (strcmp(yytext, "unsigned") == 0) {
  432. yylval.type = NewSwigType(T_UINT);
  433. return (TYPE_UNSIGNED);
  434. }
  435. if (strcmp(yytext, "bool") == 0) {
  436. yylval.type = NewSwigType(T_BOOL);
  437. return (TYPE_BOOL);
  438. }
  439. /* Non ISO (Windows) C extensions */
  440. if (strcmp(yytext, "__int8") == 0) {
  441. yylval.type = NewString(yytext);
  442. return (TYPE_NON_ISO_INT8);
  443. }
  444. if (strcmp(yytext, "__int16") == 0) {
  445. yylval.type = NewString(yytext);
  446. return (TYPE_NON_ISO_INT16);
  447. }
  448. if (strcmp(yytext, "__int32") == 0) {
  449. yylval.type = NewString(yytext);
  450. return (TYPE_NON_ISO_INT32);
  451. }
  452. if (strcmp(yytext, "__int64") == 0) {
  453. yylval.type = NewString(yytext);
  454. return (TYPE_NON_ISO_INT64);
  455. }
  456. /* C++ keywords */
  457. if (cparse_cplusplus) {
  458. if (strcmp(yytext, "and") == 0)
  459. return (LAND);
  460. if (strcmp(yytext, "or") == 0)
  461. return (LOR);
  462. if (strcmp(yytext, "not") == 0)
  463. return (LNOT);
  464. if (strcmp(yytext, "class") == 0)
  465. return (CLASS);
  466. if (strcmp(yytext, "private") == 0)
  467. return (PRIVATE);
  468. if (strcmp(yytext, "public") == 0)
  469. return (PUBLIC);
  470. if (strcmp(yytext, "protected") == 0)
  471. return (PROTECTED);
  472. if (strcmp(yytext, "friend") == 0)
  473. return (FRIEND);
  474. if (strcmp(yytext, "virtual") == 0)
  475. return (VIRTUAL);
  476. if (strcmp(yytext, "operator") == 0) {
  477. int nexttok;
  478. String *s = NewString("operator ");
  479. /* If we have an operator, we have to collect the operator symbol and attach it to
  480. the operator identifier. To do this, we need to scan ahead by several tokens.
  481. Cases include:
  482. (1) If the next token is an operator as determined by Scanner_isoperator(),
  483. it means that the operator applies to one of the standard C++ mathematical,
  484. assignment, or logical operator symbols (e.g., '+','<=','==','&', etc.)
  485. In this case, we merely append the symbol text to the operator string above.
  486. (2) If the next token is (, we look for ). This is operator ().
  487. (3) If the next token is [, we look for ]. This is operator [].
  488. (4) If the next token is an identifier. The operator is possibly a conversion operator.
  489. (a) Must check for special case new[] and delete[]
  490. Error handling is somewhat tricky here. We'll try to back out gracefully if we can.
  491. */
  492. nexttok = Scanner_token(scan);
  493. if (Scanner_isoperator(nexttok)) {
  494. /* One of the standard C/C++ symbolic operators */
  495. Append(s,Scanner_text(scan));
  496. yylval.str = s;
  497. return OPERATOR;
  498. } else if (nexttok == SWIG_TOKEN_LPAREN) {
  499. /* Function call operator. The next token MUST be a RPAREN */
  500. nexttok = Scanner_token(scan);
  501. if (nexttok != SWIG_TOKEN_RPAREN) {
  502. Swig_error(Scanner_file(scan),Scanner_line(scan),"Syntax error. Bad operator name.\n");
  503. } else {
  504. Append(s,"()");
  505. yylval.str = s;
  506. return OPERATOR;
  507. }
  508. } else if (nexttok == SWIG_TOKEN_LBRACKET) {
  509. /* Array access operator. The next token MUST be a RBRACKET */
  510. nexttok = Scanner_token(scan);
  511. if (nexttok != SWIG_TOKEN_RBRACKET) {
  512. Swig_error(Scanner_file(scan),Scanner_line(scan),"Syntax error. Bad operator name.\n");
  513. } else {
  514. Append(s,"[]");
  515. yylval.str = s;
  516. return OPERATOR;
  517. }
  518. } else if (nexttok == SWIG_TOKEN_ID) {
  519. /* We have an identifier. This could be any number of things. It could be a named version of
  520. an operator (e.g., 'and_eq') or it could be a conversion operator. To deal with this, we're
  521. going to read tokens until we encounter a ( or ;. Some care is needed for formatting. */
  522. int needspace = 1;
  523. int termtoken = 0;
  524. const char *termvalue = 0;
  525. Append(s,Scanner_text(scan));
  526. while (1) {
  527. nexttok = Scanner_token(scan);
  528. if (nexttok <= 0) {
  529. Swig_error(Scanner_file(scan),Scanner_line(scan),"Syntax error. Bad operator name.\n");
  530. }
  531. if (nexttok == SWIG_TOKEN_LPAREN) {
  532. termtoken = SWIG_TOKEN_LPAREN;
  533. termvalue = "(";
  534. break;
  535. } else if (nexttok == SWIG_TOKEN_CODEBLOCK) {
  536. termtoken = SWIG_TOKEN_CODEBLOCK;
  537. termvalue = Char(Scanner_text(scan));
  538. break;
  539. } else if (nexttok == SWIG_TOKEN_LBRACE) {
  540. termtoken = SWIG_TOKEN_LBRACE;
  541. termvalue = "{";
  542. break;
  543. } else if (nexttok == SWIG_TOKEN_SEMI) {
  544. termtoken = SWIG_TOKEN_SEMI;
  545. termvalue = ";";
  546. break;
  547. } else if (nexttok == SWIG_TOKEN_STRING) {
  548. termtoken = SWIG_TOKEN_STRING;
  549. termvalue = Swig_copy_string(Char(Scanner_text(scan)));
  550. break;
  551. } else if (nexttok == SWIG_TOKEN_ID) {
  552. if (needspace) {
  553. Append(s," ");
  554. }
  555. Append(s,Scanner_text(scan));
  556. } else {
  557. Append(s,Scanner_text(scan));
  558. needspace = 0;
  559. }
  560. }
  561. yylval.str = s;
  562. if (!rename_active) {
  563. String *cs;
  564. char *t = Char(s) + 9;
  565. if (!((strcmp(t, "new") == 0)
  566. || (strcmp(t, "delete") == 0)
  567. || (strcmp(t, "new[]") == 0)
  568. || (strcmp(t, "delete[]") == 0)
  569. || (strcmp(t, "and") == 0)
  570. || (strcmp(t, "and_eq") == 0)
  571. || (strcmp(t, "bitand") == 0)
  572. || (strcmp(t, "bitor") == 0)
  573. || (strcmp(t, "compl") == 0)
  574. || (strcmp(t, "not") == 0)
  575. || (strcmp(t, "not_eq") == 0)
  576. || (strcmp(t, "or") == 0)
  577. || (strcmp(t, "or_eq") == 0)
  578. || (strcmp(t, "xor") == 0)
  579. || (strcmp(t, "xor_eq") == 0)
  580. )) {
  581. /* retract(strlen(t)); */
  582. /* The operator is a conversion operator. In order to deal with this, we need to feed the
  583. type information back into the parser. For now this is a hack. Needs to be cleaned up later. */
  584. cs = NewString(t);
  585. if (termtoken) Append(cs,termvalue);
  586. Seek(cs,0,SEEK_SET);
  587. Setline(cs,cparse_line);
  588. Setfile(cs,cparse_file);
  589. Scanner_push(scan,cs);
  590. Delete(cs);
  591. return COPERATOR;
  592. }
  593. }
  594. if (termtoken)
  595. Scanner_pushtoken(scan, termtoken, termvalue);
  596. return (OPERATOR);
  597. }
  598. }
  599. if (strcmp(yytext, "throw") == 0)
  600. return (THROW);
  601. if (strcmp(yytext, "try") == 0)
  602. return (yylex());
  603. if (strcmp(yytext, "catch") == 0)
  604. return (CATCH);
  605. if (strcmp(yytext, "inline") == 0)
  606. return (yylex());
  607. if (strcmp(yytext, "mutable") == 0)
  608. return (yylex());
  609. if (strcmp(yytext, "explicit") == 0)
  610. return (EXPLICIT);
  611. if (strcmp(yytext, "export") == 0)
  612. return (yylex());
  613. if (strcmp(yytext, "typename") == 0)
  614. return (TYPENAME);
  615. if (strcmp(yytext, "template") == 0) {
  616. yylval.intvalue = cparse_line;
  617. return (TEMPLATE);
  618. }
  619. if (strcmp(yytext, "delete") == 0) {
  620. return (DELETE_KW);
  621. }
  622. if (strcmp(yytext, "using") == 0) {
  623. return (USING);
  624. }
  625. if (strcmp(yytext, "namespace") == 0) {
  626. return (NAMESPACE);
  627. }
  628. } else {
  629. if (strcmp(yytext, "class") == 0) {
  630. Swig_warning(WARN_PARSE_CLASS_KEYWORD, cparse_file, cparse_line, "class keyword used, but not in C++ mode.\n");
  631. }
  632. if (strcmp(yytext, "complex") == 0) {
  633. yylval.type = NewSwigType(T_COMPLEX);
  634. return (TYPE_COMPLEX);
  635. }
  636. if (strcmp(yytext, "restrict") == 0)
  637. return (yylex());
  638. }
  639. /* Misc keywords */
  640. if (strcmp(yytext, "extern") == 0)
  641. return (EXTERN);
  642. if (strcmp(yytext, "const") == 0)
  643. return (CONST_QUAL);
  644. if (strcmp(yytext, "static") == 0)
  645. return (STATIC);
  646. if (strcmp(yytext, "struct") == 0)
  647. return (STRUCT);
  648. if (strcmp(yytext, "union") == 0)
  649. return (UNION);
  650. if (strcmp(yytext, "enum") == 0)
  651. return (ENUM);
  652. if (strcmp(yytext, "sizeof") == 0)
  653. return (SIZEOF);
  654. if (strcmp(yytext, "typedef") == 0) {
  655. yylval.intvalue = 0;
  656. return (TYPEDEF);
  657. }
  658. /* Ignored keywords */
  659. if (strcmp(yytext, "volatile") == 0)
  660. return (VOLATILE);
  661. if (strcmp(yytext, "register") == 0)
  662. return (REGISTER);
  663. if (strcmp(yytext, "inline") == 0)
  664. return (yylex());
  665. /* SWIG directives */
  666. } else {
  667. if (strcmp(yytext, "%module") == 0)
  668. return (MODULE);
  669. if (strcmp(yytext, "%insert") == 0)
  670. return (INSERT);
  671. if (strcmp(yytext, "%name") == 0)
  672. return (NAME);
  673. if (strcmp(yytext, "%rename") == 0) {
  674. rename_active = 1;
  675. return (RENAME);
  676. }
  677. if (strcmp(yytext, "%namewarn") == 0) {
  678. rename_active = 1;
  679. return (NAMEWARN);
  680. }
  681. if (strcmp(yytext, "%includefile") == 0)
  682. return (INCLUDE);
  683. if (strcmp(yytext, "%beginfile") == 0)
  684. return (BEGINFILE);
  685. if (strcmp(yytext, "%endoffile") == 0)
  686. return (ENDOFFILE);
  687. if (strcmp(yytext, "%val") == 0) {
  688. Swig_warning(WARN_DEPRECATED_VAL, cparse_file, cparse_line, "%%val directive deprecated (ignored).\n");
  689. return (yylex());
  690. }
  691. if (strcmp(yytext, "%out") == 0) {
  692. Swig_warning(WARN_DEPRECATED_OUT, cparse_file, cparse_line, "%%out directive deprecated (ignored).\n");
  693. return (yylex());
  694. }
  695. if (strcmp(yytext, "%constant") == 0)
  696. return (CONSTANT);
  697. if (strcmp(yytext, "%typedef") == 0) {
  698. yylval.intvalue = 1;
  699. return (TYPEDEF);
  700. }
  701. if (strcmp(yytext, "%native") == 0)
  702. return (NATIVE);
  703. if (strcmp(yytext, "%pragma") == 0)
  704. return (PRAGMA);
  705. if (strcmp(yytext, "%extend") == 0)
  706. return (EXTEND);
  707. if (strcmp(yytext, "%fragment") == 0)
  708. return (FRAGMENT);
  709. if (strcmp(yytext, "%inline") == 0)
  710. return (INLINE);
  711. if (strcmp(yytext, "%typemap") == 0)
  712. return (TYPEMAP);
  713. if (strcmp(yytext, "%feature") == 0) {
  714. /* The rename_active indicates we don't need the information of the
  715. * following function's return type. This applied for %rename, so do
  716. * %feature.
  717. */
  718. rename_active = 1;
  719. return (FEATURE);
  720. }
  721. if (strcmp(yytext, "%except") == 0)
  722. return (EXCEPT);
  723. if (strcmp(yytext, "%importfile") == 0)
  724. return (IMPORT);
  725. if (strcmp(yytext, "%echo") == 0)
  726. return (ECHO);
  727. if (strcmp(yytext, "%apply") == 0)
  728. return (APPLY);
  729. if (strcmp(yytext, "%clear") == 0)
  730. return (CLEAR);
  731. if (strcmp(yytext, "%types") == 0)
  732. return (TYPES);
  733. if (strcmp(yytext, "%parms") == 0)
  734. return (PARMS);
  735. if (strcmp(yytext, "%varargs") == 0)
  736. return (VARARGS);
  737. if (strcmp(yytext, "%template") == 0) {
  738. return (SWIGTEMPLATE);
  739. }
  740. if (strcmp(yytext, "%warn") == 0)
  741. return (WARN);
  742. }
  743. /* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */
  744. /* Need to fix this */
  745. if (check_typedef) {
  746. if (SwigType_istypedef(yytext)) {
  747. yylval.type = NewString(yytext);
  748. return (TYPE_TYPEDEF);
  749. }
  750. }
  751. yylval.id = Swig_copy_string(yytext);
  752. last_id = 1;
  753. return (ID);
  754. case POUND:
  755. return yylex();
  756. default:
  757. return (l);
  758. }
  759. }