/plugins/JavaSideKick/tags/javasidekick-2-3-1/src/sidekick/java/parser/TigerParser.java

# · Java · 2340 lines · 2099 code · 89 blank · 152 comment · 382 complexity · 9694de4aaba2bb9e4b2e4269e0020066 MD5 · raw file

Large files are truncated click here to view the full file

  1. /* Generated By:JavaCC: Do not edit this line. TigerParser.java */
  2. package sidekick.java.parser;
  3. import sidekick.java.node.*;
  4. import sidekick.java.util.Log;
  5. import java.io.*;
  6. import java.util.*;
  7. /**
  8. * Based on grammar to parse Java version 1.5 written by Sreenivasa Viswanadha,
  9. * parses a java file for the JavaSideKick plugin to provide a java code
  10. * browser that works with java 1.5. I've also updated this file so it will
  11. * parse javacc files for JavaSideKick too, that makes it a lot easier to edit
  12. * files such as this.
  13. * <p>
  14. * Example usage to parse a java file:<p>
  15. * <code>
  16. * TigerParser parser = new TigerParser(filename);<br>
  17. * CUNode root = parser.getJavaRootNode();<br>
  18. * </code>
  19. * or to parse a javacc file:<br>
  20. * <code>
  21. * TigerParser parser = new TigerParser(filename);<br>
  22. * CUNode root = parser.getJavaCCRootNode();<br>
  23. * </code>
  24. * Calling either of the above causes the file to be parsed into
  25. * TigerNodes, of which, CUNode is the top-level. The TigerNodes have a parent/
  26. * child relastionship, which naturally forms a tree structure.
  27. * <p>
  28. * To turn this .jj file into a .java file, run <code>javacc Tiger.jj</code>
  29. * from the directory that contains this file. Javacc will produce a number of
  30. * .java files, Be careful -- not all files in the directory are produced by
  31. * javacc, in particular ModifierSet.java and Token.java are required files and
  32. * are NOT produced by javacc. So the sequence is:<br>
  33. * .jj -> javacc -> .java -> javac -> .class
  34. * <p>
  35. */
  36. public class TigerParser implements TigerParserConstants {
  37. // accumulates counts of classes, interfaces, methods and fields.
  38. private Results results = new Results();
  39. private InputStream inputStream = null;
  40. /**
  41. * Constructor for TigerParser. Note that JavaSideKick does not use this
  42. * constructor -- since the options for building the parser have both
  43. * USER_TOKEN_MANAGER and USER_CHAR_STREAM set to false (these are the
  44. * default values so are not explicitly set), javacc will create a
  45. * constructor "public TigerParser(InputStream)". It is that constructor
  46. * that JavaSideKick uses.
  47. * @param fileName name of the file to parse
  48. */
  49. public TigerParser(String filename)
  50. {
  51. this(System.in);
  52. try {
  53. inputStream = new FileInputStream(new File(filename));
  54. ReInit(inputStream);
  55. }
  56. catch(Exception e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. TigerParser(JavaCharStream stream) {
  61. jj_input_stream = stream;
  62. token_source = new TigerParserTokenManager(jj_input_stream);
  63. token = new Token();
  64. jj_ntk = -1;
  65. }
  66. /**
  67. * @return the accumulated counts of classes, interfaces, methods, and fields.
  68. */
  69. public Results getResults() {
  70. return results;
  71. }
  72. public Location getLocation(Token t) {
  73. if (t == null)
  74. return new Location(0, 0);
  75. return new Location(t.beginLine, t.beginColumn);
  76. }
  77. public Location getEndLocation(Token t) {
  78. if (t == null)
  79. return new Location(0, 0);
  80. return new Location(t.endLine, t.endColumn);
  81. }
  82. public Location getLocation(Modifier m) {
  83. if (m == null)
  84. return new Location(0, 0);
  85. if (m.beginLine == -1)
  86. m.beginLine = 0;
  87. return new Location(m.beginLine, m.beginColumn);
  88. }
  89. public void error_skipto(int kind) {
  90. ParseException e = generateParseException(); // generate the exception object.
  91. addException(e);
  92. Token t = null;
  93. int i = 0;
  94. do {
  95. i++;
  96. if (i > 100) {
  97. break;
  98. }
  99. t = getNextToken();
  100. } while (t != null && t.kind != kind);
  101. }
  102. private List exceptions = new ArrayList();
  103. private void addException(ParseException pe) {
  104. ErrorNode en = new ErrorNode(pe);
  105. exceptions.add(en);
  106. }
  107. public List getErrors() {
  108. return exceptions;
  109. }
  110. public void adjustModifier(Modifier m, Token t) {
  111. if (m.beginLine < t.beginLine) {
  112. m.beginLine = t.beginLine;
  113. }
  114. if (m.beginLine == t.beginLine && (t.beginColumn < m.beginColumn || m.beginColumn == -1)) {
  115. m.beginColumn = t.beginColumn;
  116. }
  117. if (m.endLine < t.endLine) {
  118. m.endLine = t.endLine;
  119. }
  120. if (m.endLine == t.endLine && m.endColumn < t.endColumn) {
  121. m.endColumn = t.endColumn;
  122. }
  123. }
  124. public void setTabSize(int size) {
  125. jj_input_stream.setTabSize(size);
  126. }
  127. public int getTabSize() {
  128. return jj_input_stream.getTabSize(0);
  129. }
  130. /*
  131. * Returns true if the next token is not in the FOLLOW list of "expansion".
  132. * It is used to decide when the end of an "expansion" has been reached.
  133. */
  134. private boolean notTailOfExpansionUnit() {
  135. Token t;
  136. t = getToken(1);
  137. if (t.kind == BIT_OR || t.kind == COMMA || t.kind == RPAREN || t.kind == RBRACE || t.kind == RBRACKET) return false;
  138. return true;
  139. }
  140. /* returns a list as a comma separated string */
  141. private String toString(List list) {
  142. if (list != null) {
  143. StringBuffer sb = new StringBuffer();
  144. for (Iterator it = list.iterator(); it.hasNext(); ) {
  145. Object o = it.next();
  146. if (o == null) {
  147. o = "null";
  148. }
  149. sb.append(o.toString());
  150. if (it.hasNext()) {
  151. sb.append(",");
  152. }
  153. }
  154. return sb.toString();
  155. }
  156. return "";
  157. }
  158. private String toTigerString(List list) {
  159. if (list != null) {
  160. StringBuffer sb = new StringBuffer();
  161. for (Iterator it = list.iterator(); it.hasNext(); ) {
  162. TigerNode tn = (TigerNode)it.next();
  163. sb.append(tn.getName()).append(", ");
  164. if (tn.getChildCount() > 0) {
  165. sb.append(toTigerString(tn.getChildren()));
  166. }
  167. }
  168. return sb.toString();
  169. }
  170. return "";
  171. }
  172. /************************************************
  173. * THE JAVACC GRAMMAR SPECIFICATION STARTS HERE *
  174. ************************************************/
  175. final public CUNode getJavaCCRootNode(int tab_size) throws ParseException {
  176. setTabSize(tab_size);
  177. CUNode n = new CUNode();
  178. List children = null;
  179. children = javacc_input();
  180. if (children != null ) {
  181. for (Iterator it = children.iterator(); it.hasNext(); ) {
  182. n.addChild((TigerNode)it.next());
  183. }
  184. }
  185. {if (true) return n;}
  186. throw new Error("Missing return statement in function");
  187. }
  188. final public List javacc_input() throws ParseException {
  189. List children = new ArrayList();
  190. TigerNode options_node = null;
  191. Token parser_node_start_t = null;
  192. Token parser_node_end_t = null;
  193. Token cunode_start_t = null;
  194. Token cunode_end_t = null;
  195. TigerNode production_node = null;
  196. TigerNode cunode = null;
  197. TigerNode parser_node = new TigerNode(){public int getOrdinal(){return TigerNode.PARSER;}};
  198. options_node = javacc_options();
  199. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("PARSER_BEGIN")) {
  200. } else {
  201. jj_consume_token(-1);
  202. throw new ParseException();
  203. }
  204. parser_node_start_t = jj_consume_token(IDENTIFIER);
  205. jj_consume_token(LPAREN);
  206. identifier();
  207. cunode_start_t = jj_consume_token(RPAREN);
  208. cunode = CompilationUnit(getTabSize());
  209. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("PARSER_END")) {
  210. } else {
  211. jj_consume_token(-1);
  212. throw new ParseException();
  213. }
  214. cunode_end_t = jj_consume_token(IDENTIFIER);
  215. jj_consume_token(LPAREN);
  216. identifier();
  217. parser_node_end_t = jj_consume_token(RPAREN);
  218. label_1:
  219. while (true) {
  220. production_node = production();
  221. children.add(production_node);
  222. if (jj_2_1(1)) {
  223. ;
  224. } else {
  225. break label_1;
  226. }
  227. }
  228. jj_consume_token(0);
  229. if (options_node != null) {
  230. children.add(options_node);
  231. }
  232. if (parser_node_start_t != null && parser_node_end_t != null ) {
  233. parser_node.setName("PARSER");
  234. parser_node.setStartLocation(getLocation(parser_node_start_t));
  235. parser_node.setEndLocation(getEndLocation(parser_node_end_t));
  236. children.add(parser_node);
  237. if (cunode != null) {
  238. cunode.setStartLocation(getLocation(cunode_start_t));
  239. cunode.setEndLocation(getEndLocation(cunode_end_t));
  240. if (cunode.getChildren() != null ) {
  241. for (Iterator it = cunode.getChildren().iterator(); it.hasNext(); ) {
  242. parser_node.addChild((TigerNode)it.next());
  243. }
  244. }
  245. else {
  246. parser_node.addChild(cunode);
  247. }
  248. }
  249. }
  250. {if (true) return children;}
  251. throw new Error("Missing return statement in function");
  252. }
  253. final public TigerNode javacc_options() throws ParseException {
  254. TigerNode tn = new TigerNode() {public int getOrdinal() { return TigerNode.OPTIONS;}};
  255. Token start_t = null;
  256. Token end_t = null;
  257. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("options")) {
  258. start_t = jj_consume_token(IDENTIFIER);
  259. jj_consume_token(LBRACE);
  260. label_2:
  261. while (true) {
  262. option_binding();
  263. if (jj_2_2(1)) {
  264. ;
  265. } else {
  266. break label_2;
  267. }
  268. }
  269. end_t = jj_consume_token(RBRACE);
  270. } else {
  271. ;
  272. }
  273. tn.setName("options");
  274. tn.setStartLocation(getLocation(start_t));
  275. tn.setEndLocation(getEndLocation(end_t));
  276. {if (true) return tn;}
  277. throw new Error("Missing return statement in function");
  278. }
  279. final public void option_binding() throws ParseException {
  280. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("LOOKAHEAD")) {
  281. identifier();
  282. } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("IGNORE_CASE")) {
  283. identifier();
  284. } else {
  285. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  286. case IDENTIFIER:
  287. jj_consume_token(IDENTIFIER);
  288. break;
  289. case STATIC:
  290. jj_consume_token(STATIC);
  291. break;
  292. default:
  293. jj_consume_token(-1);
  294. throw new ParseException();
  295. }
  296. }
  297. jj_consume_token(ASSIGN);
  298. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  299. case INTEGER_LITERAL:
  300. IntegerLiteral();
  301. break;
  302. case FALSE:
  303. case TRUE:
  304. BooleanLiteral();
  305. break;
  306. case STRING_LITERAL:
  307. StringLiteral();
  308. break;
  309. default:
  310. jj_consume_token(-1);
  311. throw new ParseException();
  312. }
  313. jj_consume_token(SEMICOLON);
  314. }
  315. final public TigerNode production() throws ParseException {
  316. TigerNode tn = null;
  317. if (jj_2_3(1)) {
  318. /*
  319. * Since JAVACODE is both a JavaCC reserved word and a Java identifier,
  320. * we need to give preference to "javacode_production" over
  321. * "bnf_production".
  322. */
  323. tn = javacode_production();
  324. } else if (jj_2_4(1)) {
  325. /*
  326. * Since SKIP, TOKEN, etc. are both JavaCC reserved words and Java
  327. * identifiers, we need to give preference to "regular_expression_production"
  328. * over "bnf_production".
  329. */
  330. tn = regular_expr_production();
  331. } else if (jj_2_5(1)) {
  332. /*
  333. * Since TOKEN_MGR_DECLS is both a JavaCC reserved word and a Java identifier,
  334. * we need to give preference to "token_manager_decls" over
  335. * "bnf_production".
  336. */
  337. tn = token_manager_decls();
  338. } else {
  339. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  340. case BOOLEAN:
  341. case BYTE:
  342. case CHAR:
  343. case DOUBLE:
  344. case FLOAT:
  345. case INT:
  346. case LONG:
  347. case SHORT:
  348. case VOID:
  349. case IDENTIFIER:
  350. tn = bnf_production();
  351. break;
  352. default:
  353. jj_consume_token(-1);
  354. throw new ParseException();
  355. }
  356. }
  357. {if (true) return tn;}
  358. throw new Error("Missing return statement in function");
  359. }
  360. final public TigerNode javacode_production() throws ParseException {
  361. JavaCodeProductionNode mn = new JavaCodeProductionNode();
  362. List params = null;
  363. Token start_t = null;
  364. Type resultType = null;
  365. String identifier = "";
  366. BlockNode bn = null;
  367. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("JAVACODE")) {
  368. } else {
  369. jj_consume_token(-1);
  370. throw new ParseException();
  371. }
  372. start_t = jj_consume_token(IDENTIFIER);
  373. resultType = ResultType();
  374. identifier = identifier();
  375. params = FormalParameters();
  376. if (jj_2_6(2)) {
  377. jj_consume_token(THROWS);
  378. Name();
  379. label_3:
  380. while (true) {
  381. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  382. case COMMA:
  383. ;
  384. break;
  385. default:
  386. break label_3;
  387. }
  388. jj_consume_token(COMMA);
  389. Name();
  390. }
  391. } else {
  392. ;
  393. }
  394. if (jj_2_7(2)) {
  395. node_descriptor();
  396. } else {
  397. ;
  398. }
  399. bn = Block();
  400. if (start_t != null){
  401. mn.setStartLocation(getLocation(start_t));
  402. }
  403. if (resultType != null) {
  404. mn.setReturnType(resultType);
  405. }
  406. mn.setName(identifier);
  407. if (params != null) {
  408. mn.setFormalParams(params);
  409. }
  410. if (bn != null) {
  411. mn.setEndLocation(bn.getEndLocation());
  412. mn.addChild(bn);
  413. }
  414. {if (true) return mn;}
  415. throw new Error("Missing return statement in function");
  416. }
  417. final public TigerNode bnf_production() throws ParseException {
  418. BNFProductionNode mn = new BNFProductionNode();
  419. List params = null;
  420. Type resultType = null;
  421. String identifier = "";
  422. Token end_t = null;
  423. BlockNode java_block = null;
  424. resultType = ResultType();
  425. identifier = identifier();
  426. params = FormalParameters();
  427. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  428. case THROWS:
  429. jj_consume_token(THROWS);
  430. Name();
  431. label_4:
  432. while (true) {
  433. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  434. case COMMA:
  435. ;
  436. break;
  437. default:
  438. break label_4;
  439. }
  440. jj_consume_token(COMMA);
  441. Name();
  442. }
  443. break;
  444. default:
  445. ;
  446. }
  447. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  448. case 125:
  449. node_descriptor();
  450. break;
  451. default:
  452. ;
  453. }
  454. jj_consume_token(COLON);
  455. java_block = Block();
  456. jj_consume_token(LBRACE);
  457. expansion_choices();
  458. end_t = jj_consume_token(RBRACE);
  459. if (resultType != null) {
  460. mn.setStartLocation(resultType.getStartLocation());
  461. mn.setReturnType(resultType);
  462. }
  463. mn.setName(identifier);
  464. if (params != null) {
  465. mn.setFormalParams(params);
  466. }
  467. if (end_t != null ) {
  468. mn.setEndLocation(getEndLocation(end_t));
  469. }
  470. if (java_block != null) {
  471. mn.addChild(java_block);
  472. }
  473. {if (true) return mn;}
  474. throw new Error("Missing return statement in function");
  475. }
  476. final public TigerNode regular_expr_production() throws ParseException {
  477. Token start_t = null;
  478. Token end_t = null;
  479. Token t = null;
  480. TigerNode tn = new RegexProductionNode();
  481. Token kind = null;
  482. StringBuffer lexical_state_list = new StringBuffer();
  483. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  484. case LT:
  485. if (jj_2_8(2)) {
  486. start_t = jj_consume_token(LT);
  487. jj_consume_token(STAR);
  488. jj_consume_token(GT);
  489. lexical_state_list.append("<*>");
  490. } else {
  491. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  492. case LT:
  493. start_t = jj_consume_token(LT);
  494. t = jj_consume_token(IDENTIFIER);
  495. lexical_state_list.append("<").append(t.image);
  496. label_5:
  497. while (true) {
  498. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  499. case COMMA:
  500. ;
  501. break;
  502. default:
  503. break label_5;
  504. }
  505. jj_consume_token(COMMA);
  506. t = jj_consume_token(IDENTIFIER);
  507. lexical_state_list.append(",").append(t.image);
  508. }
  509. jj_consume_token(GT);
  510. lexical_state_list.append(">");
  511. break;
  512. default:
  513. jj_consume_token(-1);
  514. throw new ParseException();
  515. }
  516. }
  517. break;
  518. default:
  519. ;
  520. }
  521. kind = regexpr_kind();
  522. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  523. case LBRACKET:
  524. jj_consume_token(LBRACKET);
  525. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("IGNORE_CASE")) {
  526. } else {
  527. jj_consume_token(-1);
  528. throw new ParseException();
  529. }
  530. jj_consume_token(IDENTIFIER);
  531. jj_consume_token(RBRACKET);
  532. break;
  533. default:
  534. ;
  535. }
  536. jj_consume_token(COLON);
  537. jj_consume_token(LBRACE);
  538. regexpr_spec();
  539. label_6:
  540. while (true) {
  541. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  542. case BIT_OR:
  543. ;
  544. break;
  545. default:
  546. break label_6;
  547. }
  548. jj_consume_token(BIT_OR);
  549. regexpr_spec();
  550. }
  551. end_t = jj_consume_token(RBRACE);
  552. if (lexical_state_list.length() > 0) {
  553. tn.setName(lexical_state_list.toString());
  554. }
  555. else if (kind != null) {
  556. tn.setName(kind.image);
  557. }
  558. tn.setStartLocation(getLocation(start_t == null ? kind : start_t));
  559. tn.setEndLocation(getEndLocation(end_t));
  560. {if (true) return tn;}
  561. throw new Error("Missing return statement in function");
  562. }
  563. final public TigerNode token_manager_decls() throws ParseException {
  564. Token start_t = null;
  565. BlockNode bn = null;
  566. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("TOKEN_MGR_DECLS")) {
  567. } else {
  568. jj_consume_token(-1);
  569. throw new ParseException();
  570. }
  571. start_t = jj_consume_token(IDENTIFIER);
  572. jj_consume_token(COLON);
  573. bn = TokenMgrDeclBlock();
  574. TigerNode tn = new TokenMgrDeclProductionNode();
  575. tn.setName(start_t.image);
  576. tn.setStartLocation(getLocation(start_t));
  577. if (bn != null) {
  578. tn.setEndLocation(bn.getEndLocation());
  579. tn.addChildren(bn.getChildren());
  580. }
  581. {if (true) return tn;}
  582. throw new Error("Missing return statement in function");
  583. }
  584. final public Token regexpr_kind() throws ParseException {
  585. Token t = null;
  586. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("TOKEN")) {
  587. t = jj_consume_token(IDENTIFIER);
  588. } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("SPECIAL_TOKEN")) {
  589. t = jj_consume_token(IDENTIFIER);
  590. } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("SKIP")) {
  591. t = jj_consume_token(IDENTIFIER);
  592. } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("MORE")) {
  593. t = jj_consume_token(IDENTIFIER);
  594. } else {
  595. jj_consume_token(-1);
  596. throw new ParseException();
  597. }
  598. {if (true) return t;}
  599. throw new Error("Missing return statement in function");
  600. }
  601. final public void regexpr_spec() throws ParseException {
  602. regular_expression();
  603. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  604. case LBRACE:
  605. Block();
  606. break;
  607. default:
  608. ;
  609. }
  610. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  611. case COLON:
  612. jj_consume_token(COLON);
  613. jj_consume_token(IDENTIFIER);
  614. break;
  615. default:
  616. ;
  617. }
  618. }
  619. final public void expansion_choices() throws ParseException {
  620. expansion();
  621. label_7:
  622. while (true) {
  623. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  624. case BIT_OR:
  625. ;
  626. break;
  627. default:
  628. break label_7;
  629. }
  630. jj_consume_token(BIT_OR);
  631. expansion();
  632. }
  633. }
  634. final public void expansion() throws ParseException {
  635. if (jj_2_9(1)) {
  636. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("LOOKAHEAD")) {
  637. } else {
  638. jj_consume_token(-1);
  639. throw new ParseException();
  640. }
  641. jj_consume_token(IDENTIFIER);
  642. jj_consume_token(LPAREN);
  643. local_lookahead();
  644. jj_consume_token(RPAREN);
  645. } else {
  646. ;
  647. }
  648. label_8:
  649. while (true) {
  650. expansion_unit();
  651. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  652. case 125:
  653. node_descriptor();
  654. break;
  655. default:
  656. ;
  657. }
  658. if (notTailOfExpansionUnit()) {
  659. ;
  660. } else {
  661. break label_8;
  662. }
  663. }
  664. }
  665. final public void local_lookahead() throws ParseException {
  666. boolean commaAtEnd = false, emptyLA = true;
  667. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  668. case INTEGER_LITERAL:
  669. IntegerLiteral();
  670. emptyLA = false;
  671. break;
  672. default:
  673. ;
  674. }
  675. if (!emptyLA && (getToken(1).kind != RPAREN)) {
  676. jj_consume_token(COMMA);
  677. commaAtEnd = true;
  678. } else {
  679. ;
  680. }
  681. if (getToken(1).kind != RPAREN && getToken(1).kind != LBRACE) {
  682. expansion_choices();
  683. emptyLA = false; commaAtEnd = false;
  684. } else {
  685. ;
  686. }
  687. if (!emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN)) {
  688. jj_consume_token(COMMA);
  689. commaAtEnd = true;
  690. } else {
  691. ;
  692. }
  693. if (emptyLA || commaAtEnd) {
  694. jj_consume_token(LBRACE);
  695. Expression();
  696. jj_consume_token(RBRACE);
  697. } else {
  698. ;
  699. }
  700. }
  701. final public void expansion_unit() throws ParseException {
  702. if (jj_2_11(1)) {
  703. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("LOOKAHEAD")) {
  704. } else {
  705. jj_consume_token(-1);
  706. throw new ParseException();
  707. }
  708. jj_consume_token(IDENTIFIER);
  709. jj_consume_token(LPAREN);
  710. local_lookahead();
  711. jj_consume_token(RPAREN);
  712. } else {
  713. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  714. case LBRACE:
  715. Block();
  716. break;
  717. case LBRACKET:
  718. jj_consume_token(LBRACKET);
  719. expansion_choices();
  720. jj_consume_token(RBRACKET);
  721. break;
  722. case TRY:
  723. jj_consume_token(TRY);
  724. jj_consume_token(LBRACE);
  725. expansion_choices();
  726. jj_consume_token(RBRACE);
  727. label_9:
  728. while (true) {
  729. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  730. case CATCH:
  731. ;
  732. break;
  733. default:
  734. break label_9;
  735. }
  736. jj_consume_token(CATCH);
  737. jj_consume_token(LPAREN);
  738. Name();
  739. jj_consume_token(IDENTIFIER);
  740. jj_consume_token(RPAREN);
  741. Block();
  742. }
  743. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  744. case FINALLY:
  745. jj_consume_token(FINALLY);
  746. Block();
  747. break;
  748. default:
  749. ;
  750. }
  751. break;
  752. default:
  753. if (jj_2_12(2147483647)) {
  754. if (jj_2_10(2147483647)) {
  755. PrimaryExpression();
  756. jj_consume_token(ASSIGN);
  757. } else {
  758. ;
  759. }
  760. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  761. case STRING_LITERAL:
  762. case LT:
  763. regular_expression();
  764. break;
  765. case IDENTIFIER:
  766. identifier();
  767. Arguments();
  768. break;
  769. default:
  770. jj_consume_token(-1);
  771. throw new ParseException();
  772. }
  773. } else {
  774. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  775. case LPAREN:
  776. jj_consume_token(LPAREN);
  777. expansion_choices();
  778. jj_consume_token(RPAREN);
  779. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  780. case HOOK:
  781. case PLUS:
  782. case STAR:
  783. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  784. case PLUS:
  785. jj_consume_token(PLUS);
  786. break;
  787. case STAR:
  788. jj_consume_token(STAR);
  789. break;
  790. case HOOK:
  791. jj_consume_token(HOOK);
  792. break;
  793. default:
  794. jj_consume_token(-1);
  795. throw new ParseException();
  796. }
  797. break;
  798. default:
  799. ;
  800. }
  801. break;
  802. default:
  803. jj_consume_token(-1);
  804. throw new ParseException();
  805. }
  806. }
  807. }
  808. }
  809. }
  810. final public void regular_expression() throws ParseException {
  811. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  812. case STRING_LITERAL:
  813. StringLiteral();
  814. break;
  815. default:
  816. if (jj_2_13(3)) {
  817. jj_consume_token(LT);
  818. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  819. case IDENTIFIER:
  820. case 125:
  821. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  822. case 125:
  823. jj_consume_token(125);
  824. break;
  825. default:
  826. ;
  827. }
  828. identifier();
  829. jj_consume_token(COLON);
  830. break;
  831. default:
  832. ;
  833. }
  834. complex_regular_expression_choices();
  835. jj_consume_token(GT);
  836. } else if (jj_2_14(2)) {
  837. jj_consume_token(LT);
  838. identifier();
  839. jj_consume_token(GT);
  840. } else {
  841. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  842. case LT:
  843. jj_consume_token(LT);
  844. if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("EOF")) {
  845. } else {
  846. jj_consume_token(-1);
  847. throw new ParseException();
  848. }
  849. jj_consume_token(IDENTIFIER);
  850. jj_consume_token(GT);
  851. break;
  852. default:
  853. jj_consume_token(-1);
  854. throw new ParseException();
  855. }
  856. }
  857. }
  858. }
  859. final public void complex_regular_expression_choices() throws ParseException {
  860. complex_regular_expression();
  861. label_10:
  862. while (true) {
  863. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  864. case BIT_OR:
  865. ;
  866. break;
  867. default:
  868. break label_10;
  869. }
  870. jj_consume_token(BIT_OR);
  871. complex_regular_expression();
  872. }
  873. }
  874. final public void complex_regular_expression() throws ParseException {
  875. label_11:
  876. while (true) {
  877. complex_regular_expression_unit();
  878. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  879. case STRING_LITERAL:
  880. case LPAREN:
  881. case LBRACKET:
  882. case LT:
  883. case TILDE:
  884. ;
  885. break;
  886. default:
  887. break label_11;
  888. }
  889. }
  890. }
  891. final public void complex_regular_expression_unit() throws ParseException {
  892. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  893. case STRING_LITERAL:
  894. StringLiteral();
  895. break;
  896. case LT:
  897. jj_consume_token(LT);
  898. identifier();
  899. jj_consume_token(GT);
  900. break;
  901. case LBRACKET:
  902. case TILDE:
  903. character_list();
  904. break;
  905. case LPAREN:
  906. jj_consume_token(LPAREN);
  907. complex_regular_expression_choices();
  908. jj_consume_token(RPAREN);
  909. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  910. case HOOK:
  911. case PLUS:
  912. case STAR:
  913. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  914. case PLUS:
  915. jj_consume_token(PLUS);
  916. break;
  917. case STAR:
  918. jj_consume_token(STAR);
  919. break;
  920. case HOOK:
  921. jj_consume_token(HOOK);
  922. break;
  923. default:
  924. jj_consume_token(-1);
  925. throw new ParseException();
  926. }
  927. break;
  928. default:
  929. ;
  930. }
  931. break;
  932. default:
  933. jj_consume_token(-1);
  934. throw new ParseException();
  935. }
  936. }
  937. final public void character_list() throws ParseException {
  938. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  939. case TILDE:
  940. jj_consume_token(TILDE);
  941. break;
  942. default:
  943. ;
  944. }
  945. jj_consume_token(LBRACKET);
  946. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  947. case STRING_LITERAL:
  948. character_descriptor();
  949. label_12:
  950. while (true) {
  951. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  952. case COMMA:
  953. ;
  954. break;
  955. default:
  956. break label_12;
  957. }
  958. jj_consume_token(COMMA);
  959. character_descriptor();
  960. }
  961. break;
  962. default:
  963. ;
  964. }
  965. jj_consume_token(RBRACKET);
  966. }
  967. final public void character_descriptor() throws ParseException {
  968. StringLiteral();
  969. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  970. case MINUS:
  971. jj_consume_token(MINUS);
  972. StringLiteral();
  973. break;
  974. default:
  975. ;
  976. }
  977. }
  978. final public String identifier() throws ParseException {
  979. Token t = null;
  980. t = jj_consume_token(IDENTIFIER);
  981. {if (true) return t.image;}
  982. throw new Error("Missing return statement in function");
  983. }
  984. /**********************************************
  985. * THE JJTREE PRODUCTIONS START HERE *
  986. **********************************************/
  987. final public void node_descriptor() throws ParseException {
  988. jj_consume_token(125);
  989. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  990. case IDENTIFIER:
  991. jj_consume_token(IDENTIFIER);
  992. break;
  993. case VOID:
  994. jj_consume_token(VOID);
  995. break;
  996. default:
  997. jj_consume_token(-1);
  998. throw new ParseException();
  999. }
  1000. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1001. case LPAREN:
  1002. jj_consume_token(LPAREN);
  1003. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1004. case GT:
  1005. jj_consume_token(GT);
  1006. break;
  1007. default:
  1008. ;
  1009. }
  1010. node_descriptor_expression();
  1011. jj_consume_token(RPAREN);
  1012. break;
  1013. default:
  1014. ;
  1015. }
  1016. }
  1017. void node_descriptor_expression() throws ParseException {
  1018. Token tok;
  1019. int nesting = 1;
  1020. while (true) {
  1021. tok = getToken(1);
  1022. if (tok.kind == 0) {
  1023. throw new ParseException();
  1024. }
  1025. if (tok.kind == LPAREN) nesting++;
  1026. if (tok.kind == RPAREN) {
  1027. nesting--;
  1028. if (nesting == 0) break;
  1029. }
  1030. tok = getNextToken();
  1031. }
  1032. }
  1033. /* javacc productions */
  1034. final public void IntegerLiteral() throws ParseException {
  1035. jj_consume_token(INTEGER_LITERAL);
  1036. }
  1037. final public void StringLiteral() throws ParseException {
  1038. jj_consume_token(STRING_LITERAL);
  1039. }
  1040. /*****************************************
  1041. * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
  1042. *****************************************/
  1043. /*
  1044. * Program structuring syntax follows.
  1045. */
  1046. final public CUNode getJavaRootNode(int tab_size) throws ParseException {
  1047. CUNode n = null;
  1048. n = JavaCompilationUnit(tab_size);
  1049. {if (true) return n;}
  1050. throw new Error("Missing return statement in function");
  1051. }
  1052. /**
  1053. * Main entry point for parsing the PARSER section in javacc files. Use
  1054. * JavaCompilationUnit as main entry point for parsing java files.
  1055. * @return a CUNode, which is parent or root node of all other nodes.
  1056. */
  1057. final public CUNode CompilationUnit(int tab_size) throws ParseException {
  1058. setTabSize(tab_size);
  1059. CUNode n = new CUNode();
  1060. TigerNode a;
  1061. String packageName = "";
  1062. ImportNode in = null;
  1063. try {
  1064. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1065. case PACKAGE:
  1066. packageName = PackageDeclaration();
  1067. break;
  1068. default:
  1069. ;
  1070. }
  1071. label_13:
  1072. while (true) {
  1073. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1074. case IMPORT:
  1075. ;
  1076. break;
  1077. default:
  1078. break label_13;
  1079. }
  1080. in = ImportDeclaration();
  1081. n.addImport(in);
  1082. }
  1083. label_14:
  1084. while (true) {
  1085. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1086. case ABSTRACT:
  1087. case CLASS:
  1088. case ENUM:
  1089. case FINAL:
  1090. case INTERFACE:
  1091. case NATIVE:
  1092. case PRIVATE:
  1093. case PROTECTED:
  1094. case PUBLIC:
  1095. case STATIC:
  1096. case STRICTFP:
  1097. case SYNCHRONIZED:
  1098. case TRANSIENT:
  1099. case VOLATILE:
  1100. case SEMICOLON:
  1101. case AT:
  1102. ;
  1103. break;
  1104. default:
  1105. break label_14;
  1106. }
  1107. a = TypeDeclaration();
  1108. n.addChild(a);
  1109. }
  1110. } catch (ParseException pe) {
  1111. error_skipto(SEMICOLON);
  1112. }
  1113. n.setPackageName(packageName);
  1114. {if (true) return n;}
  1115. throw new Error("Missing return statement in function");
  1116. }
  1117. /**
  1118. * Main entry point for parsing java files.
  1119. * @return a CUNode, which is parent or root node of all other nodes.
  1120. */
  1121. final public CUNode JavaCompilationUnit(int tab_size) throws ParseException {
  1122. CUNode n = null;
  1123. Token end_t = null;
  1124. try {
  1125. n = CompilationUnit(tab_size);
  1126. // read the whole file
  1127. end_t = jj_consume_token(0);
  1128. } catch (ParseException pe) {
  1129. error_skipto(SEMICOLON);
  1130. }
  1131. if (end_t != null) {
  1132. n.setEndLocation(getLocation(end_t));
  1133. }
  1134. {if (true) return n;}
  1135. throw new Error("Missing return statement in function");
  1136. }
  1137. final public String PackageDeclaration() throws ParseException {
  1138. TigerNode name = null;
  1139. try {
  1140. jj_consume_token(PACKAGE);
  1141. name = Name();
  1142. jj_consume_token(SEMICOLON);
  1143. } catch (ParseException pe) {
  1144. error_skipto(SEMICOLON);
  1145. }
  1146. {if (true) return name == null ? "" : name.getName();}
  1147. throw new Error("Missing return statement in function");
  1148. }
  1149. /**
  1150. * @return just the package name, without the 'import' or 'static' or '.*', e.g.
  1151. * "import java.util.*;" will return "java.util". A fully qualified import will
  1152. * return the full classname, e.g. "import java.util.List;" will return
  1153. * "java.util.List", this is also the case with static imports, e.g.
  1154. * "import static java.lang.Math.PI;" will return "java.lang.Math.PI".
  1155. */
  1156. final public ImportNode ImportDeclaration() throws ParseException {
  1157. TigerNode name = null;
  1158. Token st = null;
  1159. Token et = null;
  1160. try {
  1161. st = jj_consume_token(IMPORT);
  1162. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1163. case STATIC:
  1164. jj_consume_token(STATIC);
  1165. break;
  1166. default:
  1167. ;
  1168. }
  1169. name = Name();
  1170. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1171. case DOT:
  1172. jj_consume_token(DOT);
  1173. jj_consume_token(STAR);
  1174. break;
  1175. default:
  1176. ;
  1177. }
  1178. et = jj_consume_token(SEMICOLON);
  1179. } catch (ParseException pe) {
  1180. error_skipto(SEMICOLON);
  1181. }
  1182. if (name != null) {
  1183. ImportNode in = new ImportNode(name.getName());
  1184. //in.setStartLocation(name.getStartLocation());
  1185. //in.setEndLocation(name.getEndLocation());
  1186. in.setStartLocation(getLocation(st));
  1187. in.setEndLocation(getEndLocation(et));
  1188. {if (true) return in;}
  1189. }
  1190. {if (true) return null;}
  1191. throw new Error("Missing return statement in function");
  1192. }
  1193. /*
  1194. * Modifiers. We match all modifiers in a single rule to reduce the chances of
  1195. * syntax errors for simple modifier mistakes. It will also enable us to give
  1196. * better error messages.
  1197. */
  1198. final public Modifier Modifiers() throws ParseException {
  1199. int modifiers = 0;
  1200. Token t = null;
  1201. Modifier m = new Modifier();
  1202. label_15:
  1203. while (true) {
  1204. if (jj_2_15(2)) {
  1205. ;
  1206. } else {
  1207. break label_15;
  1208. }
  1209. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1210. case PUBLIC:
  1211. t = jj_consume_token(PUBLIC);
  1212. modifiers |= ModifierSet.PUBLIC; adjustModifier(m, t);
  1213. break;
  1214. case STATIC:
  1215. t = jj_consume_token(STATIC);
  1216. modifiers |= ModifierSet.STATIC; adjustModifier(m, t);
  1217. break;
  1218. case PROTECTED:
  1219. t = jj_consume_token(PROTECTED);
  1220. modifiers |= ModifierSet.PROTECTED; adjustModifier(m, t);
  1221. break;
  1222. case PRIVATE:
  1223. t = jj_consume_token(PRIVATE);
  1224. modifiers |= ModifierSet.PRIVATE; adjustModifier(m, t);
  1225. break;
  1226. case FINAL:
  1227. t = jj_consume_token(FINAL);
  1228. modifiers |= ModifierSet.FINAL; adjustModifier(m, t);
  1229. break;
  1230. case ABSTRACT:
  1231. t = jj_consume_token(ABSTRACT);
  1232. modifiers |= ModifierSet.ABSTRACT; adjustModifier(m, t);
  1233. break;
  1234. case SYNCHRONIZED:
  1235. t = jj_consume_token(SYNCHRONIZED);
  1236. modifiers |= ModifierSet.SYNCHRONIZED; adjustModifier(m, t);
  1237. break;
  1238. case NATIVE:
  1239. t = jj_consume_token(NATIVE);
  1240. modifiers |= ModifierSet.NATIVE; adjustModifier(m, t);
  1241. break;
  1242. case TRANSIENT:
  1243. t = jj_consume_token(TRANSIENT);
  1244. modifiers |= ModifierSet.TRANSIENT; adjustModifier(m, t);
  1245. break;
  1246. case VOLATILE:
  1247. t = jj_consume_token(VOLATILE);
  1248. modifiers |= ModifierSet.VOLATILE; adjustModifier(m, t);
  1249. break;
  1250. case STRICTFP:
  1251. t = jj_consume_token(STRICTFP);
  1252. modifiers |= ModifierSet.STRICTFP; adjustModifier(m, t);
  1253. break;
  1254. case AT:
  1255. Annotation();
  1256. break;
  1257. default:
  1258. jj_consume_token(-1);
  1259. throw new ParseException();
  1260. }
  1261. }
  1262. m.modifiers = modifiers;
  1263. {if (true) return m;}
  1264. throw new Error("Missing return statement in function");
  1265. }
  1266. /*
  1267. * Declaration syntax follows.
  1268. */
  1269. // Handle classes, interfaces, enums, and annotations.
  1270. final public TigerNode TypeDeclaration() throws ParseException {
  1271. Modifier modifier;
  1272. TigerNode tn = null;
  1273. try {
  1274. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1275. case SEMICOLON:
  1276. jj_consume_token(SEMICOLON);
  1277. break;
  1278. case ABSTRACT:
  1279. case CLASS:
  1280. case ENUM:
  1281. case FINAL:
  1282. case INTERFACE:
  1283. case NATIVE:
  1284. case PRIVATE:
  1285. case PROTECTED:
  1286. case PUBLIC:
  1287. case STATIC:
  1288. case STRICTFP:
  1289. case SYNCHRONIZED:
  1290. case TRANSIENT:
  1291. case VOLATILE:
  1292. case AT:
  1293. modifier = Modifiers();
  1294. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1295. case CLASS:
  1296. case INTERFACE:
  1297. tn = ClassOrInterfaceDeclaration(modifier);
  1298. break;
  1299. case ENUM:
  1300. tn = EnumDeclaration(modifier);
  1301. break;
  1302. case AT:
  1303. AnnotationTypeDeclaration(modifier);
  1304. tn = null;
  1305. break;
  1306. default:
  1307. jj_consume_token(-1);
  1308. throw new ParseException();
  1309. }
  1310. break;
  1311. default:
  1312. jj_consume_token(-1);
  1313. throw new ParseException();
  1314. }
  1315. } catch (ParseException pe) {
  1316. error_skipto(SEMICOLON);
  1317. }
  1318. {if (true) return tn;}
  1319. throw new Error("Missing return statement in function");
  1320. }
  1321. /**
  1322. * @return a ClassNode or an InterfaceNode
  1323. */
  1324. final public TigerNode ClassOrInterfaceDeclaration(Modifier m) throws ParseException {
  1325. boolean isInterface = false;
  1326. Token t = null;
  1327. TigerNode kids = null; // only need the children of this node
  1328. String type_params = "";
  1329. List extends_list = null;
  1330. List implements_list = null;
  1331. Token type = null;
  1332. try {
  1333. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1334. case CLASS:
  1335. type = jj_consume_token(CLASS);
  1336. break;
  1337. case INTERFACE:
  1338. type = jj_consume_token(INTERFACE);
  1339. isInterface = true;
  1340. break;
  1341. default:
  1342. jj_consume_token(-1);
  1343. throw new ParseException();
  1344. }
  1345. t = jj_consume_token(IDENTIFIER);
  1346. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1347. case LT:
  1348. type_params = TypeParameters();
  1349. break;
  1350. default:
  1351. ;
  1352. }
  1353. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1354. case EXTENDS:
  1355. extends_list = ExtendsList(isInterface);
  1356. break;
  1357. default:
  1358. ;
  1359. }
  1360. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1361. case IMPLEMENTS:
  1362. implements_list = ImplementsList(isInterface);
  1363. break;
  1364. default:
  1365. ;
  1366. }
  1367. kids = ClassOrInterfaceBody(isInterface);
  1368. if (jj_2_16(2)) {
  1369. jj_consume_token(SEMICOLON);
  1370. } else {
  1371. ;
  1372. }
  1373. } catch (ParseException pe) {
  1374. error_skipto(SEMICOLON);
  1375. }
  1376. ClassNode node = isInterface ? new InterfaceNode(t.image, m.modifiers) : new ClassNode(t.image, m.modifiers);
  1377. if (isInterface)
  1378. results.incInterfaceCount();
  1379. else
  1380. results.incClassCount();
  1381. if (m.beginColumn > -1) {
  1382. node.setStartLocation(getLocation(m) );
  1383. }
  1384. else {
  1385. node.setStartLocation(getLocation(type));
  1386. }
  1387. if (kids != null)
  1388. node.setEndLocation(kids.getEndLocation());
  1389. // add the child nodes, don't need the 'kids' node itself, it's just a holder
  1390. // for the nodes I want (although I do want the end location).
  1391. if (kids != null && kids.getChildren() != null)
  1392. node.addChildren(kids.getChildren());
  1393. node.setTypeParams(type_params);
  1394. node.setExtendsList(extends_list);
  1395. node.setImplementsList(implements_list);
  1396. {if (true) return node;}
  1397. throw new Error("Missing return statement in function");
  1398. }
  1399. /**
  1400. * @return a list of sidekick.java.node.Types representing items in an 'extends'
  1401. * list, e.g. the "Bar" in "public class Foo extends Bar"
  1402. */
  1403. final public List ExtendsList(boolean isInterface) throws ParseException {
  1404. boolean extendsMoreThanOne = false;
  1405. List list = new ArrayList(); // a list of Types
  1406. Type type_s = null;
  1407. Type type_a = null;
  1408. try {
  1409. jj_consume_token(EXTENDS);
  1410. type_s = ClassOrInterfaceType();
  1411. list.add(type_s);
  1412. label_16:
  1413. while (true) {
  1414. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1415. case COMMA:
  1416. ;
  1417. break;
  1418. default:
  1419. break label_16;
  1420. }
  1421. jj_consume_token(COMMA);
  1422. type_a = ClassOrInterfaceType();
  1423. extendsMoreThanOne = true; list.add(type_a);
  1424. }
  1425. } catch (ParseException pe) {
  1426. error_skipto(SEMICOLON);
  1427. }
  1428. if (extendsMoreThanOne && !isInterface)
  1429. {if (true) throw new ParseException("A class cannot extend more than one other class");}
  1430. {if (true) return list;}
  1431. throw new Error("Missing return statement in function");
  1432. }
  1433. /**
  1434. * @return a list of sidekick.java.node.Types representing items in an 'implements'
  1435. * list, e.g. the "Bar" and "Serializable" in "public class Foo implements Bar, Serializable"
  1436. */
  1437. final public List ImplementsList(boolean isInterface) throws ParseException {
  1438. List list = new ArrayList();
  1439. Type type_s = null;
  1440. Type type_a = null;
  1441. try {
  1442. jj_consume_token(IMPLEMENTS);
  1443. type_s = ClassOrInterfaceType();
  1444. list.add(type_s);
  1445. label_17:
  1446. while (true) {
  1447. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1448. case COMMA:
  1449. ;
  1450. break;
  1451. default:
  1452. break label_17;
  1453. }
  1454. jj_consume_token(COMMA);
  1455. type_a = ClassOrInterfaceType();
  1456. list.add(type_a);
  1457. }
  1458. } catch (ParseException pe) {
  1459. error_skipto(SEMICOLON);
  1460. }
  1461. if (isInterface)
  1462. {if (true) throw new ParseException("An interface cannot implement other interfaces");}
  1463. {if (true) return list;}
  1464. throw new Error("Missing return statement in function");
  1465. }
  1466. /**
  1467. * @return an EnumNode
  1468. */
  1469. final public TigerNode EnumDeclaration(Modifier m) throws ParseException {
  1470. Token t = null;
  1471. Token start_t = null;
  1472. Location end_loc = null;
  1473. try {
  1474. start_t = jj_consume_token(ENUM);
  1475. t = jj_consume_token(IDENTIFIER);
  1476. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1477. case IMPLEMENTS:
  1478. ImplementsList(false);
  1479. break;
  1480. default:
  1481. ;
  1482. }
  1483. end_loc = EnumBody();
  1484. } catch (ParseException pe) {
  1485. if (t == null) {
  1486. // handle the case where old code used 'enum' as a variable name
  1487. ParseException e = new ParseException("Parse error at line " + start_t.beginLine + ", column " + start_t.beginColumn + ". Encountered: 'enum' as an identifier, 'enum' is a keyword.");
  1488. addException(e);
  1489. {if (true) return null;}
  1490. }
  1491. else
  1492. error_skipto(SEMICOLON);
  1493. }
  1494. if (t == null) {
  1495. // handle the case where old code used 'enum' as a variable name
  1496. ParseException e = new ParseException("Parse error at line " + start_t.beginLine + ", column " + start_t.beginColumn + ". Encountered: 'enum' as an identifier, 'enum' is a keyword.");
  1497. addException(e);
  1498. {if (true) return null;}
  1499. }
  1500. EnumNode node = new EnumNode(t.image, m.modifiers);
  1501. if (start_t != null) {
  1502. if (m.beginColumn == -1)
  1503. node.setStartLocation(getLocation(start_t));
  1504. else
  1505. node.setStartLocation(getLocation(m));
  1506. }
  1507. if (end_loc != null)
  1508. node.setEndLocation(end_loc);
  1509. {if (true) return node;}
  1510. throw new Error("Missing return statement in function");
  1511. }
  1512. // returns the end location of the enum body
  1513. final public Location EnumBody() throws ParseException {
  1514. Token t = null;
  1515. try {
  1516. jj_consume_token(LBRACE);
  1517. EnumConstant();
  1518. label_18:
  1519. while (true) {
  1520. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1521. case COMMA:
  1522. ;
  1523. break;
  1524. default:
  1525. break label_18;
  1526. }
  1527. jj_consume_token(COMMA);
  1528. EnumConstant();
  1529. }
  1530. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1531. case SEMICOLON:
  1532. jj_consume_token(SEMICOLON);
  1533. label_19:
  1534. while (true) {
  1535. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1536. case ABSTRACT:
  1537. case BOOLEAN:
  1538. case BYTE:
  1539. case CHAR:
  1540. case CLASS:
  1541. case DOUBLE:
  1542. case ENUM:
  1543. case FINAL:
  1544. case FLOAT:
  1545. case INT:
  1546. case INTERFACE:
  1547. case LONG:
  1548. case NATIVE:
  1549. case PRIVATE:
  1550. case PROTECTED:
  1551. case PUBLIC:
  1552. case SHORT:
  1553. case STATIC:
  1554. case STRICTFP:
  1555. case SYNCHRONIZED:
  1556. case TRANSIENT:
  1557. case VOID:
  1558. case VOLATILE:
  1559. case IDENTIFIER:
  1560. case LBRACE:
  1561. case SEMICOLON:
  1562. case AT:
  1563. case LT:
  1564. ;
  1565. break;
  1566. default:
  1567. break label_19;
  1568. }
  1569. ClassOrInterfaceBodyDeclaration(false);
  1570. }
  1571. break;
  1572. default:
  1573. ;
  1574. }
  1575. t = jj_consume_token(RBRACE);
  1576. } catch (ParseException pe) {
  1577. error_skipto(SEMICOLON);
  1578. }
  1579. {if (true) return t == null ? null : getLocation(t);}
  1580. throw new Error("Missing return statement in function");
  1581. }
  1582. /// what is this? Should I be handling it?
  1583. final public void EnumConstant() throws ParseException {
  1584. try {
  1585. jj_consume_token(IDENTIFIER);
  1586. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1587. case LPAREN:
  1588. Arguments();
  1589. break;
  1590. default:
  1591. ;
  1592. }
  1593. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1594. case LBRACE:
  1595. ClassOrInterfaceBody(false);
  1596. break;
  1597. default:
  1598. ;
  1599. }
  1600. } catch (ParseException pe) {
  1601. error_skipto(SEMICOLON);
  1602. }
  1603. }
  1604. /**
  1605. * @return a string representing a generics type, e.g. the "<String>" in
  1606. * "List<String> list = new List();", the string will contain the angle brackets.
  1607. */
  1608. final public String TypeParameters() throws ParseException {
  1609. String s = "<";
  1610. String a = "";
  1611. try {
  1612. jj_consume_token(LT);
  1613. a = TypeParameter();
  1614. s += a;
  1615. label_20:
  1616. while (true) {
  1617. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1618. case COMMA:
  1619. ;
  1620. break;
  1621. default:
  1622. break label_20;
  1623. }
  1624. jj_consume_token(COMMA);
  1625. s += ",";
  1626. a = TypeParameter();
  1627. s += a;
  1628. }
  1629. jj_consume_token(GT);
  1630. } catch (ParseException pe) {
  1631. error_skipto(SEMICOLON);
  1632. }
  1633. {if (true) return s + ">";}
  1634. throw new Error("Missing return statement in function");
  1635. }
  1636. final public String TypeParameter() throws ParseException {
  1637. String s = "";
  1638. Token t = null;
  1639. try {
  1640. t = jj_consume_token(IDENTIFIER);
  1641. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1642. case EXTENDS:
  1643. s = TypeBound();
  1644. break;
  1645. default:
  1646. ;
  1647. }
  1648. } catch (ParseException pe) {
  1649. error_skipto(SEMICOLON);
  1650. }
  1651. StringBuffer sb = new StringBuffer();
  1652. if (t.image != null)
  1653. sb.append(t.image);
  1654. if (s.length() > 0)
  1655. sb.append(" ").append(s);
  1656. {if (true) return sb.toString();}
  1657. throw new Error("Missing return statement in function");
  1658. }
  1659. final public String TypeBound() throws ParseException {
  1660. String s = "extends";
  1661. Type type_s = null;
  1662. Type type_a = null;
  1663. try {
  1664. jj_consume_token(EXTENDS);
  1665. type_a = ClassOrInterfaceType();
  1666. s += " " + type_a.toString();
  1667. label_21:
  1668. while (true) {
  1669. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  1670. case BIT_AND:
  1671. ;
  1672. break;
  1673. default:
  1674. break label_21;
  1675. }
  1676. jj_consume_token(BIT_AND);
  1677. s += " & ";
  1678. type_a = ClassOrInterfaceType();
  1679. s += type_a.toString();
  1680. }
  1681. } catch (ParseException pe) {
  1682. error_skipto(SEMICOLON);
  1683. }
  1684. {if (true) return s;}
  1685. throw new Error("Missing return statement in function");
  1686. }
  1687. /**
  1688. * @return a node representing the contents of a Class or Interface body. The
  1689. * returned node is simply a holder for the contents, it is the children of this
  1690. * node that is useful as they are the methods and fields of the class or
  1691. * interface.
  1692. */
  1693. final public TigerNode ClassOrInterfaceBody(boolean isInterface) throws ParseException {
  1694. TigerNode parent = new TigerNode("", -1);
  1695. TigerNode child;
  1696. Token start_t = null;
  1697. Token end_t = null;
  1698. try {
  1699. start_t = jj_consume_token(LBRACE);