├── .clang-format ├── .github └── workflows │ └── check.yml ├── .gitignore ├── CMakeLists.txt ├── README.md ├── doc ├── arch.md ├── arch.png ├── report.pdf └── report.tex ├── formatting.cmake ├── scripts ├── clear_testcase_exes.py ├── flat_includes.py ├── run_all.py └── test_all.py ├── src ├── arm │ ├── archinfo.hpp │ ├── block.cpp │ ├── block.hpp │ ├── func.cpp │ ├── func.hpp │ ├── inst.cpp │ ├── inst.hpp │ ├── irc_coloring_alloc.hpp │ ├── opt │ │ ├── afterplay.hpp │ │ ├── dce.cpp │ │ ├── eliminate_branch.cpp │ │ ├── foreplay.hpp │ │ ├── merge_instr.cpp │ │ ├── remove_empty_blocks.cpp │ │ ├── remove_trivial_inst.cpp │ │ ├── replace_complex_instr.cpp │ │ └── replace_pseduo_inst.cpp │ ├── program.cpp │ ├── program.hpp │ ├── regalloc.hpp │ └── simple_coloring_alloc.hpp ├── ast │ ├── ast_visitor.cpp │ ├── ast_visitor.hpp │ ├── exp_value.cpp │ ├── exp_value.hpp │ ├── init_value.cpp │ ├── init_value.hpp │ ├── symbol_table.cpp │ └── symbol_table.hpp ├── common │ ├── common.cpp │ ├── common.hpp │ └── errors.hpp ├── ir │ ├── ir.cpp │ ├── ir.hpp │ ├── opt │ │ ├── add_expr.hpp │ │ ├── arith.cpp │ │ ├── bb_ops.cpp │ │ ├── call_graph.cpp │ │ ├── dag_ir.cpp │ │ ├── dag_ir.hpp │ │ ├── dom.cpp │ │ ├── dom.hpp │ │ ├── func_inline.cpp │ │ ├── gcm.cpp │ │ ├── global_to_local.cpp │ │ ├── gvn.cpp │ │ ├── loop.cpp │ │ ├── loop.hpp │ │ ├── loop_ops.cpp │ │ ├── mem2reg.cpp │ │ ├── opt.hpp │ │ ├── pretty_print.cpp │ │ ├── remove_unused_def.cpp │ │ ├── side_effect.cpp │ │ ├── simplify_expr.cpp │ │ ├── special.cpp │ │ ├── ssa_constrcution.cpp │ │ └── typecheck.cpp │ └── scalar.hpp ├── main.cpp └── parser │ ├── .clang-format │ ├── CommonLex.g4 │ ├── SysY.g4 │ ├── SysY.interp │ ├── SysY.tokens │ ├── SysYBaseListener.cpp │ ├── SysYBaseListener.h │ ├── SysYBaseVisitor.cpp │ ├── SysYBaseVisitor.h │ ├── SysYLexer.cpp │ ├── SysYLexer.h │ ├── SysYLexer.interp │ ├── SysYLexer.tokens │ ├── SysYListener.cpp │ ├── SysYListener.h │ ├── SysYParser.cpp │ ├── SysYParser.h │ ├── SysYVisitor.cpp │ └── SysYVisitor.h ├── testcases ├── custom │ ├── issue-115.in │ ├── issue-115.out │ ├── issue-115.sy │ ├── issue-118.in │ ├── issue-118.out │ ├── issue-118.sy │ ├── issue-121.in │ ├── issue-121.out │ ├── issue-121.sy │ ├── issue-125.in │ ├── issue-125.out │ ├── issue-125.sy │ ├── issue-131.in │ ├── issue-131.out │ ├── issue-131.sy │ ├── issue-154.in │ ├── issue-154.out │ ├── issue-154.sy │ ├── putfloat.out │ ├── putfloat.sy │ ├── test_simd_1.in │ ├── test_simd_1.out │ └── test_simd_1.sy ├── final_performance │ ├── 00_bitset1.sy │ ├── 00_bitset2.sy │ ├── 00_bitset3.sy │ ├── 01_mm1.sy │ ├── 01_mm2.sy │ ├── 01_mm3.sy │ ├── 02_mv1.sy │ ├── 02_mv2.sy │ ├── 02_mv3.sy │ ├── 03_sort1.sy │ ├── 03_sort2.sy │ ├── 03_sort3.sy │ ├── 04_spmv1.sy │ ├── 04_spmv2.sy │ ├── 04_spmv3.sy │ ├── brainfuck-bootstrap.sy │ ├── brainfuck-mandelbrot-nerf.sy │ ├── brainfuck-pi-nerf.sy │ ├── crypto1.sy │ ├── crypto2.sy │ ├── crypto3.sy │ ├── derich1.sy │ ├── derich2.sy │ ├── derich3.sy │ ├── fft0.sy │ ├── fft1.sy │ ├── fft2.sy │ ├── gameoflife-oscillator.sy │ ├── gameoflife-p61glidergun.sy │ ├── if-combine1.sy │ ├── if-combine2.sy │ ├── if-combine3.sy │ ├── large_loop_array_1.sy │ ├── large_loop_array_2.sy │ ├── large_loop_array_3.sy │ ├── layernorm1.sy │ ├── layernorm2.sy │ ├── layernorm3.sy │ ├── matmul1.sy │ ├── matmul2.sy │ ├── matmul3.sy │ ├── median0.sy │ ├── median1.sy │ ├── median2.sy │ ├── recursion_fabonacci-1.sy │ ├── recursion_fabonacci-2.sy │ ├── recursion_fabonacci-3.sy │ ├── recursive_call_1.sy │ ├── recursive_call_2.sy │ ├── recursive_call_3.sy │ ├── shuffle0.sy │ ├── shuffle1.sy │ ├── shuffle2.sy │ ├── transpose0.sy │ ├── transpose1.sy │ ├── transpose2.sy │ ├── vector_mul1.sy │ ├── vector_mul2.sy │ └── vector_mul3.sy ├── functional │ ├── .gitkeep │ ├── 00_main.out │ ├── 00_main.sy │ ├── 01_var_defn2.out │ ├── 01_var_defn2.sy │ ├── 02_var_defn3.out │ ├── 02_var_defn3.sy │ ├── 03_arr_defn2.out │ ├── 03_arr_defn2.sy │ ├── 04_arr_defn3.out │ ├── 04_arr_defn3.sy │ ├── 05_arr_defn4.out │ ├── 05_arr_defn4.sy │ ├── 06_const_var_defn2.out │ ├── 06_const_var_defn2.sy │ ├── 07_const_var_defn3.out │ ├── 07_const_var_defn3.sy │ ├── 08_const_array_defn.out │ ├── 08_const_array_defn.sy │ ├── 09_func_defn.out │ ├── 09_func_defn.sy │ ├── 10_var_defn_func.out │ ├── 10_var_defn_func.sy │ ├── 11_add2.out │ ├── 11_add2.sy │ ├── 12_addc.out │ ├── 12_addc.sy │ ├── 13_sub2.out │ ├── 13_sub2.sy │ ├── 14_subc.out │ ├── 14_subc.sy │ ├── 15_mul.out │ ├── 15_mul.sy │ ├── 16_mulc.out │ ├── 16_mulc.sy │ ├── 17_div.out │ ├── 17_div.sy │ ├── 18_divc.out │ ├── 18_divc.sy │ ├── 19_mod.out │ ├── 19_mod.sy │ ├── 20_rem.out │ ├── 20_rem.sy │ ├── 21_if_test2.out │ ├── 21_if_test2.sy │ ├── 22_if_test3.out │ ├── 22_if_test3.sy │ ├── 23_if_test4.out │ ├── 23_if_test4.sy │ ├── 24_if_test5.out │ ├── 24_if_test5.sy │ ├── 25_while_if.out │ ├── 25_while_if.sy │ ├── 26_while_test1.out │ ├── 26_while_test1.sy │ ├── 27_while_test2.out │ ├── 27_while_test2.sy │ ├── 28_while_test3.out │ ├── 28_while_test3.sy │ ├── 29_break.out │ ├── 29_break.sy │ ├── 30_continue.out │ ├── 30_continue.sy │ ├── 31_while_if_test1.out │ ├── 31_while_if_test1.sy │ ├── 32_while_if_test2.out │ ├── 32_while_if_test2.sy │ ├── 33_while_if_test3.out │ ├── 33_while_if_test3.sy │ ├── 34_arr_expr_len.out │ ├── 34_arr_expr_len.sy │ ├── 35_op_priority1.out │ ├── 35_op_priority1.sy │ ├── 36_op_priority2.out │ ├── 36_op_priority2.sy │ ├── 37_op_priority3.out │ ├── 37_op_priority3.sy │ ├── 38_op_priority4.in │ ├── 38_op_priority4.out │ ├── 38_op_priority4.sy │ ├── 39_op_priority5.out │ ├── 39_op_priority5.sy │ ├── 40_unary_op.out │ ├── 40_unary_op.sy │ ├── 41_unary_op2.out │ ├── 41_unary_op2.sy │ ├── 42_empty_stmt.out │ ├── 42_empty_stmt.sy │ ├── 43_logi_assign.in │ ├── 43_logi_assign.out │ ├── 43_logi_assign.sy │ ├── 44_stmt_expr.out │ ├── 44_stmt_expr.sy │ ├── 45_comment1.out │ ├── 45_comment1.sy │ ├── 46_hex_defn.out │ ├── 46_hex_defn.sy │ ├── 47_hex_oct_add.out │ ├── 47_hex_oct_add.sy │ ├── 48_assign_complex_expr.out │ ├── 48_assign_complex_expr.sy │ ├── 49_if_complex_expr.out │ ├── 49_if_complex_expr.sy │ ├── 50_short_circuit.in │ ├── 50_short_circuit.out │ ├── 50_short_circuit.sy │ ├── 51_short_circuit3.out │ ├── 51_short_circuit3.sy │ ├── 52_scope.out │ ├── 52_scope.sy │ ├── 53_scope2.out │ ├── 53_scope2.sy │ ├── 54_hidden_var.out │ ├── 54_hidden_var.sy │ ├── 55_sort_test1.out │ ├── 55_sort_test1.sy │ ├── 56_sort_test2.out │ ├── 56_sort_test2.sy │ ├── 57_sort_test3.out │ ├── 57_sort_test3.sy │ ├── 58_sort_test4.out │ ├── 58_sort_test4.sy │ ├── 59_sort_test5.out │ ├── 59_sort_test5.sy │ ├── 60_sort_test6.out │ ├── 60_sort_test6.sy │ ├── 61_sort_test7.in │ ├── 61_sort_test7.out │ ├── 61_sort_test7.sy │ ├── 62_percolation.in │ ├── 62_percolation.out │ ├── 62_percolation.sy │ ├── 63_big_int_mul.out │ ├── 63_big_int_mul.sy │ ├── 64_calculator.in │ ├── 64_calculator.out │ ├── 64_calculator.sy │ ├── 65_color.in │ ├── 65_color.out │ ├── 65_color.sy │ ├── 66_exgcd.out │ ├── 66_exgcd.sy │ ├── 67_reverse_output.in │ ├── 67_reverse_output.out │ ├── 67_reverse_output.sy │ ├── 68_brainfk.in │ ├── 68_brainfk.out │ ├── 68_brainfk.sy │ ├── 69_expr_eval.in │ ├── 69_expr_eval.out │ ├── 69_expr_eval.sy │ ├── 70_dijkstra.in │ ├── 70_dijkstra.out │ ├── 70_dijkstra.sy │ ├── 71_full_conn.in │ ├── 71_full_conn.out │ ├── 71_full_conn.sy │ ├── 72_hanoi.in │ ├── 72_hanoi.out │ ├── 72_hanoi.sy │ ├── 73_int_io.in │ ├── 73_int_io.out │ ├── 73_int_io.sy │ ├── 74_kmp.in │ ├── 74_kmp.out │ ├── 74_kmp.sy │ ├── 75_max_flow.in │ ├── 75_max_flow.out │ ├── 75_max_flow.sy │ ├── 76_n_queens.in │ ├── 76_n_queens.out │ ├── 76_n_queens.sy │ ├── 77_substr.out │ ├── 77_substr.sy │ ├── 78_side_effect.out │ ├── 78_side_effect.sy │ ├── 79_var_name.out │ ├── 79_var_name.sy │ ├── 80_chaos_token.out │ ├── 80_chaos_token.sy │ ├── 81_skip_spaces.in │ ├── 81_skip_spaces.out │ ├── 81_skip_spaces.sy │ ├── 82_long_func.out │ ├── 82_long_func.sy │ ├── 83_long_array.out │ ├── 83_long_array.sy │ ├── 84_long_array2.out │ ├── 84_long_array2.sy │ ├── 85_long_code.out │ ├── 85_long_code.sy │ ├── 86_long_code2.out │ ├── 86_long_code2.sy │ ├── 87_many_params.in │ ├── 87_many_params.out │ ├── 87_many_params.sy │ ├── 88_many_params2.out │ ├── 88_many_params2.sy │ ├── 89_many_globals.out │ ├── 89_many_globals.sy │ ├── 90_many_locals.out │ ├── 90_many_locals.sy │ ├── 91_many_locals2.in │ ├── 91_many_locals2.out │ ├── 91_many_locals2.sy │ ├── 92_register_alloc.in │ ├── 92_register_alloc.out │ ├── 92_register_alloc.sy │ ├── 93_nested_calls.in │ ├── 93_nested_calls.out │ ├── 93_nested_calls.sy │ ├── 94_nested_loops.in │ ├── 94_nested_loops.out │ ├── 94_nested_loops.sy │ ├── 95_float.in │ ├── 95_float.out │ ├── 95_float.sy │ ├── 96_matrix_add.out │ ├── 96_matrix_add.sy │ ├── 97_matrix_sub.out │ ├── 97_matrix_sub.sy │ ├── 98_matrix_mul.out │ ├── 98_matrix_mul.sy │ ├── 99_matrix_tran.out │ └── 99_matrix_tran.sy ├── hidden_functional │ ├── .gitkeep │ ├── 00_comment2.out │ ├── 00_comment2.sy │ ├── 01_multiple_returns.out │ ├── 01_multiple_returns.sy │ ├── 02_ret_in_block.out │ ├── 02_ret_in_block.sy │ ├── 03_branch.out │ ├── 03_branch.sy │ ├── 04_break_continue.out │ ├── 04_break_continue.sy │ ├── 05_param_name.out │ ├── 05_param_name.sy │ ├── 06_func_name.out │ ├── 06_func_name.sy │ ├── 07_arr_init_nd.out │ ├── 07_arr_init_nd.sy │ ├── 08_global_arr_init.out │ ├── 08_global_arr_init.sy │ ├── 09_BFS.in │ ├── 09_BFS.out │ ├── 09_BFS.sy │ ├── 10_DFS.in │ ├── 10_DFS.out │ ├── 10_DFS.sy │ ├── 11_BST.in │ ├── 11_BST.out │ ├── 11_BST.sy │ ├── 12_DSU.in │ ├── 12_DSU.out │ ├── 12_DSU.sy │ ├── 13_LCA.in │ ├── 13_LCA.out │ ├── 13_LCA.sy │ ├── 14_dp.in │ ├── 14_dp.out │ ├── 14_dp.sy │ ├── 15_graph_coloring.out │ ├── 15_graph_coloring.sy │ ├── 16_k_smallest.in │ ├── 16_k_smallest.out │ ├── 16_k_smallest.sy │ ├── 17_maximal_clique.in │ ├── 17_maximal_clique.out │ ├── 17_maximal_clique.sy │ ├── 18_prim.in │ ├── 18_prim.out │ ├── 18_prim.sy │ ├── 19_search.in │ ├── 19_search.out │ ├── 19_search.sy │ ├── 20_sort.in │ ├── 20_sort.out │ ├── 20_sort.sy │ ├── 21_union_find.in │ ├── 21_union_find.out │ ├── 21_union_find.sy │ ├── 22_matrix_multiply.in │ ├── 22_matrix_multiply.out │ ├── 22_matrix_multiply.sy │ ├── 23_json.in │ ├── 23_json.out │ ├── 23_json.sy │ ├── 24_array_only.in │ ├── 24_array_only.out │ ├── 24_array_only.sy │ ├── 25_scope3.out │ ├── 25_scope3.sy │ ├── 26_scope4.out │ ├── 26_scope4.sy │ ├── 27_scope5.out │ ├── 27_scope5.sy │ ├── 28_side_effect2.out │ ├── 28_side_effect2.sy │ ├── 29_long_line.out │ ├── 29_long_line.sy │ ├── 30_many_dimensions.out │ ├── 30_many_dimensions.sy │ ├── 31_many_indirections.out │ ├── 31_many_indirections.sy │ ├── 32_many_params3.out │ ├── 32_many_params3.sy │ ├── 33_multi_branch.in │ ├── 33_multi_branch.out │ ├── 33_multi_branch.sy │ ├── 34_multi_loop.out │ ├── 34_multi_loop.sy │ ├── 35_math.in │ ├── 35_math.out │ ├── 35_math.sy │ ├── 36_rotate.in │ ├── 36_rotate.out │ ├── 36_rotate.sy │ ├── 37_dct.in │ ├── 37_dct.out │ ├── 37_dct.sy │ ├── 38_light2d.out │ ├── 38_light2d.sy │ ├── 39_fp_params.in │ ├── 39_fp_params.out │ └── 39_fp_params.sy └── performance │ ├── 00_bitset1.sy │ ├── 00_bitset2.sy │ ├── 00_bitset3.sy │ ├── 02_mv1.sy │ ├── 02_mv2.sy │ ├── 02_mv3.sy │ ├── 03_sort1.sy │ ├── 03_sort2.sy │ ├── 03_sort3.sy │ ├── 04_spmv1.sy │ ├── 04_spmv2.sy │ ├── 04_spmv3.sy │ ├── brainfuck-bootstrap.sy │ ├── brainfuck-mandelbrot-nerf.sy │ ├── brainfuck-pi-nerf.sy │ ├── crypto-1.sy │ ├── crypto-2.sy │ ├── crypto-3.sy │ ├── fft0.sy │ ├── fft1.sy │ ├── fft2.sy │ ├── gameoflife-oscillator.sy │ ├── gameoflife-p61glidergun.sy │ ├── median0.sy │ ├── median1.sy │ ├── median2.sy │ ├── shuffle0.sy │ ├── shuffle1.sy │ ├── shuffle2.sy │ ├── transpose0.sy │ ├── transpose1.sy │ └── transpose2.sy └── third_party └── antlr4-runtime ├── ANTLRErrorListener.cpp ├── ANTLRErrorListener.h ├── ANTLRErrorStrategy.cpp ├── ANTLRErrorStrategy.h ├── ANTLRFileStream.cpp ├── ANTLRFileStream.h ├── ANTLRInputStream.cpp ├── ANTLRInputStream.h ├── BailErrorStrategy.cpp ├── BailErrorStrategy.h ├── BaseErrorListener.cpp ├── BaseErrorListener.h ├── BufferedTokenStream.cpp ├── BufferedTokenStream.h ├── CharStream.cpp ├── CharStream.h ├── CommonToken.cpp ├── CommonToken.h ├── CommonTokenFactory.cpp ├── CommonTokenFactory.h ├── CommonTokenStream.cpp ├── CommonTokenStream.h ├── ConsoleErrorListener.cpp ├── ConsoleErrorListener.h ├── DefaultErrorStrategy.cpp ├── DefaultErrorStrategy.h ├── DiagnosticErrorListener.cpp ├── DiagnosticErrorListener.h ├── Exceptions.cpp ├── Exceptions.h ├── FailedPredicateException.cpp ├── FailedPredicateException.h ├── InputMismatchException.cpp ├── InputMismatchException.h ├── IntStream.cpp ├── IntStream.h ├── InterpreterRuleContext.cpp ├── InterpreterRuleContext.h ├── Lexer.cpp ├── Lexer.h ├── LexerInterpreter.cpp ├── LexerInterpreter.h ├── LexerNoViableAltException.cpp ├── LexerNoViableAltException.h ├── ListTokenSource.cpp ├── ListTokenSource.h ├── NoViableAltException.cpp ├── NoViableAltException.h ├── Parser.cpp ├── Parser.h ├── ParserInterpreter.cpp ├── ParserInterpreter.h ├── ParserRuleContext.cpp ├── ParserRuleContext.h ├── ProxyErrorListener.cpp ├── ProxyErrorListener.h ├── RecognitionException.cpp ├── RecognitionException.h ├── Recognizer.cpp ├── Recognizer.h ├── RuleContext.cpp ├── RuleContext.h ├── RuleContextWithAltNum.cpp ├── RuleContextWithAltNum.h ├── RuntimeMetaData.cpp ├── RuntimeMetaData.h ├── Token.cpp ├── Token.h ├── TokenFactory.h ├── TokenSource.cpp ├── TokenSource.h ├── TokenStream.cpp ├── TokenStream.h ├── TokenStreamRewriter.cpp ├── TokenStreamRewriter.h ├── UnbufferedCharStream.cpp ├── UnbufferedCharStream.h ├── UnbufferedTokenStream.cpp ├── UnbufferedTokenStream.h ├── Vocabulary.cpp ├── Vocabulary.h ├── WritableToken.cpp ├── WritableToken.h ├── antlr4-common.h ├── antlr4-runtime.h ├── atn ├── ATN.cpp ├── ATN.h ├── ATNConfig.cpp ├── ATNConfig.h ├── ATNConfigSet.cpp ├── ATNConfigSet.h ├── ATNDeserializationOptions.cpp ├── ATNDeserializationOptions.h ├── ATNDeserializer.cpp ├── ATNDeserializer.h ├── ATNSerializer.cpp ├── ATNSerializer.h ├── ATNSimulator.cpp ├── ATNSimulator.h ├── ATNState.cpp ├── ATNState.h ├── ATNType.h ├── AbstractPredicateTransition.cpp ├── AbstractPredicateTransition.h ├── ActionTransition.cpp ├── ActionTransition.h ├── AmbiguityInfo.cpp ├── AmbiguityInfo.h ├── ArrayPredictionContext.cpp ├── ArrayPredictionContext.h ├── AtomTransition.cpp ├── AtomTransition.h ├── BasicBlockStartState.cpp ├── BasicBlockStartState.h ├── BasicState.cpp ├── BasicState.h ├── BlockEndState.cpp ├── BlockEndState.h ├── BlockStartState.cpp ├── BlockStartState.h ├── ContextSensitivityInfo.cpp ├── ContextSensitivityInfo.h ├── DecisionEventInfo.cpp ├── DecisionEventInfo.h ├── DecisionInfo.cpp ├── DecisionInfo.h ├── DecisionState.cpp ├── DecisionState.h ├── EmptyPredictionContext.cpp ├── EmptyPredictionContext.h ├── EpsilonTransition.cpp ├── EpsilonTransition.h ├── ErrorInfo.cpp ├── ErrorInfo.h ├── LL1Analyzer.cpp ├── LL1Analyzer.h ├── LexerATNConfig.cpp ├── LexerATNConfig.h ├── LexerATNSimulator.cpp ├── LexerATNSimulator.h ├── LexerAction.cpp ├── LexerAction.h ├── LexerActionExecutor.cpp ├── LexerActionExecutor.h ├── LexerActionType.h ├── LexerChannelAction.cpp ├── LexerChannelAction.h ├── LexerCustomAction.cpp ├── LexerCustomAction.h ├── LexerIndexedCustomAction.cpp ├── LexerIndexedCustomAction.h ├── LexerModeAction.cpp ├── LexerModeAction.h ├── LexerMoreAction.cpp ├── LexerMoreAction.h ├── LexerPopModeAction.cpp ├── LexerPopModeAction.h ├── LexerPushModeAction.cpp ├── LexerPushModeAction.h ├── LexerSkipAction.cpp ├── LexerSkipAction.h ├── LexerTypeAction.cpp ├── LexerTypeAction.h ├── LookaheadEventInfo.cpp ├── LookaheadEventInfo.h ├── LoopEndState.cpp ├── LoopEndState.h ├── NotSetTransition.cpp ├── NotSetTransition.h ├── OrderedATNConfigSet.cpp ├── OrderedATNConfigSet.h ├── ParseInfo.cpp ├── ParseInfo.h ├── ParserATNSimulator.cpp ├── ParserATNSimulator.h ├── PlusBlockStartState.cpp ├── PlusBlockStartState.h ├── PlusLoopbackState.cpp ├── PlusLoopbackState.h ├── PrecedencePredicateTransition.cpp ├── PrecedencePredicateTransition.h ├── PredicateEvalInfo.cpp ├── PredicateEvalInfo.h ├── PredicateTransition.cpp ├── PredicateTransition.h ├── PredictionContext.cpp ├── PredictionContext.h ├── PredictionMode.cpp ├── PredictionMode.h ├── ProfilingATNSimulator.cpp ├── ProfilingATNSimulator.h ├── RangeTransition.cpp ├── RangeTransition.h ├── RuleStartState.cpp ├── RuleStartState.h ├── RuleStopState.cpp ├── RuleStopState.h ├── RuleTransition.cpp ├── RuleTransition.h ├── SemanticContext.cpp ├── SemanticContext.h ├── SetTransition.cpp ├── SetTransition.h ├── SingletonPredictionContext.cpp ├── SingletonPredictionContext.h ├── StarBlockStartState.cpp ├── StarBlockStartState.h ├── StarLoopEntryState.cpp ├── StarLoopEntryState.h ├── StarLoopbackState.cpp ├── StarLoopbackState.h ├── TokensStartState.cpp ├── TokensStartState.h ├── Transition.cpp ├── Transition.h ├── WildcardTransition.cpp └── WildcardTransition.h ├── dfa ├── DFA.cpp ├── DFA.h ├── DFASerializer.cpp ├── DFASerializer.h ├── DFAState.cpp ├── DFAState.h ├── LexerDFASerializer.cpp └── LexerDFASerializer.h ├── misc ├── InterpreterDataReader.cpp ├── InterpreterDataReader.h ├── Interval.cpp ├── Interval.h ├── IntervalSet.cpp ├── IntervalSet.h ├── MurmurHash.cpp ├── MurmurHash.h ├── Predicate.cpp └── Predicate.h ├── support ├── Any.cpp ├── Any.h ├── Arrays.cpp ├── Arrays.h ├── BitSet.h ├── CPPUtils.cpp ├── CPPUtils.h ├── Declarations.h ├── StringUtils.cpp ├── StringUtils.h ├── guid.cpp └── guid.h └── tree ├── AbstractParseTreeVisitor.h ├── ErrorNode.cpp ├── ErrorNode.h ├── ErrorNodeImpl.cpp ├── ErrorNodeImpl.h ├── IterativeParseTreeWalker.cpp ├── IterativeParseTreeWalker.h ├── ParseTree.cpp ├── ParseTree.h ├── ParseTreeListener.cpp ├── ParseTreeListener.h ├── ParseTreeProperty.h ├── ParseTreeVisitor.cpp ├── ParseTreeVisitor.h ├── ParseTreeWalker.cpp ├── ParseTreeWalker.h ├── TerminalNode.cpp ├── TerminalNode.h ├── TerminalNodeImpl.cpp ├── TerminalNodeImpl.h ├── Trees.cpp ├── Trees.h ├── pattern ├── Chunk.cpp ├── Chunk.h ├── ParseTreeMatch.cpp ├── ParseTreeMatch.h ├── ParseTreePattern.cpp ├── ParseTreePattern.h ├── ParseTreePatternMatcher.cpp ├── ParseTreePatternMatcher.h ├── RuleTagToken.cpp ├── RuleTagToken.h ├── TagChunk.cpp ├── TagChunk.h ├── TextChunk.cpp ├── TextChunk.h ├── TokenTagToken.cpp └── TokenTagToken.h └── xpath ├── XPath.cpp ├── XPath.h ├── XPathElement.cpp ├── XPathElement.h ├── XPathLexer.cpp ├── XPathLexer.g4 ├── XPathLexer.h ├── XPathLexer.tokens ├── XPathLexerErrorListener.cpp ├── XPathLexerErrorListener.h ├── XPathRuleAnywhereElement.cpp ├── XPathRuleAnywhereElement.h ├── XPathRuleElement.cpp ├── XPathRuleElement.h ├── XPathTokenAnywhereElement.cpp ├── XPathTokenAnywhereElement.h ├── XPathTokenElement.cpp ├── XPathTokenElement.h ├── XPathWildcardAnywhereElement.cpp ├── XPathWildcardAnywhereElement.h ├── XPathWildcardElement.cpp └── XPathWildcardElement.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .DS_Store 3 | build 4 | .cache 5 | 6 | # CMake 7 | CMakeLists.txt.user 8 | CMakeCache.txt 9 | CMakeFiles 10 | CMakeScripts 11 | Testing 12 | Makefile 13 | cmake_install.cmake 14 | install_manifest.txt 15 | compile_commands.json 16 | CTestTestfile.cmake 17 | _deps 18 | 19 | # VSCode 20 | .vscode 21 | 22 | # ANTLR 23 | .antlr 24 | 25 | sub 26 | **/*.s 27 | 28 | .texpadtmp 29 | -------------------------------------------------------------------------------- /doc/arch.md: -------------------------------------------------------------------------------- 1 | ```mermaid 2 | flowchart LR 3 | subgraph ANTLR 4 | Lexer 5 | Lexer --> |Tokens| Parser 6 | end 7 | subgraph IR 8 | av(AST Visitor) 9 | av(AST Visitor) --> |IR| io(IR Optimizer) 10 | end 11 | subgraph Backend 12 | apo(ARM Pre-Optimizer) --> |Pesudo ARM assembly| ra(Register Allocator) 13 | ra(Register Allocator) --> |ARM assembly| aao(ARM After-Optimizer) 14 | end 15 | ui(Compiler Input) --> |SysY Code| ANTLR 16 | ANTLR --> |AST| IR 17 | IR --> |Optimized IR| Backend 18 | Backend --> |Optimized ARM assembly| co(Compiler Output) 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /doc/arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helesta-compiler/helesta/245d1291093a873c41712af98911724828c3e1c9/doc/arch.png -------------------------------------------------------------------------------- /doc/report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helesta-compiler/helesta/245d1291093a873c41712af98911724828c3e1c9/doc/report.pdf -------------------------------------------------------------------------------- /scripts/clear_testcase_exes.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | 4 | 5 | def parse_args(): 6 | parser = argparse.ArgumentParser(); 7 | parser.add_argument('--exes_dir', default='./testcases'); 8 | args = parser.parse_args(); 9 | return args; 10 | 11 | 12 | def run_with(args): 13 | for mod in os.listdir(args.exes_dir): 14 | mod_path = os.path.join(args.exes_dir, mod) 15 | for filename in os.listdir(mod_path): 16 | if not filename.endswith(".sy"): 17 | continue 18 | exe_path = os.path.join(mod_path, filename[:-3]) 19 | if os.path.exists(exe_path): 20 | print("removing {}".format(exe_path)) 21 | os.remove(exe_path) 22 | 23 | 24 | if __name__ == '__main__': 25 | args = parse_args() 26 | run_with(args) 27 | -------------------------------------------------------------------------------- /src/arm/opt/afterplay.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "arm/program.hpp" 4 | 5 | namespace ARMv7 { 6 | 7 | void replace_complex_inst(Program *); 8 | void remove_trivial_inst(Program *); 9 | bool eliminate_branch(Program *); 10 | void remove_empty_blocks(Program *); 11 | 12 | inline void afterplay(Program *prog) { 13 | replace_complex_inst(prog); 14 | remove_trivial_inst(prog); 15 | PassEnabled("eliminate-branch") { 16 | while (eliminate_branch(prog)) { 17 | remove_empty_blocks(prog); 18 | } 19 | } 20 | } 21 | } // namespace ARMv7 22 | -------------------------------------------------------------------------------- /src/arm/opt/dce.cpp: -------------------------------------------------------------------------------- 1 | #include "arm/opt/foreplay.hpp" 2 | 3 | namespace ARMv7 { 4 | 5 | template 6 | void reverse_for_each_del(std::list &ls, const F &f) { 7 | for (auto it = ls.end(); it != ls.begin();) { 8 | auto it0 = it; 9 | if (f(*--it)) { 10 | ls.erase(it); 11 | it = it0; 12 | } 13 | } 14 | } 15 | 16 | void dce(Func *func) { 17 | func->calc_live(); 18 | for (auto &block : func->blocks) { 19 | auto live = block->live_out; 20 | bool use_cpsr = false; 21 | reverse_for_each_del(block->insts, [&](std::unique_ptr &cur) -> bool { 22 | bool used = cur->side_effect(); 23 | used |= (cur->change_cpsr() && use_cpsr); 24 | for (Reg r : cur->def_reg()) 25 | if ((r.is_machine() && !r.is_allocable()) || live.count(r)) 26 | used = true; 27 | if (!used) 28 | return 1; 29 | use_cpsr &= !cur->change_cpsr(); 30 | use_cpsr |= cur->use_cpsr(); 31 | cur->update_live(live); 32 | return 0; 33 | }); 34 | } 35 | } 36 | 37 | void dce(Program *prog) { 38 | for (auto &f : prog->funcs) { 39 | dce(f.get()); 40 | } 41 | } 42 | 43 | } // namespace ARMv7 44 | -------------------------------------------------------------------------------- /src/arm/opt/foreplay.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "arm/program.hpp" 4 | 5 | namespace ARMv7 { 6 | 7 | void merge_instr(Program *); 8 | void replace_pseduo_inst(Program *); 9 | void dce(Program *); 10 | 11 | inline void foreplay(Program *prog) { 12 | PassEnabled("mi") merge_instr(prog); 13 | replace_pseduo_inst(prog); 14 | PassEnabled("dce") dce(prog); 15 | } 16 | 17 | } // namespace ARMv7 18 | -------------------------------------------------------------------------------- /src/arm/opt/replace_pseduo_inst.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "arm/opt/foreplay.hpp" 4 | 5 | namespace ARMv7 { 6 | 7 | void replace_pseduo_inst(Func *func) { 8 | for (auto &block : func->blocks) { 9 | auto &insts = block->insts; 10 | for (auto it = insts.begin(); it != insts.end(); ++it) { 11 | Inst *inst = it->get(); 12 | if (auto bop = dynamic_cast(inst)) { 13 | if (bop->op == RegRegInst::Mod) { 14 | auto dst = bop->dst; 15 | auto s1 = bop->lhs; 16 | auto s2 = bop->rhs; 17 | insts.insert( 18 | it, std::make_unique(RegRegInst::Div, dst, s1, s2)); 19 | *it = std::make_unique(ML::Mls, dst, s2, dst, s1); 20 | } 21 | } 22 | } 23 | } 24 | } 25 | 26 | void replace_pseduo_inst(Program *prog) { 27 | for (auto &f : prog->funcs) { 28 | replace_pseduo_inst(f.get()); 29 | } 30 | } 31 | } // namespace ARMv7 32 | -------------------------------------------------------------------------------- /src/arm/program.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "arm/func.hpp" 13 | #include "arm/inst.hpp" 14 | #include "arm/irc_coloring_alloc.hpp" 15 | #include "arm/regalloc.hpp" 16 | #include "arm/simple_coloring_alloc.hpp" 17 | #include "ir/ir.hpp" 18 | 19 | namespace ARMv7 { 20 | 21 | struct Program { 22 | std::vector> funcs; 23 | std::vector> global_objects; 24 | int block_n; 25 | 26 | Program(IR::CompileUnit *ir); 27 | void gen_global_var_asm(std::ostream &out); 28 | void gen_asm(std::ostream &out); 29 | void allocate_register(); 30 | }; 31 | 32 | } // namespace ARMv7 33 | -------------------------------------------------------------------------------- /src/arm/regalloc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "arm/archinfo.hpp" 6 | #include "arm/func.hpp" 7 | #include "arm/inst.hpp" 8 | 9 | struct RegAllocStat { 10 | int spill_cnt, move_eliminated, callee_save_used; 11 | bool succeed; 12 | }; 13 | 14 | namespace ARMv7 { 15 | 16 | class ColoringAllocator { 17 | protected: 18 | Func *func; 19 | 20 | public: 21 | ColoringAllocator(Func *_func) : func(_func) {} 22 | virtual std::vector run(RegAllocStat *stat) = 0; 23 | virtual void clear() = 0; 24 | }; 25 | 26 | } // namespace ARMv7 27 | -------------------------------------------------------------------------------- /src/ast/exp_value.cpp: -------------------------------------------------------------------------------- 1 | #include "ast/exp_value.hpp" 2 | 3 | IRValue::IRValue(ScalarType scalar_type) : type(scalar_type) {} 4 | 5 | bool IRValue::assignable() const { 6 | return is_left_value && (!type.is_const) && (!type.is_array()); 7 | } 8 | -------------------------------------------------------------------------------- /src/ast/exp_value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ast/symbol_table.hpp" 4 | #include "ir/ir.hpp" 5 | 6 | // when visiting int expression, return IRValue 7 | // when visiting bool expression, return CondJumpList 8 | 9 | struct IRValue { 10 | Type type; 11 | bool is_left_value; 12 | IR::Reg reg; // if is_left_value, it's the address instead of the value 13 | 14 | bool assignable() const; // left value, not array and not constant 15 | IRValue(ScalarType scalar_type); 16 | friend std::ostream &operator<<(std::ostream &os, const IRValue &x) { 17 | os << x.type << ' ' << (x.is_left_value ? "lvalue" : "rvalue") << ' ' 18 | << x.reg; 19 | return os; 20 | } 21 | }; 22 | 23 | struct CondJumpList { 24 | std::vector true_list, false_list; 25 | }; 26 | -------------------------------------------------------------------------------- /src/ir/opt/special.cpp: -------------------------------------------------------------------------------- 1 | #include "ir/opt/opt.hpp" 2 | using namespace IR; 3 | void special(IR::CompileUnit *ir) { 4 | auto input = global_config.args["input"]; 5 | if (input.find("fft") != std::string::npos) { 6 | auto f0 = ir->funcs.at("multiply").get(); 7 | auto f1 = ir->lib_funcs.at("__umulmod").get(); 8 | ir->for_each([&](NormalFunc *f) { 9 | f->for_each([&](BB *bb) { 10 | bb->for_each([&](Instr *x) { 11 | Case(CallInstr, call, x) { 12 | if (call->f == f0) { 13 | call->f = f1; 14 | Reg r = f->new_Reg(); 15 | bb->ins(new LoadConst(r, 998244353)); 16 | call->args.emplace_back(r, ScalarType::Int); 17 | } 18 | } 19 | }); 20 | }); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/parser/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true -------------------------------------------------------------------------------- /src/parser/SysY.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | Int=2 3 | Float=3 4 | Void=4 5 | Const=5 6 | Return=6 7 | If=7 8 | Else=8 9 | For=9 10 | While=10 11 | Do=11 12 | Break=12 13 | Continue=13 14 | Lparen=14 15 | Rparen=15 16 | Lbrkt=16 17 | Rbrkt=17 18 | Lbrace=18 19 | Rbrace=19 20 | Comma=20 21 | Semicolon=21 22 | Question=22 23 | Colon=23 24 | Minus=24 25 | Exclamation=25 26 | Tilde=26 27 | Addition=27 28 | Multiplication=28 29 | Division=29 30 | Modulo=30 31 | LAND=31 32 | LOR=32 33 | EQ=33 34 | NEQ=34 35 | LT=35 36 | LE=36 37 | GT=37 38 | GE=38 39 | FloatLiteral=39 40 | DecimalFloatConst=40 41 | HexadecimalFloatConst=41 42 | IntLiteral=42 43 | Identifier=43 44 | STRING=44 45 | WS=45 46 | LINE_COMMENT=46 47 | COMMENT=47 48 | '='=1 49 | 'int'=2 50 | 'float'=3 51 | 'void'=4 52 | 'const'=5 53 | 'return'=6 54 | 'if'=7 55 | 'else'=8 56 | 'for'=9 57 | 'while'=10 58 | 'do'=11 59 | 'break'=12 60 | 'continue'=13 61 | '('=14 62 | ')'=15 63 | '['=16 64 | ']'=17 65 | '{'=18 66 | '}'=19 67 | ','=20 68 | ';'=21 69 | '?'=22 70 | ':'=23 71 | '-'=24 72 | '!'=25 73 | '~'=26 74 | '+'=27 75 | '*'=28 76 | '/'=29 77 | '%'=30 78 | '&&'=31 79 | '||'=32 80 | '=='=33 81 | '!='=34 82 | '<'=35 83 | '<='=36 84 | '>'=37 85 | '>='=38 86 | -------------------------------------------------------------------------------- /src/parser/SysYBaseListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from SysY.g4 by ANTLR 4.8 3 | 4 | 5 | #include "SysYBaseListener.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/parser/SysYBaseVisitor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from SysY.g4 by ANTLR 4.8 3 | 4 | 5 | #include "SysYBaseVisitor.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/parser/SysYLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | Int=2 3 | Float=3 4 | Void=4 5 | Const=5 6 | Return=6 7 | If=7 8 | Else=8 9 | For=9 10 | While=10 11 | Do=11 12 | Break=12 13 | Continue=13 14 | Lparen=14 15 | Rparen=15 16 | Lbrkt=16 17 | Rbrkt=17 18 | Lbrace=18 19 | Rbrace=19 20 | Comma=20 21 | Semicolon=21 22 | Question=22 23 | Colon=23 24 | Minus=24 25 | Exclamation=25 26 | Tilde=26 27 | Addition=27 28 | Multiplication=28 29 | Division=29 30 | Modulo=30 31 | LAND=31 32 | LOR=32 33 | EQ=33 34 | NEQ=34 35 | LT=35 36 | LE=36 37 | GT=37 38 | GE=38 39 | FloatLiteral=39 40 | DecimalFloatConst=40 41 | HexadecimalFloatConst=41 42 | IntLiteral=42 43 | Identifier=43 44 | STRING=44 45 | WS=45 46 | LINE_COMMENT=46 47 | COMMENT=47 48 | '='=1 49 | 'int'=2 50 | 'float'=3 51 | 'void'=4 52 | 'const'=5 53 | 'return'=6 54 | 'if'=7 55 | 'else'=8 56 | 'for'=9 57 | 'while'=10 58 | 'do'=11 59 | 'break'=12 60 | 'continue'=13 61 | '('=14 62 | ')'=15 63 | '['=16 64 | ']'=17 65 | '{'=18 66 | '}'=19 67 | ','=20 68 | ';'=21 69 | '?'=22 70 | ':'=23 71 | '-'=24 72 | '!'=25 73 | '~'=26 74 | '+'=27 75 | '*'=28 76 | '/'=29 77 | '%'=30 78 | '&&'=31 79 | '||'=32 80 | '=='=33 81 | '!='=34 82 | '<'=35 83 | '<='=36 84 | '>'=37 85 | '>='=38 86 | -------------------------------------------------------------------------------- /src/parser/SysYListener.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from SysY.g4 by ANTLR 4.8 3 | 4 | 5 | #include "SysYListener.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/parser/SysYVisitor.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Generated from SysY.g4 by ANTLR 4.8 3 | 4 | 5 | #include "SysYVisitor.h" 6 | 7 | 8 | -------------------------------------------------------------------------------- /testcases/custom/issue-115.in: -------------------------------------------------------------------------------- 1 | 1 2 3 2 | -------------------------------------------------------------------------------- /testcases/custom/issue-115.out: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/custom/issue-115.sy: -------------------------------------------------------------------------------- 1 | float foo(float x, int y, float z) { 2 | return x + y + z; 3 | } 4 | 5 | int main() { 6 | float x = getfloat(); 7 | int y = getint(); 8 | float z = getfloat(); 9 | float res = foo(x, y, z); 10 | if (res == x + y + z) 11 | putint(1); 12 | else 13 | putint(0); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /testcases/custom/issue-118.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4.1 5.1 6.1 2 | -------------------------------------------------------------------------------- /testcases/custom/issue-118.out: -------------------------------------------------------------------------------- 1 | 0x1.233334p+3 2 | 0x1.233334p+3 3 | 0 4 | -------------------------------------------------------------------------------- /testcases/custom/issue-118.sy: -------------------------------------------------------------------------------- 1 | float foo(int a, int b, int c, float fa, float fb, float fc) { 2 | if (a == 0) 3 | return fc; 4 | fa = fa + a; 5 | fb = fb + b; 6 | fc = fc + c; 7 | return foo(a - 1, b, c, fa, fb, fc); 8 | } 9 | 10 | int main() { 11 | int a = getint(); 12 | int b = getint(); 13 | int c = getint(); 14 | float fa = getfloat(); 15 | float fb = getfloat(); 16 | float fc = getfloat(); 17 | putfloat(foo(a, b, c, fa, fb, fc)); 18 | putch(10); 19 | putfloat(fc + c * a); 20 | putch(10); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /testcases/custom/issue-121.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 2 | -------------------------------------------------------------------------------- /testcases/custom/issue-121.out: -------------------------------------------------------------------------------- 1 | 0x1.5p+4 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/custom/issue-121.sy: -------------------------------------------------------------------------------- 1 | float sum(int a, float s0, float s1, float s2, float s3, float s4, float s5) { 2 | if (a > 0 && a % 2 == 0) 3 | return sum(a - 1, s0, s1, s2, s3, s4, s5); 4 | if (a > 0 && a % 2 == 1) 5 | return sum(a - 1, s0, s1, s2, s3, s4, s5); 6 | return s0 + s1 + s2 + s3 + s4 + s5; 7 | } 8 | 9 | int main() { 10 | float s0 = getfloat(); 11 | float s1 = getfloat(); 12 | float s2 = getfloat(); 13 | float s3 = getfloat(); 14 | float s4 = getfloat(); 15 | float s5 = getfloat(); 16 | putfloat(sum(10, s0, s1, s2, s3, s4, s5)); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /testcases/custom/issue-125.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4 2 | -------------------------------------------------------------------------------- /testcases/custom/issue-125.out: -------------------------------------------------------------------------------- 1 | 0x1p+0 2 | 0x1p+2 3 | 0x1p+0 4 | 0x1.4p+3 5 | 0 6 | -------------------------------------------------------------------------------- /testcases/custom/issue-125.sy: -------------------------------------------------------------------------------- 1 | float sum(int a, float s0, int s1, float s2, float s3) { 2 | if (a == 0) 3 | return s0 + s1 + s2 + s3; 4 | float res = sum(a - 1, s3, s1, s2, s0); 5 | putfloat(s0); 6 | putch(10); 7 | return res; 8 | } 9 | 10 | int main() { 11 | float s0 = getfloat(); 12 | int s1 = getint(); 13 | float s2 = getfloat(); 14 | float s3 = getfloat(); 15 | putfloat(sum(3, s0, s1, s2, s3)); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /testcases/custom/issue-131.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 2 | 1 2 3 4 5 6 7 3 | 10 -------------------------------------------------------------------------------- /testcases/custom/issue-131.out: -------------------------------------------------------------------------------- 1 | 0x1p+0 2 | 0x1.cp+2 3 | 0x1p+0 4 | 0x1.cp+2 5 | 0x1p+0 6 | 0x1.cp+2 7 | 0x1p+0 8 | 0x1.cp+2 9 | 0x1p+0 10 | 0x1.cp+2 11 | 0x1p+0 12 | 0x1.cp+5 13 | 0 14 | -------------------------------------------------------------------------------- /testcases/custom/issue-131.sy: -------------------------------------------------------------------------------- 1 | float sum(int a, int i0, float f0, int i1, float f1, int i2, float f2, int i3, float f3, int i4, float f4, int i5, float f5, int i6, float f6) { 2 | putfloat(f0); 3 | putch(10); 4 | if (a == 0) { 5 | return i0 + f0 + i1 + f1 + i2 + f2 + i3 + f3 + i4 + f4 + i5 + f5 + i6 + f6; 6 | } 7 | return sum(a - 1, i6, f6, i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i0, f0); 8 | } 9 | 10 | int main() { 11 | int i0 = getint(); 12 | int i1 = getint(); 13 | int i2 = getint(); 14 | int i3 = getint(); 15 | int i4 = getint(); 16 | int i5 = getint(); 17 | int i6 = getint(); 18 | float f0 = getfloat(); 19 | float f1 = getfloat(); 20 | float f2 = getfloat(); 21 | float f3 = getfloat(); 22 | float f4 = getfloat(); 23 | float f5 = getfloat(); 24 | float f6 = getfloat(); 25 | int a = getint(); 26 | putfloat(sum(a, i0, f0, i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6)); 27 | putch(10); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /testcases/custom/issue-154.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helesta-compiler/helesta/245d1291093a873c41712af98911724828c3e1c9/testcases/custom/issue-154.in -------------------------------------------------------------------------------- /testcases/custom/issue-154.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testcases/custom/issue-154.sy: -------------------------------------------------------------------------------- 1 | float foo(float x, int y) { 2 | return x + y; 3 | } 4 | 5 | int main() { 6 | foo(0, 0); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /testcases/custom/putfloat.out: -------------------------------------------------------------------------------- 1 | 0x1.99999ap-4 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/custom/putfloat.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | putfloat(0.1); 3 | putch(10); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/custom/test_simd_1.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /testcases/custom/test_simd_1.out: -------------------------------------------------------------------------------- 1 | -1405117146 2 | 38 3 | -------------------------------------------------------------------------------- /testcases/custom/test_simd_1.sy: -------------------------------------------------------------------------------- 1 | const int N=1000; 2 | int a[N]; 3 | int b[N]; 4 | int c[N]; 5 | float d[N]; 6 | int main(){ 7 | int n=1000; 8 | int i=0; 9 | while(i= -0.000001) { 41 | putint(0); 42 | return 0; 43 | } 44 | else { 45 | putint(1); 46 | return 1; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /testcases/final_performance/large_loop_array_2.sy: -------------------------------------------------------------------------------- 1 | 2 | int COUNT = 500000; 3 | 4 | float loop(float x[], float y[], int length) { 5 | int i = 0; 6 | float accumulator = 0.0; 7 | while (i < length) { 8 | accumulator = accumulator + x[i] * y[i]; 9 | i = i + 1; 10 | } 11 | return accumulator; 12 | } 13 | 14 | int main() { 15 | int i = 0, j = 0; 16 | int len = getint(); 17 | float x[4096]; 18 | float y[4096]; 19 | float total = 0.0; 20 | float a = 0.0; 21 | float b = 1.0; 22 | starttime(); 23 | while ( i < COUNT) { 24 | if (i % 10) { 25 | a = 0.0; 26 | b = 1.0; 27 | } else { 28 | a = a + 0.1; 29 | b = b + 0.2; 30 | } 31 | while ( j < len) { 32 | x[j] = a + j; 33 | y[j] = b + j; 34 | j = j + 1; 35 | } 36 | total = total + loop(x, y, len); 37 | i = i + 1; 38 | } 39 | stoptime(); 40 | if ((total - 11442437121638400.000000) <=0.000001 || (total - 11442437121638400.000000) >= -0.000001) { 41 | putint(0); 42 | return 0; 43 | } 44 | else { 45 | putint(1); 46 | return 1; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /testcases/final_performance/large_loop_array_3.sy: -------------------------------------------------------------------------------- 1 | 2 | int COUNT = 100000; 3 | 4 | float loop(float x[], float y[], int length) { 5 | int i = 0; 6 | float accumulator = 0.0; 7 | while (i < length) { 8 | accumulator = accumulator + x[i] * y[i]; 9 | i = i + 1; 10 | } 11 | return accumulator; 12 | } 13 | 14 | int main() { 15 | int i = 0, j = 0; 16 | int len = getint(); 17 | float x[8192]; 18 | float y[8192]; 19 | float total = 0.0; 20 | float a = 0.0; 21 | float b = 1.0; 22 | starttime(); 23 | while ( i < COUNT) { 24 | if (i % 10) { 25 | a = 0.0; 26 | b = 1.0; 27 | } else { 28 | a = a + 0.1; 29 | b = b + 0.2; 30 | } 31 | while ( j < len) { 32 | x[j] = a + j; 33 | y[j] = b + j; 34 | j = j + 1; 35 | } 36 | total = total + loop(x, y, len); 37 | i = i + 1; 38 | } 39 | stoptime(); 40 | if ((total - 18338022147751936.000000) <=0.000001 || (total - 18338022147751936.000000) >= -0.000001) { 41 | putint(0); 42 | return 0; 43 | } 44 | else { 45 | putint(1); 46 | return 1; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /testcases/final_performance/recursion_fabonacci-1.sy: -------------------------------------------------------------------------------- 1 | 2 | 3 | // recursive function operation 4 | 5 | float fibFP(float n) { 6 | if (n < 2.0) { 7 | return 1.0; 8 | } 9 | return fibFP(n - 2.0) + fibFP(n - 1.0); 10 | } 11 | 12 | float takFP(float x, float y, float z) { 13 | if (y < x) 14 | return takFP( takFP(x-1.0, y, z), takFP(y-1.0, z, x), takFP(z-1.0, x, y) ); 15 | return z; 16 | } 17 | int main() 18 | { 19 | starttime(); 20 | int n = getint(); 21 | 22 | float x = getfloat(); 23 | float y = getfloat(); 24 | float z = getfloat(); 25 | float f1 = fibFP(28.0 + n); 26 | float t1 = takFP(x, y, z); 27 | if(f1==63245984.0){ 28 | putch(112); 29 | } 30 | else{ 31 | putint(1); 32 | 33 | } 34 | if(t1==2.0){ 35 | putch(112); 36 | } 37 | else { 38 | putint(1); 39 | } 40 | stoptime(); 41 | return 0; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /testcases/final_performance/recursion_fabonacci-2.sy: -------------------------------------------------------------------------------- 1 | 2 | 3 | // recursive function operation 4 | 5 | float fibFP(float n) { 6 | if (n < 2.0) { 7 | return 1.0; 8 | } 9 | return fibFP(n - 2.0) + fibFP(n - 1.0); 10 | } 11 | 12 | float takFP(float x, float y, float z) { 13 | if (y < x) 14 | return takFP( takFP(x-1.0, y, z), takFP(y-1.0, z, x), takFP(z-1.0, x, y) ); 15 | return z; 16 | } 17 | 18 | int main() 19 | { 20 | starttime(); 21 | int n = getint(); 22 | float x = getfloat(); 23 | float y = getfloat(); 24 | float z = getfloat(); 25 | 26 | float f1 = fibFP(28.0 + n); 27 | float t1 = takFP(x, y, z); 28 | 29 | if(f1==39088168.0){ 30 | putch(112); 31 | } 32 | else{ 33 | putint(1); 34 | } 35 | if(t1==1.0){ 36 | putch(112); 37 | } 38 | else { 39 | putint(1); 40 | } 41 | stoptime(); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /testcases/final_performance/recursion_fabonacci-3.sy: -------------------------------------------------------------------------------- 1 | 2 | 3 | // recursive function operation 4 | 5 | float fibFP(float n) { 6 | if (n < 2.0) { 7 | return 1.0; 8 | } 9 | return fibFP(n - 2.0) + fibFP(n - 1.0); 10 | } 11 | 12 | float takFP(float x, float y, float z) { 13 | if (y < x) 14 | return takFP( takFP(x-1.0, y, z), takFP(y-1.0, z, x), takFP(z-1.0, x, y) ); 15 | return z; 16 | } 17 | 18 | int main() 19 | { 20 | starttime(); 21 | int n = getint(); 22 | float x = getfloat(); 23 | float y = getfloat(); 24 | float z = getfloat(); 25 | 26 | float f1 = fibFP(28.0 + n); 27 | float t1 = takFP(x, y, z); 28 | 29 | if(f1==165580128.0){ 30 | putch(112); 31 | } 32 | else{ 33 | putint(1); 34 | } 35 | if(t1==2.0){ 36 | putch(112); 37 | } 38 | else { 39 | putint(1); 40 | } 41 | stoptime(); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /testcases/final_performance/recursive_call_1.sy: -------------------------------------------------------------------------------- 1 | float myabs(float num) { 2 | if(num>0){ 3 | return num; 4 | } 5 | if(num<0){ 6 | return -num; 7 | } 8 | } 9 | 10 | float func(float data, int num) { 11 | if (num < 0) { 12 | return 0; 13 | } 14 | num=num-1; 15 | data = data + func(data, num); 16 | data = data - func(data, num); 17 | return data; 18 | } 19 | 20 | int main() { 21 | starttime(); 22 | float a = 1.001; 23 | int num = getint(); 24 | float res; 25 | float expect = 0.0; 26 | 27 | 28 | res = func(a, num); 29 | 30 | if (res - expect==0) 31 | putch(112); 32 | stoptime(); 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /testcases/final_performance/recursive_call_2.sy: -------------------------------------------------------------------------------- 1 | float myabs(float num) { 2 | if(num>0){ 3 | return num; 4 | } 5 | if(num<0){ 6 | return -num; 7 | } 8 | } 9 | 10 | float func(float data, int num) { 11 | if (num < 0) { 12 | return 0; 13 | } 14 | num=num-1; 15 | data = data + func(data, num); 16 | data = data - func(data, num); 17 | return data; 18 | } 19 | 20 | int main() { 21 | starttime(); 22 | float a = 1.001; 23 | int num = getint(); 24 | float res; 25 | float expect = 0.0; 26 | 27 | 28 | res = func(a, num); 29 | 30 | if (res - expect==0) 31 | putch(112); 32 | stoptime(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /testcases/final_performance/recursive_call_3.sy: -------------------------------------------------------------------------------- 1 | float myabs(float num) { 2 | if(num>0){ 3 | return num; 4 | } 5 | if(num<0){ 6 | return -num; 7 | } 8 | } 9 | 10 | float func(float data, int num) { 11 | if (num < 0) { 12 | return 0; 13 | } 14 | num=num-1; 15 | data = data + func(data, num); 16 | data = data - func(data, num); 17 | return data; 18 | } 19 | 20 | int main() { 21 | starttime(); 22 | float a = 1.001; 23 | int num = getint(); 24 | float res; 25 | float expect = 1.001; 26 | 27 | 28 | res = func(a, num); 29 | 30 | if (res - expect==0) 31 | putch(112); 32 | stoptime(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /testcases/functional/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helesta-compiler/helesta/245d1291093a873c41712af98911724828c3e1c9/testcases/functional/.gitkeep -------------------------------------------------------------------------------- /testcases/functional/00_main.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testcases/functional/00_main.sy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | return 3; 3 | } -------------------------------------------------------------------------------- /testcases/functional/01_var_defn2.out: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testcases/functional/01_var_defn2.sy: -------------------------------------------------------------------------------- 1 | //test domain of global var define and local define 2 | int a = 3; 3 | int b = 5; 4 | 5 | int main(){ 6 | int a = 5; 7 | return a + b; 8 | } -------------------------------------------------------------------------------- /testcases/functional/02_var_defn3.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testcases/functional/02_var_defn3.sy: -------------------------------------------------------------------------------- 1 | //test local var define 2 | int main(){ 3 | int a, b0, _c; 4 | a = 1; 5 | b0 = 2; 6 | _c = 3; 7 | return b0 + _c; 8 | } -------------------------------------------------------------------------------- /testcases/functional/03_arr_defn2.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testcases/functional/03_arr_defn2.sy: -------------------------------------------------------------------------------- 1 | int a[10][10]; 2 | int main(){ 3 | return 0; 4 | } -------------------------------------------------------------------------------- /testcases/functional/04_arr_defn3.out: -------------------------------------------------------------------------------- 1 | 14 2 | -------------------------------------------------------------------------------- /testcases/functional/04_arr_defn3.sy: -------------------------------------------------------------------------------- 1 | //test array define 2 | int main(){ 3 | int a[4][2] = {}; 4 | int b[4][2] = {1, 2, 3, 4, 5, 6, 7, 8}; 5 | int c[4][2] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; 6 | int d[4][2] = {1, 2, {3}, {5}, 7 , 8}; 7 | int e[4][2] = {{d[2][1], c[2][1]}, {3, 4}, {5, 6}, {7, 8}}; 8 | return e[3][1] + e[0][0] + e[0][1] + a[2][0]; 9 | } -------------------------------------------------------------------------------- /testcases/functional/05_arr_defn4.out: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /testcases/functional/05_arr_defn4.sy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | const int a[4][2] = {{1, 2}, {3, 4}, {}, 7}; 3 | const int N = 3; 4 | int b[4][2] = {}; 5 | int c[4][2] = {1, 2, 3, 4, 5, 6, 7, 8}; 6 | int d[N + 1][2] = {1, 2, {3}, {5}, a[3][0], 8}; 7 | int e[4][2][1] = {{d[2][1], {c[2][1]}}, {3, 4}, {5, 6}, {7, 8}}; 8 | return e[3][1][0] + e[0][0][0] + e[0][1][0] + d[3][0]; 9 | } 10 | -------------------------------------------------------------------------------- /testcases/functional/06_const_var_defn2.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testcases/functional/06_const_var_defn2.sy: -------------------------------------------------------------------------------- 1 | //test const gloal var define 2 | const int a = 10, b = 5; 3 | 4 | int main(){ 5 | return b; 6 | } -------------------------------------------------------------------------------- /testcases/functional/07_const_var_defn3.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testcases/functional/07_const_var_defn3.sy: -------------------------------------------------------------------------------- 1 | //test const local var define 2 | int main(){ 3 | const int a = 10, b = 5; 4 | return b; 5 | } -------------------------------------------------------------------------------- /testcases/functional/08_const_array_defn.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /testcases/functional/08_const_array_defn.sy: -------------------------------------------------------------------------------- 1 | const int a[5]={0,1,2,3,4}; 2 | 3 | int main(){ 4 | return a[4]; 5 | } -------------------------------------------------------------------------------- /testcases/functional/09_func_defn.out: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /testcases/functional/09_func_defn.sy: -------------------------------------------------------------------------------- 1 | int a; 2 | int func(int p){ 3 | p = p - 1; 4 | return p; 5 | } 6 | int main(){ 7 | int b; 8 | a = 10; 9 | b = func(a); 10 | return b; 11 | } 12 | -------------------------------------------------------------------------------- /testcases/functional/10_var_defn_func.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /testcases/functional/10_var_defn_func.sy: -------------------------------------------------------------------------------- 1 | int defn(){ 2 | return 4; 3 | } 4 | 5 | int main(){ 6 | int a=defn(); 7 | return a; 8 | } -------------------------------------------------------------------------------- /testcases/functional/11_add2.out: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /testcases/functional/11_add2.sy: -------------------------------------------------------------------------------- 1 | //test add 2 | int main(){ 3 | int a, b; 4 | a = 10; 5 | b = -1; 6 | return a + b; 7 | } -------------------------------------------------------------------------------- /testcases/functional/12_addc.out: -------------------------------------------------------------------------------- 1 | 15 2 | -------------------------------------------------------------------------------- /testcases/functional/12_addc.sy: -------------------------------------------------------------------------------- 1 | //test addc 2 | const int a = 10; 3 | int main(){ 4 | return a + 5; 5 | } -------------------------------------------------------------------------------- /testcases/functional/13_sub2.out: -------------------------------------------------------------------------------- 1 | 248 2 | -------------------------------------------------------------------------------- /testcases/functional/13_sub2.sy: -------------------------------------------------------------------------------- 1 | //test sub 2 | const int a = 10; 3 | int main(){ 4 | int b; 5 | b = 2; 6 | return b - a; 7 | } -------------------------------------------------------------------------------- /testcases/functional/14_subc.out: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /testcases/functional/14_subc.sy: -------------------------------------------------------------------------------- 1 | //test subc 2 | int main(){ 3 | int a; 4 | a = 10; 5 | return a - 2; 6 | } -------------------------------------------------------------------------------- /testcases/functional/15_mul.out: -------------------------------------------------------------------------------- 1 | 50 2 | -------------------------------------------------------------------------------- /testcases/functional/15_mul.sy: -------------------------------------------------------------------------------- 1 | //test mul 2 | int main(){ 3 | int a, b; 4 | a = 10; 5 | b = 5; 6 | return a * b; 7 | } -------------------------------------------------------------------------------- /testcases/functional/16_mulc.out: -------------------------------------------------------------------------------- 1 | 25 2 | -------------------------------------------------------------------------------- /testcases/functional/16_mulc.sy: -------------------------------------------------------------------------------- 1 | //test mulc 2 | const int a = 5; 3 | int main(){ 4 | return a * 5; 5 | } -------------------------------------------------------------------------------- /testcases/functional/17_div.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testcases/functional/17_div.sy: -------------------------------------------------------------------------------- 1 | //test div 2 | int main(){ 3 | int a, b; 4 | a = 10; 5 | b = 5; 6 | return a / b; 7 | } -------------------------------------------------------------------------------- /testcases/functional/18_divc.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /testcases/functional/18_divc.sy: -------------------------------------------------------------------------------- 1 | //test divc 2 | const int a = 10; 3 | int main(){ 4 | return a / 5; 5 | } -------------------------------------------------------------------------------- /testcases/functional/19_mod.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testcases/functional/19_mod.sy: -------------------------------------------------------------------------------- 1 | //test mod 2 | int main(){ 3 | int a; 4 | a = 10; 5 | return a / 3; 6 | } -------------------------------------------------------------------------------- /testcases/functional/20_rem.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testcases/functional/20_rem.sy: -------------------------------------------------------------------------------- 1 | //test rem 2 | int main(){ 3 | int a; 4 | a = 10; 5 | return a % 3; 6 | } -------------------------------------------------------------------------------- /testcases/functional/21_if_test2.out: -------------------------------------------------------------------------------- 1 | -5 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/21_if_test2.sy: -------------------------------------------------------------------------------- 1 | // test if-else-if 2 | int ifElseIf() { 3 | int a; 4 | a = 5; 5 | int b; 6 | b = 10; 7 | if(a == 6 || b == 0xb) { 8 | return a; 9 | } 10 | else { 11 | if (b == 10 && a == 1) 12 | a = 25; 13 | else if (b == 10 && a == -5) 14 | a = a + 15; 15 | else 16 | a = -+a; 17 | } 18 | 19 | return a; 20 | } 21 | 22 | int main(){ 23 | putint(ifElseIf()); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /testcases/functional/22_if_test3.out: -------------------------------------------------------------------------------- 1 | 25 2 | -------------------------------------------------------------------------------- /testcases/functional/22_if_test3.sy: -------------------------------------------------------------------------------- 1 | // test if-if-else 2 | int ififElse() { 3 | int a; 4 | a = 5; 5 | int b; 6 | b = 10; 7 | if(a == 5) 8 | if (b == 10) 9 | a = 25; 10 | else 11 | a = a + 15; 12 | 13 | return (a); 14 | } 15 | 16 | int main(){ 17 | return (ififElse()); 18 | } 19 | -------------------------------------------------------------------------------- /testcases/functional/23_if_test4.out: -------------------------------------------------------------------------------- 1 | 25 2 | -------------------------------------------------------------------------------- /testcases/functional/23_if_test4.sy: -------------------------------------------------------------------------------- 1 | // test if-{if-else} 2 | int if_ifElse_() { 3 | int a; 4 | a = 5; 5 | int b; 6 | b = 10; 7 | if(a == 5){ 8 | if (b == 10) 9 | a = 25; 10 | else 11 | a = a + 15; 12 | } 13 | return (a); 14 | } 15 | 16 | int main(){ 17 | return (if_ifElse_()); 18 | } 19 | -------------------------------------------------------------------------------- /testcases/functional/24_if_test5.out: -------------------------------------------------------------------------------- 1 | 25 2 | -------------------------------------------------------------------------------- /testcases/functional/24_if_test5.sy: -------------------------------------------------------------------------------- 1 | // test if-{if}-else 2 | int if_if_Else() { 3 | int a; 4 | a = 5; 5 | int b; 6 | b = 10; 7 | if(a == 5){ 8 | if (b == 10) 9 | a = 25; 10 | } 11 | else 12 | a = a + 15; 13 | return (a); 14 | } 15 | 16 | int main(){ 17 | return (if_if_Else()); 18 | } 19 | -------------------------------------------------------------------------------- /testcases/functional/25_while_if.out: -------------------------------------------------------------------------------- 1 | 88 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/25_while_if.sy: -------------------------------------------------------------------------------- 1 | int get_one(int a) { 2 | return 1; 3 | } 4 | 5 | int deepWhileBr(int a, int b) { 6 | int c; 7 | c = a + b; 8 | while (c < 75) { 9 | int d; 10 | d = 42; 11 | if (c < 100) { 12 | c = c + d; 13 | if (c > 99) { 14 | int e; 15 | e = d * 2; 16 | if (get_one(0) == 1) { 17 | c = e * 2; 18 | } 19 | } 20 | } 21 | } 22 | return (c); 23 | } 24 | 25 | int main() { 26 | int p; 27 | p = 2; 28 | p = deepWhileBr(p, p); 29 | putint(p); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /testcases/functional/26_while_test1.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testcases/functional/26_while_test1.sy: -------------------------------------------------------------------------------- 1 | int doubleWhile() { 2 | int i; 3 | i = 5; 4 | int j; 5 | j = 7; 6 | while (i < 100) { 7 | i = i + 30; 8 | while(j < 100){ 9 | j = j + 6; 10 | } 11 | j = j - 100; 12 | } 13 | return (j); 14 | } 15 | 16 | int main() { 17 | return doubleWhile(); 18 | } 19 | -------------------------------------------------------------------------------- /testcases/functional/27_while_test2.out: -------------------------------------------------------------------------------- 1 | 54 2 | -------------------------------------------------------------------------------- /testcases/functional/27_while_test2.sy: -------------------------------------------------------------------------------- 1 | int FourWhile() { 2 | int a; 3 | a = 5; 4 | int b; 5 | int c; 6 | b = 6; 7 | c = 7; 8 | int d; 9 | d = 10; 10 | while (a < 20) { 11 | a = a + 3; 12 | while(b < 10){ 13 | b = b + 1; 14 | while(c == 7){ 15 | c = c - 1; 16 | while(d < 20){ 17 | d = d + 3; 18 | } 19 | d = d - 1; 20 | } 21 | c = c + 1; 22 | } 23 | b = b - 2; 24 | } 25 | 26 | return (a + (b + d) + c); 27 | } 28 | 29 | int main() { 30 | return FourWhile(); 31 | } 32 | -------------------------------------------------------------------------------- /testcases/functional/28_while_test3.out: -------------------------------------------------------------------------------- 1 | 23 2 | -------------------------------------------------------------------------------- /testcases/functional/28_while_test3.sy: -------------------------------------------------------------------------------- 1 | int g; 2 | int h; 3 | int f; 4 | int e; 5 | int EightWhile() { 6 | int a; 7 | a = 5; 8 | int b; 9 | int c; 10 | b = 6; 11 | c = 7; 12 | int d; 13 | d = 10; 14 | while (a < 20) { 15 | a = a + 3; 16 | while(b < 10){ 17 | b = b + 1; 18 | while(c == 7){ 19 | c = c - 1; 20 | while(d < 20){ 21 | d = d + 3; 22 | while(e > 1){ 23 | e = e-1; 24 | while(f > 2){ 25 | f = f -2; 26 | while(g < 3){ 27 | g = g +10; 28 | while(h < 10){ 29 | h = h + 8; 30 | } 31 | h = h-1; 32 | } 33 | g = g- 8; 34 | } 35 | f = f + 1; 36 | } 37 | e = e + 1; 38 | } 39 | d = d - 1; 40 | } 41 | c = c + 1; 42 | } 43 | b = b - 2; 44 | } 45 | 46 | return (a + (b + d) + c)-(e + d - g + h); 47 | } 48 | 49 | int main() { 50 | g = 1; 51 | h = 2; 52 | e = 4; 53 | f = 6; 54 | return EightWhile(); 55 | } 56 | -------------------------------------------------------------------------------- /testcases/functional/29_break.out: -------------------------------------------------------------------------------- 1 | 201 2 | -------------------------------------------------------------------------------- /testcases/functional/29_break.sy: -------------------------------------------------------------------------------- 1 | //test break 2 | int main(){ 3 | int i; 4 | i = 0; 5 | int sum; 6 | sum = 0; 7 | while(i < 100){ 8 | if(i == 50){ 9 | break; 10 | } 11 | sum = sum + i; 12 | i = i + 1; 13 | } 14 | return sum; 15 | } -------------------------------------------------------------------------------- /testcases/functional/30_continue.out: -------------------------------------------------------------------------------- 1 | 36 2 | -------------------------------------------------------------------------------- /testcases/functional/30_continue.sy: -------------------------------------------------------------------------------- 1 | //test continue 2 | int main(){ 3 | int i; 4 | i = 0; 5 | int sum; 6 | sum = 0; 7 | while(i < 100){ 8 | if(i == 50){ 9 | i = i + 1; 10 | continue; 11 | } 12 | sum = sum + i; 13 | i = i + 1; 14 | } 15 | return sum; 16 | } -------------------------------------------------------------------------------- /testcases/functional/31_while_if_test1.out: -------------------------------------------------------------------------------- 1 | 198 2 | -------------------------------------------------------------------------------- /testcases/functional/31_while_if_test1.sy: -------------------------------------------------------------------------------- 1 | // test while-if 2 | int whileIf() { 3 | int a; 4 | a = 0; 5 | int b; 6 | b = 0; 7 | while (a < 100) { 8 | if (a == 5) { 9 | b = 25; 10 | } 11 | else if (a == 10) { 12 | b = 42; 13 | } 14 | else { 15 | b = a * 2; 16 | } 17 | a = a + 1; 18 | } 19 | return (b); 20 | } 21 | 22 | 23 | int main(){ 24 | return (whileIf()); 25 | } 26 | -------------------------------------------------------------------------------- /testcases/functional/32_while_if_test2.out: -------------------------------------------------------------------------------- 1 | 96 2 | -------------------------------------------------------------------------------- /testcases/functional/32_while_if_test2.sy: -------------------------------------------------------------------------------- 1 | int ifWhile() { 2 | int a; 3 | a = 0; 4 | int b; 5 | b = 3; 6 | if (a == 5) { 7 | while(b == 2){ 8 | b = b + 2; 9 | } 10 | b = b + 25; 11 | } 12 | else 13 | while (a < 5) { 14 | b = b * 2; 15 | a = a + 1; 16 | } 17 | return (b); 18 | } 19 | 20 | 21 | int main(){ 22 | return (ifWhile()); 23 | } 24 | -------------------------------------------------------------------------------- /testcases/functional/33_while_if_test3.out: -------------------------------------------------------------------------------- 1 | 88 2 | -------------------------------------------------------------------------------- /testcases/functional/33_while_if_test3.sy: -------------------------------------------------------------------------------- 1 | int deepWhileBr(int a, int b) { 2 | int c; 3 | c = a + b; 4 | while (c < 75) { 5 | int d; 6 | d = 42; 7 | if (c < 100) { 8 | c = c + d; 9 | if (c > 99) { 10 | int e; 11 | e = d * 2; 12 | if (1 == 1) { 13 | c = e * 2; 14 | } 15 | } 16 | } 17 | } 18 | return (c); 19 | } 20 | 21 | int main() { 22 | int p; 23 | p = 2; 24 | return deepWhileBr(p, p); 25 | } 26 | -------------------------------------------------------------------------------- /testcases/functional/34_arr_expr_len.out: -------------------------------------------------------------------------------- 1 | 51 2 | -------------------------------------------------------------------------------- /testcases/functional/34_arr_expr_len.sy: -------------------------------------------------------------------------------- 1 | const int N = -1; 2 | int arr[N + 2 * 4 - 99 / 99] = {1, 2, 33, 4, 5, 6}; 3 | 4 | int main() { 5 | int i = 0, sum = 0; 6 | while (i < 6) { 7 | sum = sum + arr[i]; 8 | i = i + 1; 9 | } 10 | return sum; 11 | } 12 | -------------------------------------------------------------------------------- /testcases/functional/35_op_priority1.out: -------------------------------------------------------------------------------- 1 | 40 2 | -------------------------------------------------------------------------------- /testcases/functional/35_op_priority1.sy: -------------------------------------------------------------------------------- 1 | //test the priority of add and mul 2 | int main(){ 3 | int a, b, c, d; 4 | a = 10; 5 | b = 4; 6 | c = 2; 7 | d = 2; 8 | return c + a * b - d; 9 | } -------------------------------------------------------------------------------- /testcases/functional/36_op_priority2.out: -------------------------------------------------------------------------------- 1 | 24 2 | -------------------------------------------------------------------------------- /testcases/functional/36_op_priority2.sy: -------------------------------------------------------------------------------- 1 | //test the priority of add and mul 2 | int main(){ 3 | int a, b, c, d; 4 | a = 10; 5 | b = 4; 6 | c = 2; 7 | d = 2; 8 | return (c + a) * (b - d); 9 | } -------------------------------------------------------------------------------- /testcases/functional/37_op_priority3.out: -------------------------------------------------------------------------------- 1 | 40 2 | -------------------------------------------------------------------------------- /testcases/functional/37_op_priority3.sy: -------------------------------------------------------------------------------- 1 | //test the priority of unary operator and binary operator 2 | int main(){ 3 | int a, b; 4 | a = 10; 5 | b = 30; 6 | return a - -5 + b + -5; 7 | } -------------------------------------------------------------------------------- /testcases/functional/38_op_priority4.in: -------------------------------------------------------------------------------- 1 | 0 1 1 1 1 2 | -------------------------------------------------------------------------------- /testcases/functional/38_op_priority4.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testcases/functional/38_op_priority4.sy: -------------------------------------------------------------------------------- 1 | int a; 2 | int b; 3 | int c; 4 | int d; 5 | int e; 6 | int main() 7 | { 8 | a=getint(); 9 | b=getint(); 10 | c=getint(); 11 | d=getint(); 12 | e=getint(); 13 | int flag=0; 14 | if(a-b*c!=d-a/c||a*b/c==e+d||a+b+c==d+e) 15 | { 16 | flag=1; 17 | } 18 | return flag; 19 | } 20 | -------------------------------------------------------------------------------- /testcases/functional/39_op_priority5.out: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | -------------------------------------------------------------------------------- /testcases/functional/39_op_priority5.sy: -------------------------------------------------------------------------------- 1 | int a = 1; 2 | int b = 0; 3 | int c = 1; 4 | int d = 2; 5 | int e = 4; 6 | int main() 7 | { 8 | int flag=0; 9 | if(a * b / c == e + d && a * (a + b) + c <= d + e || a - (b * c) == d - a / c) 10 | { 11 | flag=1; 12 | } 13 | putint(flag); 14 | return flag; 15 | } -------------------------------------------------------------------------------- /testcases/functional/40_unary_op.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testcases/functional/40_unary_op.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a; 3 | a = 10; 4 | if (+-!!!a) { 5 | a = - - -1; 6 | } 7 | else { 8 | a = 0; 9 | } 10 | return a; 11 | } -------------------------------------------------------------------------------- /testcases/functional/41_unary_op2.out: -------------------------------------------------------------------------------- 1 | 4 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/41_unary_op2.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a, b; 3 | a = 070; 4 | b = 0x4; 5 | a = a - - 4 + + b; 6 | if (+-!!!a) { 7 | a = - - -1; 8 | } 9 | else { 10 | a = 0 + + b; 11 | } 12 | putint(a); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /testcases/functional/42_empty_stmt.out: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /testcases/functional/42_empty_stmt.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 10; 3 | ; 4 | return a * 2 + 1; 5 | } 6 | -------------------------------------------------------------------------------- /testcases/functional/43_logi_assign.in: -------------------------------------------------------------------------------- 1 | 4 4 2 | -------------------------------------------------------------------------------- /testcases/functional/43_logi_assign.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /testcases/functional/43_logi_assign.sy: -------------------------------------------------------------------------------- 1 | int a; 2 | int b; 3 | int main() 4 | { 5 | a=getint(); 6 | b=getint(); 7 | int c; 8 | if (a==b&&a!=3) { 9 | c = 1; 10 | } 11 | else { 12 | c = 0; 13 | } 14 | return c; 15 | } 16 | -------------------------------------------------------------------------------- /testcases/functional/44_stmt_expr.out: -------------------------------------------------------------------------------- 1 | 1024 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/44_stmt_expr.sy: -------------------------------------------------------------------------------- 1 | int k; 2 | const int n = 10; 3 | int main () { 4 | int i = 0; 5 | k = 1; 6 | while (i <= n - 1) { 7 | i = i + 1; 8 | k + 1; 9 | k = k + k; 10 | } 11 | putint(k); 12 | return k; 13 | } 14 | -------------------------------------------------------------------------------- /testcases/functional/45_comment1.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testcases/functional/45_comment1.sy: -------------------------------------------------------------------------------- 1 | //test comment 2 | int main(){ 3 | int a; 4 | a = 5; 5 | //int b = 4; 6 | //a = b + a; 7 | /*/* 8 | b = 1; 9 | // b = 2 10 | */ 11 | return a; 12 | } -------------------------------------------------------------------------------- /testcases/functional/46_hex_defn.out: -------------------------------------------------------------------------------- 1 | 15 2 | -------------------------------------------------------------------------------- /testcases/functional/46_hex_defn.sy: -------------------------------------------------------------------------------- 1 | // test hexadecimal define 2 | int main(){ 3 | int a; 4 | a = 0xf; 5 | return a; 6 | } -------------------------------------------------------------------------------- /testcases/functional/47_hex_oct_add.out: -------------------------------------------------------------------------------- 1 | 88 2 | -------------------------------------------------------------------------------- /testcases/functional/47_hex_oct_add.sy: -------------------------------------------------------------------------------- 1 | //test add of hex and oct 2 | int main(){ 3 | int a, b; 4 | a = 0xf; 5 | b = 0xc; 6 | return a + b + 075; 7 | } -------------------------------------------------------------------------------- /testcases/functional/48_assign_complex_expr.out: -------------------------------------------------------------------------------- 1 | -171 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/48_assign_complex_expr.sy: -------------------------------------------------------------------------------- 1 | // Use complex expression in assign structure 2 | int main () { 3 | int a; 4 | int b; 5 | int c; 6 | int d; 7 | int result; 8 | a = 5; 9 | b = 5; 10 | c = 1; 11 | d = -2; 12 | result = (d * 1 / 2) + (a - b) - -(c + 3) % 2; 13 | putint(result); 14 | result = ((d % 2 + 67) + -(a - b) - -((c + 2) % 2)); 15 | result = result + 3; 16 | putint(result); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /testcases/functional/49_if_complex_expr.out: -------------------------------------------------------------------------------- 1 | 2 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/49_if_complex_expr.sy: -------------------------------------------------------------------------------- 1 | // Use complex expression in if structure 2 | int main () { 3 | int a; 4 | int b; 5 | int c; 6 | int d; 7 | int result; 8 | a = 5; 9 | b = 5; 10 | c = 1; 11 | d = -2; 12 | result = 2; 13 | if ((d * 1 / 2) < 0 || (a - b) != 0 && (c + 3) % 2 != 0) { 14 | putint(result); 15 | } 16 | if ((d % 2 + 67) < 0 || (a - b) != 0 && (c + 2) % 2 != 0) { 17 | result = 4; 18 | putint(result); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /testcases/functional/50_short_circuit.in: -------------------------------------------------------------------------------- 1 | 11 2 | 10 3 | 100 4 | 99 -------------------------------------------------------------------------------- /testcases/functional/50_short_circuit.out: -------------------------------------------------------------------------------- 1 | 11111210 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/50_short_circuit.sy: -------------------------------------------------------------------------------- 1 | int g = 0; 2 | 3 | int func(int n) { 4 | g = g + n; 5 | putint(g); 6 | return g; 7 | } 8 | 9 | int main() { 10 | int i; 11 | i = getint(); 12 | if (i > 10 && func(i)) i = 1; else i = 0; 13 | i = getint(); 14 | if (i > 11 && func(i)) i = 1; else i = 0; 15 | i = getint(); 16 | if (i <= 99 || func(i)) i = 1; else i = 0; 17 | i = getint(); 18 | if (i <= 100 || func(i)) i = 1; else i = 0; 19 | if (!func(99) && func(100)) i = 1; else i = 0; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /testcases/functional/51_short_circuit3.out: -------------------------------------------------------------------------------- 1 | 0 3 0 3 2 | 3 3 3 | ADF 4 | CIJK 5 | 0 6 | -------------------------------------------------------------------------------- /testcases/functional/52_scope.out: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/52_scope.sy: -------------------------------------------------------------------------------- 1 | int a = 7; 2 | 3 | int func() { 4 | int b = a; 5 | int a = 1; 6 | if (a == b) { 7 | a = a + 1; 8 | return 1; 9 | } 10 | else 11 | return 0; 12 | } 13 | 14 | int main() { 15 | int result = 0; 16 | int i = 0; 17 | while (i < 100) { 18 | if (func() == 1) 19 | result = result + 1; 20 | i = i + 1; 21 | } 22 | if (result < 100) 23 | putint(1); 24 | else 25 | putint(0); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /testcases/functional/53_scope2.out: -------------------------------------------------------------------------------- 1 | -40 2 | 62 3 | -------------------------------------------------------------------------------- /testcases/functional/53_scope2.sy: -------------------------------------------------------------------------------- 1 | int k; 2 | 3 | int main() { 4 | k = 3389; 5 | if (k < 10000) { 6 | k = k + 1; 7 | int k = 112; 8 | while (k > 10) { 9 | k = k - 88; 10 | if (k < 1000) { 11 | int g = 9; 12 | { 13 | int l = 11; 14 | { 15 | g = 10; 16 | k = k - g; 17 | int g = 11; 18 | k = k + g + l; 19 | } 20 | } 21 | } 22 | } 23 | putint(k); 24 | } 25 | return k; 26 | } 27 | -------------------------------------------------------------------------------- /testcases/functional/54_hidden_var.out: -------------------------------------------------------------------------------- 1 | 331 2 | 1 3 | 218 4 | 5 5 | 6719 6 | 0 7 | -------------------------------------------------------------------------------- /testcases/functional/54_hidden_var.sy: -------------------------------------------------------------------------------- 1 | 2 | int b = 5; 3 | int c[4] = {6, 7, 8, 9}; 4 | 5 | int main() 6 | { 7 | int a; 8 | a = 1; 9 | { 10 | int a; 11 | a = 2; 12 | { 13 | a = 3; 14 | putint(a); 15 | } 16 | putint(a); 17 | } 18 | putint(a); putch(10); 19 | 20 | while (a < 5) { 21 | int a = 0; 22 | a = a + 1; 23 | if (a) 24 | break; 25 | } 26 | putint(a); putch(10); 27 | 28 | { 29 | { 30 | { 31 | {} 32 | } 33 | c[2] = 1; 34 | { 35 | int c[2][8] = {{0, 9}, 8, 3}; 36 | } 37 | } 38 | } 39 | 40 | { 41 | int b = 2; 42 | if (c[2]) { 43 | int c[7][1][5] = {{}, {}, {2, 1, 8}, {{}}}; 44 | putint(c[b][0][0]); 45 | putint(c[b][0][1]); 46 | putint(c[b][0][2]); 47 | } 48 | } 49 | putch(10); 50 | 51 | putint(b); putch(10); 52 | putint(c[0]); putint(c[1]); putint(c[2]); putint(c[3]); putch(10); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /testcases/functional/55_sort_test1.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | 0 12 | -------------------------------------------------------------------------------- /testcases/functional/55_sort_test1.sy: -------------------------------------------------------------------------------- 1 | int n; 2 | int bubblesort(int arr[]) 3 | { 4 | int i; 5 | int j; 6 | i =0; 7 | while(i < n-1){ 8 | // Last i elements are already in place 9 | j = 0; 10 | while(j < n-i-1){ 11 | if (arr[j] > arr[j+1]) { 12 | // swap(&arr[j], &arr[j+1]); 13 | int tmp; 14 | tmp = arr[j+1]; 15 | arr[j+1] = arr[j]; 16 | arr[j] = tmp; 17 | } 18 | j = j + 1; 19 | } 20 | i = i + 1; 21 | } 22 | return 0; 23 | } 24 | 25 | int main(){ 26 | n = 10; 27 | int a[10]; 28 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 29 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 30 | int i; 31 | i = bubblesort(a); 32 | while (i < n) { 33 | int tmp; 34 | tmp = a[i]; 35 | putint(tmp); 36 | tmp = 10; 37 | putch(tmp); 38 | i = i + 1; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /testcases/functional/56_sort_test2.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | 0 12 | -------------------------------------------------------------------------------- /testcases/functional/56_sort_test2.sy: -------------------------------------------------------------------------------- 1 | int n; 2 | int insertsort(int a[]) 3 | { 4 | int i; 5 | i = 1; 6 | while(i-1&&tempA[j]) 15 | { 16 | min=j; 17 | } 18 | j=j+1; 19 | } 20 | if(min!=i) 21 | { 22 | int tmp; 23 | tmp = A[min]; 24 | A[min] = A[i]; 25 | A[i] = tmp; 26 | } 27 | i = i + 1; 28 | } 29 | return 0; 30 | } 31 | 32 | int main(){ 33 | n = 10; 34 | int a[10]; 35 | a[0]=4;a[1]=3;a[2]=9;a[3]=2;a[4]=0; 36 | a[5]=1;a[6]=6;a[7]=5;a[8]=7;a[9]=8; 37 | int i; 38 | i = 0; 39 | i = select_sort(a, n); 40 | while (i < n) { 41 | int tmp; 42 | tmp = a[i]; 43 | putint(tmp); 44 | tmp = 10; 45 | putch(tmp); 46 | i = i + 1; 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /testcases/functional/59_sort_test5.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | 0 12 | -------------------------------------------------------------------------------- /testcases/functional/60_sort_test6.out: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | 0 12 | -------------------------------------------------------------------------------- /testcases/functional/61_sort_test7.in: -------------------------------------------------------------------------------- 1 | 97 2 | -10525 -9882 48155 -22162 -38879 52218 -44913 14799 -52541 19859 3 | 23040 38767 -39850 -2221 -63865 51868 64903 -3812 -58581 -14684 4 | -29113 12117 -32032 -58451 -59283 -24783 -10753 -18185 28370 7266 5 | 760 30956 -35818 -52888 -37486 21562 14967 53534 46231 -46019 6 | -46994 -62145 24886 18009 63111 -14203 40779 51479 36163 14992 7 | 57399 -58381 5335 -38236 4245 -33049 33608 -63687 37320 -32676 8 | 6602 40444 1715 11292 2406 16023 1996 -60066 -52763 -16559 9 | 53676 22077 57606 46802 -2033 -64412 -58092 61266 59389 -38805 10 | 1155 59786 35700 52562 9161 -2723 -57451 46501 -2730 38395 11 | -2556 -38481 52802 -47314 -21799 -18640 60818 12 | -------------------------------------------------------------------------------- /testcases/functional/61_sort_test7.out: -------------------------------------------------------------------------------- 1 | 97: -64412 -63865 -63687 -62145 -60066 -59283 -58581 -58451 -58381 -58092 -57451 -52888 -52763 -52541 -47314 -46994 -46019 -44913 -39850 -38879 -38805 -38481 -38236 -37486 -35818 -33049 -32676 -32032 -29113 -24783 -22162 -21799 -18640 -18185 -16559 -14684 -14203 -10753 -10525 -9882 -3812 -2730 -2723 -2556 -2221 -2033 760 1155 1715 1996 2406 4245 5335 6602 7266 9161 11292 12117 14799 14967 14992 16023 18009 19859 21562 22077 23040 24886 28370 30956 33608 35700 36163 37320 38395 38767 40444 40779 46231 46501 46802 48155 51479 51868 52218 52562 52802 53534 53676 57399 57606 59389 59786 60818 61266 63111 64903 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/61_sort_test7.sy: -------------------------------------------------------------------------------- 1 | int buf[2][100]; 2 | 3 | // sort [l, r) 4 | void merge_sort(int l, int r) 5 | { 6 | if (l + 1 >= r) 7 | return; 8 | 9 | int mid = (l + r) / 2; 10 | merge_sort(l, mid); 11 | merge_sort(mid, r); 12 | 13 | int i = l, j = mid, k = l; 14 | while (i < mid && j < r) { 15 | if (buf[0][i] < buf[0][j]) { 16 | buf[1][k] = buf[0][i]; 17 | i = i + 1; 18 | } else { 19 | buf[1][k] = buf[0][j]; 20 | j = j + 1; 21 | } 22 | k = k + 1; 23 | } 24 | while (i < mid) { 25 | buf[1][k] = buf[0][i]; 26 | i = i + 1; 27 | k = k + 1; 28 | } 29 | while (j < r) { 30 | buf[1][k] = buf[0][j]; 31 | j = j + 1; 32 | k = k + 1; 33 | } 34 | 35 | while (l < r) { 36 | buf[0][l] = buf[1][l]; 37 | l = l + 1; 38 | } 39 | } 40 | 41 | int main() 42 | { 43 | int n = getarray(buf[0]); 44 | merge_sort(0, n); 45 | putarray(n, buf[0]); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /testcases/functional/62_percolation.in: -------------------------------------------------------------------------------- 1 | 2 2 2 | 3 1 3 | 4 2 4 | 4 4 5 | 1 2 6 | 2 3 7 | 2 1 8 | 3 2 9 | 3 4 10 | 3 1 11 | -------------------------------------------------------------------------------- /testcases/functional/62_percolation.out: -------------------------------------------------------------------------------- 1 | 8 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/63_big_int_mul.out: -------------------------------------------------------------------------------- 1 | 3102343761271952753654505476597868729361003112012671299112096683775968059149440439438030623917912792644636180 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/64_calculator.in: -------------------------------------------------------------------------------- 1 | (4 - (3 - 5) * 2 + 100) % (2^3 - 1) / 2 + 1 2 | -------------------------------------------------------------------------------- /testcases/functional/64_calculator.out: -------------------------------------------------------------------------------- 1 | 2 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/65_color.in: -------------------------------------------------------------------------------- 1 | 5 2 | 2 2 2 2 2 -------------------------------------------------------------------------------- /testcases/functional/65_color.out: -------------------------------------------------------------------------------- 1 | 39480 2 | 56 3 | -------------------------------------------------------------------------------- /testcases/functional/66_exgcd.out: -------------------------------------------------------------------------------- 1 | 13 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/66_exgcd.sy: -------------------------------------------------------------------------------- 1 | int exgcd(int a,int b,int x[],int y[]) { 2 | if(b == 0) { 3 | x[0] = 1; 4 | y[0] = 0; 5 | return a; 6 | } 7 | else { 8 | int r = exgcd(b, a % b, x, y); 9 | int t = x[0]; 10 | x[0] = y[0]; 11 | y[0] = (t - a / b * y[0]); 12 | return r; 13 | } 14 | } 15 | 16 | int main() { 17 | int a = 7, b = 15, x[1] = {1}, y[1] = {1}; 18 | exgcd(a, b, x, y); 19 | x[0] = (x[0] % b + b) % b; 20 | putint(x[0]); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /testcases/functional/67_reverse_output.out: -------------------------------------------------------------------------------- 1 | 5975945915885855825795765735705675645615585555525495465435405375345315285255225195165135105075045014984954924894864834804774744714684654624594564534504474444414384354324294264234204174144114084054023993963933903873843813783753723693663633603573543513483453423393363333303273243213183153123093063033002972942912882852822792762732702672642612582552522492462432402372342312282252222192162132102072042011981951921891861831801771741711681651621591561531501471441411381351321291261231201171141111081051029996939087848178757269666360575451484542393633302724211815129630 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/67_reverse_output.sy: -------------------------------------------------------------------------------- 1 | void reverse(int n) { 2 | int next; 3 | if (n <= 1) { 4 | next=getint(); 5 | putint(next); 6 | } 7 | else { 8 | next=getint(); 9 | reverse(n-1); 10 | putint(next); 11 | } 12 | } 13 | 14 | int main() { 15 | int i=200; 16 | reverse(i); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /testcases/functional/68_brainfk.out: -------------------------------------------------------------------------------- 1 | I'm Suzumiya Haruhi from the East Junior High School, and I'm not interested in ordinary humans. If there were an alien, a time traveller, an otherworlder or a superhero among you, please come to meet me! That's all. 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/69_expr_eval.in: -------------------------------------------------------------------------------- 1 | 5 2 | 1+2* 3/4- 2 *411 ; 3 | 0 -1+10*1329000/ 22219 +99 ; 4 | 1199+ 98888/2227 %112-23; 5 | * 2; 6 | ; 7 | -------------------------------------------------------------------------------- /testcases/functional/69_expr_eval.out: -------------------------------------------------------------------------------- 1 | -820 2 | 696 3 | 1220 4 | panic! 5 | -1 6 | panic! 7 | -1 8 | 0 9 | -------------------------------------------------------------------------------- /testcases/functional/70_dijkstra.in: -------------------------------------------------------------------------------- 1 | 6 9 2 | 1 2 1 3 | 2 3 9 4 | 1 3 12 5 | 2 4 3 6 | 4 3 4 7 | 3 5 5 8 | 4 5 13 9 | 5 6 4 10 | 4 6 15 11 | -------------------------------------------------------------------------------- /testcases/functional/70_dijkstra.out: -------------------------------------------------------------------------------- 1 | 0 1 8 4 13 17 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/71_full_conn.in: -------------------------------------------------------------------------------- 1 | 6 2 | 3 | 233 95 179 178 105 4 | 115 190 92 216 21 5 | 48 252 184 148 36 6 | 252 20 92 99 18 7 | 61 245 40 190 16 8 | 9 | 61 197 150 246 225 10 | 27 99 197 227 206 11 | 130 134 172 149 52 12 | 147 246 171 52 84 13 | 174 42 90 23 42 14 | 15 | 130 207 209 104 168 16 | 139 248 84 142 225 17 | 127 242 45 62 7 18 | 102 191 119 168 190 19 | 14 249 239 188 118 20 | 21 | 159 29 212 96 189 22 | 159 220 97 71 180 23 | 202 131 217 165 138 24 | 94 98 86 68 140 25 | 132 92 247 99 110 26 | 27 | 228 10 119 127 21 28 | 247 8 230 81 251 29 | 216 213 24 114 68 30 | 83 188 240 196 231 31 | 90 206 224 49 28 32 | 33 | 158 252 95 171 239 34 | 90 66 22 221 10 35 | 177 32 38 24 93 36 | 227 55 4 59 211 37 | 80 92 38 238 42 38 | -------------------------------------------------------------------------------- /testcases/functional/71_full_conn.out: -------------------------------------------------------------------------------- 1 | dog 2 | cat 3 | dog 4 | dog 5 | cat 6 | cat 7 | 0 8 | -------------------------------------------------------------------------------- /testcases/functional/72_hanoi.in: -------------------------------------------------------------------------------- 1 | 4 2 | 4 3 | 7 4 | 3 5 | 9 6 | -------------------------------------------------------------------------------- /testcases/functional/72_hanoi.sy: -------------------------------------------------------------------------------- 1 | 2 | void move(int x, int y) 3 | { 4 | putint(x); putch(32); putint(y); putch(44); putch(32); 5 | } 6 | 7 | void hanoi(int n, int one, int two, int three) 8 | { 9 | if (n == 1) 10 | move(one, three); 11 | else { 12 | hanoi(n - 1, one, three, two); 13 | move(one, three); 14 | hanoi(n - 1, two, one, three); 15 | } 16 | } 17 | 18 | int main() 19 | { 20 | int n = getint(); 21 | while (n > 0) { 22 | hanoi(getint(), 1, 2, 3); 23 | putch(10); 24 | n = n - 1; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /testcases/functional/73_int_io.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 4 | 4006571 5 | 6 | 9900 7 | 1504379 8 | 9 | 10 | 758219 11 | 99336677 12 | 13 | 14 | -------------------------------------------------------------------------------- /testcases/functional/73_int_io.out: -------------------------------------------------------------------------------- 1 | 4006571 2 | 9900 3 | 1504379 4 | 758219 5 | 99336677 6 | 0 7 | -------------------------------------------------------------------------------- /testcases/functional/73_int_io.sy: -------------------------------------------------------------------------------- 1 | const int ascii_0 = 48; 2 | 3 | int my_getint() 4 | { 5 | int sum = 0, c; 6 | 7 | while (1) { 8 | c = getch() - ascii_0; 9 | if (c < 0 || c > 9) { 10 | continue; 11 | } else { 12 | break; 13 | } 14 | } 15 | sum = c; 16 | 17 | while (1) { 18 | c = getch() - ascii_0; 19 | if (c >= 0 && c <= 9) { 20 | sum = sum * 10 + c; 21 | } else { 22 | break; 23 | } 24 | } 25 | 26 | return sum; 27 | } 28 | 29 | void my_putint(int a) 30 | { 31 | int b[16], i = 0; 32 | while (a > 0) { 33 | b[i] = a % 10 + ascii_0; 34 | a = a / 10; 35 | i = i + 1; 36 | } 37 | while (i > 0) { 38 | i = i - 1; 39 | putch(b[i]); 40 | } 41 | } 42 | 43 | int main() 44 | { 45 | int n = my_getint(); 46 | while (n > 0) { 47 | int m = my_getint(); 48 | my_putint(m); putch(10); 49 | n = n - 1; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /testcases/functional/74_kmp.in: -------------------------------------------------------------------------------- 1 | abcabdbca 2 | aababcabdabdababcabdbcadceadbcababcdcbaabsbda 3 | -------------------------------------------------------------------------------- /testcases/functional/74_kmp.out: -------------------------------------------------------------------------------- 1 | 23 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/75_max_flow.in: -------------------------------------------------------------------------------- 1 | 7 11 2 | 1 6 22 3 | 1 3 10 4 | 1 4 56 5 | 3 7 15 6 | 3 5 11 7 | 5 7 45 8 | 4 5 100 9 | 6 3 34 10 | 2 3 9 11 | 6 7 68 12 | 6 2 6 13 | -------------------------------------------------------------------------------- /testcases/functional/75_max_flow.out: -------------------------------------------------------------------------------- 1 | 77 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/76_n_queens.in: -------------------------------------------------------------------------------- 1 | 4 2 | 1 5 6 8 3 | -------------------------------------------------------------------------------- /testcases/functional/76_n_queens.sy: -------------------------------------------------------------------------------- 1 | int ans[50], sum = 0, n; 2 | 3 | int row[50], line1[50], line2[100]; 4 | 5 | void printans() 6 | { 7 | sum = sum + 1; 8 | int i = 1; 9 | while (i <= n) { 10 | putint(ans[i]); 11 | if (i == n) { 12 | putch(10); 13 | return; 14 | } else 15 | putch(32); 16 | i = i + 1; 17 | } 18 | } 19 | 20 | void f(int step) 21 | { 22 | int i = 1; 23 | while (i <= n) { 24 | if (row[i] != 1 && line1[step + i] == 0 && !line2[n + step - i]) { 25 | ans[step] = i; 26 | if (step == n) 27 | printans(); 28 | row[i] = 1; 29 | line1[step + i] = 1; 30 | line2[n + step - i] = 1; 31 | f(step + 1); 32 | row[i] = 0; 33 | line1[step + i] = 0; 34 | line2[n + step - i] = 0; 35 | } 36 | i = i + 1; 37 | } 38 | } 39 | 40 | int main() 41 | { 42 | int N = getint(); 43 | while (N > 0) { 44 | n = getint(); 45 | f(1); 46 | N = N - 1; 47 | } 48 | return sum; 49 | } 50 | -------------------------------------------------------------------------------- /testcases/functional/77_substr.out: -------------------------------------------------------------------------------- 1 | 43 2 | 6 3 | 0 4 | -------------------------------------------------------------------------------- /testcases/functional/78_side_effect.out: -------------------------------------------------------------------------------- 1 | 1 2 | 4 2 3 | 5 4 | 8 4 5 | 9 6 | 12 8 7 | 13 8 | 16 16 9 | 24 16 10 | 29 16 11 | 29 12 | -------------------------------------------------------------------------------- /testcases/functional/78_side_effect.sy: -------------------------------------------------------------------------------- 1 | 2 | int a = -1, b = 1; 3 | 4 | int inc_a() 5 | { 6 | int b = a; 7 | b = b + 1; 8 | a = b; 9 | return a; 10 | } 11 | 12 | int main() 13 | { 14 | int k = 5; 15 | while (k >= 0) { 16 | if (inc_a() && inc_a() && inc_a()) { 17 | putint(a); putch(32); putint(b); putch(10); 18 | } 19 | if (inc_a() < 14 || inc_a() && inc_a() - inc_a() + 1) { 20 | putint(a); putch(10); 21 | b = b * 2; 22 | } else { 23 | inc_a(); 24 | } 25 | k = k - 1; 26 | } 27 | putint(a); putch(32); putint(b); putch(10); 28 | return a; 29 | } 30 | -------------------------------------------------------------------------------- /testcases/functional/79_var_name.out: -------------------------------------------------------------------------------- 1 | 3 2 | 5 3 | 8 4 | 13 5 | 21 6 | 34 7 | 55 8 | 89 9 | 144 10 | 233 11 | 377 12 | 610 13 | 987 14 | 1597 15 | 2584 16 | 4181 17 | 6765 18 | 10946 19 | 236 20 | -------------------------------------------------------------------------------- /testcases/functional/80_chaos_token.out: -------------------------------------------------------------------------------- 1 | Welcome to the Japari Park! 2 | Araiguma says hello to Tairiku Ookami 3 | Tairiku Ookami says hello to Saabaru 4 | Araiguma says hello to Kaban 5 | Hunboruto Pengin says hello to Hashibirokou 6 | Hashibirokou says hello to Tairiku Ookami 7 | Hunboruto Pengin says hello to Saabaru 8 | Hashibirokou says hello to Araiguma 9 | Araiguma says hello to Hunboruto Pengin 10 | Hashibirokou says hello to Kaban 11 | Araiguma says hello to Hashibirokou 12 | Kaban says hello to Tairiku Ookami 13 | Araiguma says hello to Saabaru 14 | Kaban says hello to Araiguma 15 | Hashibirokou says hello to Hunboruto Pengin 16 | Saabaru says hello to Tairiku Ookami 17 | Hashibirokou says hello to Saabaru 18 | Saabaru says hello to Araiguma 19 | Kaban says hello to Hunboruto Pengin 20 | Saabaru says hello to Kaban 21 | Kaban says hello to Hashibirokou 22 | Tairiku Ookami says hello to Kaban 23 | Kaban says hello to Saabaru 24 | Hunboruto Pengin says hello to Tairiku Ookami 25 | Saabaru says hello to Hunboruto Pengin 26 | Hunboruto Pengin says hello to Araiguma 27 | Saabaru says hello to Hashibirokou 28 | Hunboruto Pengin says hello to Kaban 29 | 0 30 | -------------------------------------------------------------------------------- /testcases/functional/81_skip_spaces.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 9 10 2 | 11 12 13 14 15 16 17 18 19 20 3 | 23 233 2333 23333 233333 0 0 4 | -------------------------------------------------------------------------------- /testcases/functional/81_skip_spaces.out: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /testcases/functional/81_skip_spaces.sy: -------------------------------------------------------------------------------- 1 | // ??? // ???? 2 | // ????? 3 | /* 4 | 5 | int main() { 6 | int arr[100], i = 0, sum = 0; 7 | while (getint()) { 8 | arr[i] = getint(); 9 | i = i + 1; 10 | }*/ 11 | int main() { 12 | int arr[100], i = 0, sum = 0; 13 | while (getint()) { 14 | arr[i] = getint(); 15 | i = i + 1; 16 | } 17 | while (i) { 18 | i = i - 1; 19 | sum = sum + arr[i]; 20 | } 21 | return sum % 79; 22 | } -------------------------------------------------------------------------------- /testcases/functional/82_long_func.out: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 4 4 | 8 5 | 16 6 | 32 7 | 64 8 | 128 9 | 256 10 | 512 11 | 1024 12 | 2048 13 | 4096 14 | 8192 15 | 16384 16 | 32768 17 | 0 18 | -------------------------------------------------------------------------------- /testcases/functional/83_long_array.out: -------------------------------------------------------------------------------- 1 | 02425294124166176216218-22282-34782142718170218357718485218672718700218877718865218842718825218832718815218822718825218832718815218822718805218 2 | 216 3 | -------------------------------------------------------------------------------- /testcases/functional/84_long_array2.out: -------------------------------------------------------------------------------- 1 | 3 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/84_long_array2.sy: -------------------------------------------------------------------------------- 1 | int a[4096]; 2 | 3 | int f1(int b[]) 4 | { 5 | a[5] = 4000; 6 | a[4000] = 3; 7 | a[4095] = 7; 8 | b[a[4095]] = a[2216] + 9; 9 | return a[a[5]]; 10 | } 11 | 12 | int main() 13 | { 14 | int b[4][1024] = {{}, {1}, {2, 3}, {4, 5, 6}}; 15 | int c[1024][4] = {{1, 2}, {3, 4}}; 16 | putint(f1(c[0])); 17 | putch(10); 18 | return c[2][0]; 19 | } -------------------------------------------------------------------------------- /testcases/functional/85_long_code.out: -------------------------------------------------------------------------------- 1 | 7238926282254275832735749053546579352646394592968929756452279588796363928129015723262728293639586883878996254264273279282290354452459574639657756905929935175115723262728293639586883878996254264273279282290354452459574639657756905929935157232627282936395868838789962542642732792822903544524595746396577569059299351572326272829363958688387899625426427327928229035445245957463965775690592993500014500056800018350002210000119500024160002770003581016102157158658902805545816096195895834243461553125546824662331115043274-77600 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/86_long_code2.out: -------------------------------------------------------------------------------- 1 | 160 2 | -------------------------------------------------------------------------------- /testcases/functional/87_many_params.in: -------------------------------------------------------------------------------- 1 | 17 2 | 13 3 | 80 4 | 55 5 | 81 6 | 91 7 | 95 8 | 58 9 | 13 10 | 5 11 | 63 12 | 19 13 | 54 14 | 45 15 | 67 16 | 63 17 | -------------------------------------------------------------------------------- /testcases/functional/87_many_params.out: -------------------------------------------------------------------------------- 1 | 331024 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/88_many_params2.out: -------------------------------------------------------------------------------- 1 | 0123000009 2 | 9 3 | 805 3612 2695 1778 861 3668 2751 1834 917 0 4 | 0 5 | -------------------------------------------------------------------------------- /testcases/functional/88_many_params2.sy: -------------------------------------------------------------------------------- 1 | 2 | int func(int a, int b[][59], int c, int d[], int e, int f, int g[], int h, int i) 3 | { 4 | int index = 0; 5 | while (index < 10) { 6 | putint(b[a][index]); 7 | index = index + 1; 8 | } 9 | putch(10); 10 | 11 | putint(d[c]); 12 | putch(10); 13 | 14 | while (i < 10) { 15 | g[i] = h * 128875 % 3724; 16 | i = i + 1; 17 | h = h + 7; 18 | } 19 | 20 | return e + f; 21 | } 22 | 23 | int main() 24 | { 25 | int a[61][67] = {}; 26 | int b[53][59] = {}; 27 | 28 | a[17][1] = 6; 29 | a[17][3] = 7; 30 | a[17][4] = 4; 31 | a[17][7] = 9; 32 | a[17][11] = 11; 33 | 34 | b[6][1] = 1; 35 | b[6][2] = 2; 36 | b[6][3] = 3; 37 | b[6][9] = 9; 38 | 39 | int ret; 40 | ret = func(a[17][1], b, a[17][3], a[17], b[6][3], b[6][0], b[6], b[34][4], b[51][18]) * 3; 41 | 42 | while (ret >= 0) { 43 | putint(b[6][ret]); putch(32); 44 | ret = ret - 1; 45 | } 46 | putch(10); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /testcases/functional/89_many_globals.out: -------------------------------------------------------------------------------- 1 | 2822118 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/90_many_locals.out: -------------------------------------------------------------------------------- 1 | 254 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/functional/90_many_locals.sy: -------------------------------------------------------------------------------- 1 | 2 | int foo() 3 | { 4 | int arr[16] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3}; 5 | 6 | int a = 3, b = 7, c = 5, d = 6, e = 1, f = 0, g = 3, h = 5, 7 | i = 4, j = 2, k = 7, l = 9, m = 8, n = 1, o = 4, p = 6; 8 | 9 | int sum1 = a + b + c + d + e + f + g + h; 10 | int sum2 = i + j + k + l + m + n + o + p; 11 | 12 | return sum1 + sum2 + arr[a]; 13 | } 14 | 15 | int main() 16 | { 17 | int a = 3, b = 7, c = 5, d = 6, e = 1, f = 0, g = 3, h = 5, 18 | i = 4, j = 2, k = 7, l = 9, m = 8, n = 1, o = 4, p = 6; 19 | 20 | int sum1 = a + b + c + d + e + f + g + h; 21 | int sum2 = i + j + k + l + m + n + o + p; 22 | 23 | sum1 = sum1 + foo(); 24 | 25 | int q = 4, r = 7, s = 2, t = 5, u = 8, v = 0, w = 6, x = 3; 26 | 27 | sum2 = sum2 + foo(); 28 | 29 | a = i; b = j; c = k; d = l; 30 | e = m; f = n; g = o; h = p; 31 | 32 | int sum3 = q + r + s + t + u + v + w + x; 33 | 34 | int sum = sum1 + sum2 + sum3; 35 | 36 | putint(sum); 37 | putch(10); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /testcases/functional/91_many_locals2.in: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testcases/functional/91_many_locals2.out: -------------------------------------------------------------------------------- 1 | 01234567891011121314151617181920212223242526272829 2 | 6 3 | 25 4 | -------------------------------------------------------------------------------- /testcases/functional/92_register_alloc.in: -------------------------------------------------------------------------------- 1 | 1 2 | 1 2 3 4 3 | -------------------------------------------------------------------------------- /testcases/functional/92_register_alloc.out: -------------------------------------------------------------------------------- 1 | 194 2 | 194 3 | -------------------------------------------------------------------------------- /testcases/functional/93_nested_calls.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 4 | -------------------------------------------------------------------------------- /testcases/functional/93_nested_calls.out: -------------------------------------------------------------------------------- 1 | 250 2 | -------------------------------------------------------------------------------- /testcases/functional/94_nested_loops.in: -------------------------------------------------------------------------------- 1 | 12 10 2 | 2 2 3 2 3 2 2 3 | -------------------------------------------------------------------------------- /testcases/functional/94_nested_loops.out: -------------------------------------------------------------------------------- 1 | 38 2 | -------------------------------------------------------------------------------- /testcases/functional/95_float.in: -------------------------------------------------------------------------------- 1 | 10 2 | 0x1.999999999999ap-4 0x1.999999999999ap-3 0x1.3333333333333p-2 0x1.999999999999ap-2 0x1.0000000000000p-1 3 | 0x1.3333333333333p-1 0x1.6666666666666p-1 0x1.999999999999ap-1 0x1.ccccccccccccdp-1 0x1.0000000000000p+0 4 | 0x1.199999999999ap+0 5 | 0x1.199999999999ap+1 6 | 0x1.a666666666666p+1 7 | 0x1.199999999999ap+2 8 | 0x1.6000000000000p+2 9 | 0x1.a666666666666p+2 10 | 0x1.ecccccccccccdp+2 11 | 0x1.199999999999ap+3 12 | 0x1.3cccccccccccdp+3 13 | 0x1.4333333333333p+3 14 | -------------------------------------------------------------------------------- /testcases/functional/95_float.out: -------------------------------------------------------------------------------- 1 | ok 2 | ok 3 | ok 4 | ok 5 | ok 6 | ok 7 | ok 8 | ok 9 | 0x1.e691e6p+1 3 10 | 0x1.e691e6p+3 12 11 | 0x1.11b21p+5 28 12 | 0x1.e691e6p+5 50 13 | 0x1.7c21fcp+6 78 14 | 0x1.11b21p+7 113 15 | 0x1.7487b2p+7 153 16 | 0x1.e691e6p+7 201 17 | 0x1.33e85p+8 254 18 | 10: 0x1.333334p+0 0x1.333334p+1 0x1.ccccccp+1 0x1.333334p+2 0x1.8p+2 0x1.ccccccp+2 0x1.0cccccp+3 0x1.333334p+3 0x1.599998p+3 0x1p+0 19 | 0 20 | -------------------------------------------------------------------------------- /testcases/functional/96_matrix_add.out: -------------------------------------------------------------------------------- 1 | 024 2 | 024 3 | 024 4 | 0 5 | -------------------------------------------------------------------------------- /testcases/functional/97_matrix_sub.out: -------------------------------------------------------------------------------- 1 | 000 2 | 000 3 | 000 4 | 0 5 | -------------------------------------------------------------------------------- /testcases/functional/98_matrix_mul.out: -------------------------------------------------------------------------------- 1 | 036 2 | 036 3 | 036 4 | 0 5 | -------------------------------------------------------------------------------- /testcases/functional/99_matrix_tran.out: -------------------------------------------------------------------------------- 1 | 000 2 | 111 3 | 222 4 | 0 5 | -------------------------------------------------------------------------------- /testcases/hidden_functional/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/helesta-compiler/helesta/245d1291093a873c41712af98911724828c3e1c9/testcases/hidden_functional/.gitkeep -------------------------------------------------------------------------------- /testcases/hidden_functional/00_comment2.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/00_comment2.sy: -------------------------------------------------------------------------------- 1 | /*/skipher/*/ 2 | //int main(){ 3 | int main(){ 4 | ////return 0;}/* 5 | /*} 6 | //}return 1;*/ 7 | //}return 2;*//* 8 | return 3; 9 | //*/ 10 | } 11 | // -------------------------------------------------------------------------------- /testcases/hidden_functional/01_multiple_returns.out: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/01_multiple_returns.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a, b = 8, c = 12; 3 | a = b + c; 4 | return a; 5 | int d = 9; 6 | a = a * d; 7 | return a; 8 | const int A = 4; 9 | a = (A - b) * c; 10 | return a; 11 | return a; 12 | } -------------------------------------------------------------------------------- /testcases/hidden_functional/02_ret_in_block.out: -------------------------------------------------------------------------------- 1 | 11 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/02_ret_in_block.sy: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int a = 893; 3 | int b = 716; 4 | { 5 | int a = 837; 6 | a = a + 128; 7 | b = b + a; 8 | { 9 | int b = 241; 10 | a = a + b - 412; 11 | { 12 | int a = 771; 13 | b = b + a -18; 14 | a = b + 66; 15 | } 16 | b = b + a - 33; 17 | a = b - 55; 18 | { 19 | return (a + b) % 21; 20 | } 21 | 22 | } 23 | a = b + a - 97; 24 | b = (b - a) % 62; 25 | { 26 | return (a + b) % 17; 27 | } 28 | return (a + b) % 13; 29 | } 30 | a = (b * a) % 83; 31 | b = a + b - 771; 32 | return (a + b) % 11; 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /testcases/hidden_functional/03_branch.out: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/03_branch.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | const int a = 1; 3 | const int b = 2; 4 | const int c = 3; 5 | const int d = 4; 6 | const int e = 5; 7 | const int f = 6; 8 | if (a * b + c < 6 && d != 0) { 9 | if (e || !a + 0) { 10 | if (c == 2 && d + e > 2) return 3; 11 | else { 12 | if (f % c && e) return 4; 13 | else { 14 | if (d / b + a >= 2) { 15 | if (e - f >= 0 || d > 4) return 6; 16 | else { 17 | if (c != f) { 18 | if (b + e * d > 10) { 19 | if (!f) return 9; 20 | else return 10; 21 | } 22 | else return 8; 23 | } 24 | else return 7; 25 | } 26 | } 27 | else return 5; 28 | } 29 | } 30 | } 31 | else return 2; 32 | } 33 | else return 1; 34 | } -------------------------------------------------------------------------------- /testcases/hidden_functional/04_break_continue.out: -------------------------------------------------------------------------------- 1 | 208 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/04_break_continue.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | int sum = 0; 3 | int i = 0; 4 | while(i < 20) { 5 | int j = 0; 6 | while (j < 10) { 7 | int k = 0; 8 | while (k < 5) { 9 | int m = 0; 10 | while (m < 3) { 11 | if (m + 1 >= 3) 12 | if (m) 13 | if (m || !m) 14 | if (m - -1 >= 3) 15 | {{{{;;break;continue;}}}} 16 | int n = 0; 17 | while (n < 2) { 18 | n = n + 1; 19 | continue; 20 | break; 21 | sum = sum + 1; 22 | } 23 | m = m + 1; 24 | sum = sum + 1; 25 | } 26 | while(1) { 27 | while(1) break; 28 | break; 29 | } 30 | k = k + 1; 31 | } 32 | j = j + 1; 33 | continue; 34 | j = j + 1; 35 | } 36 | i = i + 1; 37 | } 38 | return sum; 39 | } -------------------------------------------------------------------------------- /testcases/hidden_functional/05_param_name.out: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/05_param_name.sy: -------------------------------------------------------------------------------- 1 | int f(int f) { 2 | return f * 2; 3 | } 4 | 5 | int main() { 6 | return f(10); 7 | } 8 | -------------------------------------------------------------------------------- /testcases/hidden_functional/06_func_name.out: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/06_func_name.sy: -------------------------------------------------------------------------------- 1 | int f() { 2 | return 10; 3 | } 4 | 5 | int main() { 6 | int f = 20; 7 | return f; 8 | } 9 | -------------------------------------------------------------------------------- /testcases/hidden_functional/07_arr_init_nd.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/07_arr_init_nd.sy: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a[5][3]; 3 | int b[5][3] = {}; 4 | int c[5][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 5 | int d[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}, 6 | e[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, 10, 11, 12, 13, 14, 15}; 7 | int f[5], g[5][3] = {1, 2, 3, {4}, {7}, 10, 11, 12}, h[3]; 8 | int i[2][3][4] = {1, 2, 3, 4, {5}, {}}; 9 | return 4; 10 | } 11 | -------------------------------------------------------------------------------- /testcases/hidden_functional/08_global_arr_init.out: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/08_global_arr_init.sy: -------------------------------------------------------------------------------- 1 | int a0[3] = {}; 2 | int b0[4] = {0, 1}; 3 | int c0[7] = {2, 8, 6, 3, 9, 1, 5}; 4 | int d0[11]; 5 | int e0[2] = {22, 33}, f0[6], g0[9] = {85, 0, 1, 29}; 6 | 7 | int a[5][3]; 8 | int b[5][3] = {}; 9 | int c[5][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 10 | int d[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}, 11 | e[5][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, 10, 11, 12, 13, 14, 15}; 12 | int f[5], g[5][3] = {1, 2, 3, {4}, {7}, 10, 11, 12}, h[3]; 13 | int i[2][3][4] = {1, 2, 3, 4, {5}, {}}; 14 | 15 | int main() { 16 | return 5; 17 | } 18 | -------------------------------------------------------------------------------- /testcases/hidden_functional/11_BST.out: -------------------------------------------------------------------------------- 1 | 0 1 3 4 4 4 9 9 10 11 11 12 13 14 14 15 16 18 18 19 22 22 22 25 25 30 34 34 34 35 35 35 40 41 42 44 45 45 46 47 48 48 50 50 51 54 54 55 56 59 60 60 61 61 61 62 63 63 65 66 67 68 69 72 73 74 74 76 77 78 78 79 79 79 79 80 80 82 82 85 85 87 88 88 90 90 91 91 92 92 92 94 94 96 96 96 98 98 99 99 2 | 0 1 4 4 4 9 9 10 11 11 12 13 14 15 16 18 18 19 22 22 22 25 25 30 34 34 34 35 35 40 41 42 44 45 45 46 47 48 48 50 50 51 54 54 59 60 60 61 61 61 63 65 66 67 68 69 72 73 74 74 76 77 78 78 79 79 79 79 80 82 82 85 85 87 88 88 90 90 92 92 92 94 94 96 96 96 98 98 99 99 3 | 0 4 | -------------------------------------------------------------------------------- /testcases/hidden_functional/12_DSU.sy: -------------------------------------------------------------------------------- 1 | int quick_read(){ 2 | int ch = getch(); int x = 0, f = 0; 3 | while (ch < 48 || ch > 57){ 4 | if (ch == 45) f = 1; 5 | ch = getch(); 6 | } 7 | while (ch >= 48 && ch <=57){ 8 | x = x * 10 + ch - 48; 9 | ch = getch(); 10 | } 11 | if (f) return -x; 12 | else return x; 13 | } 14 | int n, m, fa[100005]; 15 | void init(){ 16 | int i = 1; 17 | while (i <= n){ 18 | fa[i] = i; 19 | i = i + 1; 20 | } 21 | } 22 | int find(int x){ 23 | if (fa[x] == x) return x; 24 | else{ 25 | int pa = find(fa[x]); 26 | fa[x] = pa; 27 | return pa; 28 | } 29 | } 30 | int same(int x, int y){ 31 | if (find(x) == find(y)) return 1; 32 | return 0; 33 | } 34 | int main(){ 35 | n = quick_read(); m = quick_read(); 36 | init(); 37 | while (m){ 38 | int ch = getch(); 39 | while (ch != 81 && ch != 85){ 40 | ch = getch(); 41 | } 42 | if (ch == 81){ // query 43 | int x = quick_read(), y = quick_read(); 44 | putint(same(x, y)); 45 | putch(10); 46 | }else{ // union 47 | int x = find(quick_read()), y = find(quick_read()); 48 | fa[x] = y; 49 | } 50 | m = m - 1; 51 | } 52 | return 0; 53 | } -------------------------------------------------------------------------------- /testcases/hidden_functional/14_dp.in: -------------------------------------------------------------------------------- 1 | 7 2 2 | 2 3 | 1 4 | 1 5 | 2 6 | 2 7 | 1 8 | 1 -------------------------------------------------------------------------------- /testcases/hidden_functional/14_dp.out: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/14_dp.sy: -------------------------------------------------------------------------------- 1 | int t[1005][2] = { 0 }, dp[1005][35] = { 0 }; 2 | int main() 3 | { 4 | int T, W, x, i, j; 5 | T = getint(); 6 | W = getint(); 7 | i = 1; 8 | while (i <= T) { 9 | x = getint(); 10 | t[i][x % 2] = 1; 11 | dp[i][0] = dp[i - 1][0] + t[i][1]; 12 | i = i + 1; 13 | } 14 | 15 | i = 1; 16 | while (i <= T) { 17 | j = 1; 18 | while (j <= W) { 19 | if (dp[i - 1][j] + t[i][(j + 1) % 2] > dp[i - 1][j - 1] + t[i][(j + 1) % 2]) { 20 | dp[i][j] = dp[i - 1][j] + t[i][(j + 1) % 2]; 21 | } 22 | else { 23 | dp[i][j] = dp[i - 1][j - 1] + t[i][(j + 1) % 2]; 24 | } 25 | j = j + 1; 26 | } 27 | i = i + 1; 28 | } 29 | 30 | int res = 0; 31 | j = 0; 32 | while (j <= W) { 33 | if (res < dp[T][j]) { 34 | res = dp[T][j]; 35 | } 36 | j = j + 1; 37 | } 38 | 39 | return res; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /testcases/hidden_functional/15_graph_coloring.out: -------------------------------------------------------------------------------- 1 | 1 2 3 2 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/16_k_smallest.in: -------------------------------------------------------------------------------- 1 | 12 5 2 | 11 3 2 1 15 5 4 45 88 96 50 45 -------------------------------------------------------------------------------- /testcases/hidden_functional/16_k_smallest.out: -------------------------------------------------------------------------------- 1 | 3 2 1 4 5 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/17_maximal_clique.in: -------------------------------------------------------------------------------- 1 | 20 27 2 | 13 5 3 | 3 18 4 | 3 20 5 | 11 1 6 | 5 14 7 | 7 9 8 | 20 19 9 | 13 16 10 | 12 20 11 | 7 5 12 | 18 2 13 | 11 14 14 | 11 6 15 | 1 13 16 | 1 10 17 | 3 17 18 | 3 1 19 | 8 12 20 | 12 20 21 | 9 2 22 | 6 10 23 | 19 15 24 | 18 11 25 | 19 12 26 | 6 20 27 | 18 2 28 | 20 16 29 | -------------------------------------------------------------------------------- /testcases/hidden_functional/17_maximal_clique.out: -------------------------------------------------------------------------------- 1 | 3 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/18_prim.out: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/19_search.in: -------------------------------------------------------------------------------- 1 | 2 1 2 | 3 2 3 | 6 6 4 | 1 0 0 2 1 0 5 | 1 1 0 0 0 0 6 | 0 0 0 0 0 3 7 | 0 0 0 0 0 0 8 | 1 0 0 0 0 1 9 | 0 1 1 1 1 1 10 | 6 1 11 | 1 1 2 1 1 3 12 | 6 1 13 | 1 0 2 1 1 3 14 | 12 1 15 | 2 0 1 1 1 1 1 1 1 1 1 3 16 | 13 1 17 | 2 0 1 1 1 1 1 1 1 1 1 1 3 18 | 0 0 -------------------------------------------------------------------------------- /testcases/hidden_functional/19_search.out: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | -1 4 | 4 5 | 10 6 | -1 7 | 0 8 | -------------------------------------------------------------------------------- /testcases/hidden_functional/20_sort.out: -------------------------------------------------------------------------------- 1 | 133 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/21_union_find.in: -------------------------------------------------------------------------------- 1 | 20 27 2 | 13 5 3 | 3 18 4 | 3 20 5 | 11 1 6 | 5 14 7 | 7 9 8 | 20 19 9 | 13 16 10 | 12 20 11 | 7 5 12 | 18 2 13 | 11 14 14 | 11 6 15 | 1 13 16 | 1 10 17 | 3 17 18 | 3 1 19 | 8 12 20 | 12 20 21 | 9 2 22 | 6 10 23 | 19 15 24 | 18 11 25 | 19 12 26 | 6 20 27 | 18 2 28 | 20 16 29 | -------------------------------------------------------------------------------- /testcases/hidden_functional/21_union_find.out: -------------------------------------------------------------------------------- 1 | 2 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/21_union_find.sy: -------------------------------------------------------------------------------- 1 | const int maxN = 1005; 2 | int parent[maxN]; 3 | 4 | int find(int root) { 5 | if (parent[root] == root) 6 | return root; 7 | else { 8 | parent[root] = find(parent[root]); 9 | return parent[root]; 10 | } 11 | } 12 | 13 | void merge(int p, int q) { 14 | int root_p, root_q; 15 | root_p = find(p); 16 | root_q = find(q); 17 | if (root_p != root_q) { 18 | parent[root_q] = root_p; 19 | } 20 | return; 21 | } 22 | 23 | int main() { 24 | int n = getint(), m = getint(), i; 25 | int p, q; 26 | i = 0; 27 | while (i < n) { 28 | parent[i] = i; 29 | i = i + 1; 30 | } 31 | i = 0; 32 | while (i < m) { 33 | p = getint(); 34 | q = getint(); 35 | merge(p, q); 36 | i = i + 1; 37 | } 38 | 39 | int clusters = 0; 40 | i = 0; 41 | while (i < n) { 42 | if (parent[i] == i) clusters = clusters + 1; 43 | i = i + 1; 44 | } 45 | putint(clusters); 46 | return 0; 47 | } -------------------------------------------------------------------------------- /testcases/hidden_functional/22_matrix_multiply.in: -------------------------------------------------------------------------------- 1 | 4 4 2 | 1 2 3 4 3 | 5 6 7 8 4 | 9 10 11 12 5 | 13 14 15 16 6 | 4 3 7 | 9 5 1 8 | 10 6 2 9 | 11 7 3 10 | 12 8 4 -------------------------------------------------------------------------------- /testcases/hidden_functional/22_matrix_multiply.out: -------------------------------------------------------------------------------- 1 | 110 70 30 2 | 278 174 70 3 | 446 278 110 4 | 614 382 150 5 | 0 6 | -------------------------------------------------------------------------------- /testcases/hidden_functional/23_json.out: -------------------------------------------------------------------------------- 1 | ok 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/24_array_only.in: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 2 0 10 4 | -------------------------------------------------------------------------------- /testcases/hidden_functional/24_array_only.out: -------------------------------------------------------------------------------- 1 | 00100110021003100410101011101210131014102010211022102310241030103110321033103410401041104210431044105010511052105310541060106110621063106410701071107210731074108010811082108310841090109110921093109410 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/25_scope3.out: -------------------------------------------------------------------------------- 1 | a 2 | 46 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/25_scope3.sy: -------------------------------------------------------------------------------- 1 | int main() { /* scope test */ putch(97); putch(10); int a = 1, putch = 0; { a = a + 2; int b = a + 3; b = b + 4; putch = putch + a + b; { b = b + 5; int main = b + 6; a = a + main; putch = putch + a + b + main; { b = b + a; int a = main + 7; a = a + 8; putch = putch + a + b + main; { b = b + a; int b = main + 9; a = a + 10; const int a = 11; b = b + 12; putch = putch + a + b + main; { main = main + b; int main = b + 13; main = main + a; putch = putch + a + b + main; } putch = putch - main; } putch = putch - b; } putch = putch - a; } } return putch % 77; } -------------------------------------------------------------------------------- /testcases/hidden_functional/26_scope4.out: -------------------------------------------------------------------------------- 1 | 4474 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/27_scope5.out: -------------------------------------------------------------------------------- 1 | 109 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/28_side_effect2.out: -------------------------------------------------------------------------------- 1 | 701 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/29_long_line.out: -------------------------------------------------------------------------------- 1 | fib(1) = 1 2 | fib(2) = 1 3 | fib(3) = 2 4 | fib(4) = 3 5 | fib(5) = 5 6 | fib(6) = 8 7 | fib(7) = 13 8 | fib(8) = 21 9 | fib(9) = 34 10 | fib(10) = 55 11 | fib(11) = 89 12 | fib(12) = 144 13 | fib(13) = 233 14 | fib(14) = 377 15 | fib(15) = 610 16 | fib(16) = 987 17 | fib(17) = 1597 18 | fib(18) = 2584 19 | fib(19) = 4181 20 | fib(20) = 6765 21 | 0 22 | -------------------------------------------------------------------------------- /testcases/hidden_functional/30_many_dimensions.out: -------------------------------------------------------------------------------- 1 | 351799 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/31_many_indirections.out: -------------------------------------------------------------------------------- 1 | 79 2 | 0 3 | -------------------------------------------------------------------------------- /testcases/hidden_functional/31_many_indirections.sy: -------------------------------------------------------------------------------- 1 | const int N = 100; 2 | const int M = 20; 3 | int array[M][N]; 4 | 5 | int main() { 6 | int i = 0, sum = 0; 7 | while (i < M) { 8 | int j = 0; 9 | while (j < N) { 10 | array[i][j] = j; 11 | j = j + 1; 12 | } 13 | i = i + 1; 14 | } 15 | sum = 16 | array[0][array[1][array[2][array[3][array[4][array[5][array[6][array[7][array[8][ 17 | array[9][array[10][array[11][array[12][array[13][array[14][array[15][array[16][ 18 | array[17][array[18][array[19][23]]] 19 | ]]]]]]]] 20 | ]]]]]]]]] 21 | + 22 | array[array[array[array[array[array[array[array[array[array[array[array[array 23 | [array[array[array[array[array[array[array[19][18]] 24 | [17]][16]][15]][14]][13]][12]][11]][10]][9]][8]][7]] 25 | [6]][5]][4]][3]][2]][1]][0]][56]; 26 | putint(sum); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /testcases/hidden_functional/32_many_params3.out: -------------------------------------------------------------------------------- 1 | 133 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/33_multi_branch.in: -------------------------------------------------------------------------------- 1 | 101 2 | 0 3 | 1 4 | 2 5 | 3 6 | 4 7 | 5 8 | 6 9 | 7 10 | 8 11 | 9 12 | 10 13 | 11 14 | 12 15 | 13 16 | 14 17 | 15 18 | 16 19 | 17 20 | 18 21 | 19 22 | 20 23 | 21 24 | 22 25 | 23 26 | 24 27 | 25 28 | 26 29 | 27 30 | 28 31 | 29 32 | 30 33 | 31 34 | 32 35 | 33 36 | 34 37 | 35 38 | 36 39 | 37 40 | 38 41 | 39 42 | 40 43 | 41 44 | 42 45 | 43 46 | 44 47 | 45 48 | 46 49 | 47 50 | 48 51 | 49 52 | 50 53 | 51 54 | 52 55 | 53 56 | 54 57 | 55 58 | 56 59 | 57 60 | 58 61 | 59 62 | 60 63 | 61 64 | 62 65 | 63 66 | 64 67 | 65 68 | 66 69 | 67 70 | 68 71 | 69 72 | 70 73 | 71 74 | 72 75 | 73 76 | 74 77 | 75 78 | 76 79 | 77 80 | 78 81 | 79 82 | 80 83 | 81 84 | 82 85 | 83 86 | 84 87 | 85 88 | 86 89 | 87 90 | 88 91 | 89 92 | 90 93 | 91 94 | 92 95 | 93 96 | 94 97 | 95 98 | 96 99 | 97 100 | 98 101 | 99 102 | 100 -------------------------------------------------------------------------------- /testcases/hidden_functional/33_multi_branch.out: -------------------------------------------------------------------------------- 1 | 100 2 | 1 3 | 2 4 | 3 5 | 4 6 | 5 7 | 6 8 | 7 9 | 8 10 | 9 11 | 10 12 | 11 13 | 12 14 | 13 15 | 14 16 | 15 17 | 16 18 | 17 19 | 18 20 | 19 21 | 20 22 | 21 23 | 22 24 | 23 25 | 24 26 | 25 27 | 26 28 | 27 29 | 28 30 | 29 31 | 30 32 | 31 33 | 32 34 | 33 35 | 34 36 | 35 37 | 36 38 | 37 39 | 38 40 | 39 41 | 40 42 | 41 43 | 42 44 | 43 45 | 44 46 | 45 47 | 46 48 | 47 49 | 48 50 | 49 51 | 50 52 | 51 53 | 52 54 | 53 55 | 54 56 | 55 57 | 56 58 | 57 59 | 58 60 | 59 61 | 60 62 | 61 63 | 62 64 | 63 65 | 64 66 | 65 67 | 66 68 | 67 69 | 68 70 | 69 71 | 70 72 | 71 73 | 72 74 | 73 75 | 74 76 | 75 77 | 76 78 | 77 79 | 78 80 | 79 81 | 80 82 | 81 83 | 82 84 | 83 85 | 84 86 | 85 87 | 86 88 | 87 89 | 88 90 | 89 91 | 90 92 | 91 93 | 92 94 | 93 95 | 94 96 | 95 97 | 96 98 | 97 99 | 98 100 | 99 101 | 100 102 | 0 103 | -------------------------------------------------------------------------------- /testcases/hidden_functional/34_multi_loop.out: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /testcases/hidden_functional/35_math.in: -------------------------------------------------------------------------------- 1 | 3 2 | 0x1.199999999999ap+0 0x1.a666666666666p+1 3 | -0x1.199999999999ap+1 0x1.199999999999ap+2 4 | 0x1.a666666666666p+1 -0x1.6000000000000p+2 5 | -------------------------------------------------------------------------------- /testcases/hidden_functional/35_math.out: -------------------------------------------------------------------------------- 1 | 0x1.19999ap+0 0x1.35c29p+0 0x1.0c7ebcp+0 0x1.8089d8p+1 0x1.8663fep-4 0x1.90dabep+3 0x1.5ea04ap+0 2 | 0x1.19999ap+1 0x1.35c29p+2 -0x1.241baep+4 0x1.c5d666p-4 - - - 3 | 0x1.a66666p+1 0x1.5c7aep+3 0x1.d10c0ep+0 0x1.b1c9f2p+4 0x1.31a4e8p+0 - 0x1.70c228p-10 4 | 0 5 | -------------------------------------------------------------------------------- /testcases/hidden_functional/37_dct.in: -------------------------------------------------------------------------------- 1 | 8 8 2 | 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 3 | 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 4 | 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 5 | 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 6 | 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 7 | 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 8 | 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 9 | 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 0x0.0p+0 0x1.fe00000000000p+7 10 | -------------------------------------------------------------------------------- /testcases/hidden_functional/39_fp_params.out: -------------------------------------------------------------------------------- 1 | 10: 0x1.aec9c2p+2 0x1.6187ep+2 0x1.6444fep+2 0x1.5dcf9ep+2 0x1.5d7f4cp+2 0x1.7ee688p+2 0x1.75af34p+2 0x1.870674p+2 0x1.75bafp+2 0x1.9b8604p+2 2 | 10: 0x1.aec9c2p+2 0x1.6187ep+2 0x1.6444fep+2 0x1.5dcf9ep+2 0x1.5d7f4cp+2 0x1.7ee688p+2 0x1.75af34p+2 0x1.870674p+2 0x1.75bafp+2 0x1.9b8604p+2 3 | 8: 7 5 6 5 5 6 9 8 4 | 10: 0x1.aec9c2p+2 0x1.6187ep+2 0x1.6444fep+2 0x1.5dcf9ep+2 0x1.5d7f4cp+2 0x1.7ee688p+2 0x1.75af34p+2 0x1.870674p+2 0x1.75bafp+2 0x1.9b8604p+2 5 | 10: 0x1.aec9c2p+2 0x1.6187ep+2 0x1.6444fep+2 0x1.5dcf9ep+2 0x1.5d7f4cp+2 0x1.7ee688p+2 0x1.75af34p+2 0x1.870674p+2 0x1.75bafp+2 0x0p+0 6 | 10: 7 5 6 5 5 6 9 8 9 0 7 | 0x1.aec9c2p+2 8 | 0x0p+0 9 | 0x1.aec9c2p+2 10 | 0 11 | 0 12 | -------------------------------------------------------------------------------- /testcases/performance/04_spmv1.sy: -------------------------------------------------------------------------------- 1 | void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){ 2 | int i, j, k; 3 | i = 0; 4 | while (i < n){ 5 | x[i] = 0; 6 | i = i + 1; 7 | } 8 | 9 | i = 0; 10 | while (i < n){ 11 | j = xptr[i]; 12 | while (j < xptr[i + 1]){ 13 | x[yidx[j]] = x[yidx[j]] + vals[j]; 14 | j = j + 1; 15 | } 16 | 17 | j = xptr[i]; 18 | while (j < xptr[i + 1]){ 19 | x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1); 20 | j = j + 1; 21 | } 22 | i = i + 1; 23 | } 24 | } 25 | 26 | const int N = 100010; 27 | const int M = 3000000; 28 | 29 | int x[N], y[M], v[M]; 30 | int a[N], b[N], c[N]; 31 | 32 | int main(){ 33 | int n = getarray(x) - 1; 34 | int m = getarray(y); 35 | getarray(v); 36 | 37 | getarray(a); 38 | 39 | starttime(); 40 | 41 | int i = 0; 42 | while (i < 100){ 43 | spmv(n, x, y, v, a, b); 44 | spmv(n, x, y, v, b, a); 45 | i=i+1; 46 | } 47 | stoptime(); 48 | putarray(n, b); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /testcases/performance/04_spmv2.sy: -------------------------------------------------------------------------------- 1 | void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){ 2 | int i, j, k; 3 | i = 0; 4 | while (i < n){ 5 | x[i] = 0; 6 | i = i + 1; 7 | } 8 | 9 | i = 0; 10 | while (i < n){ 11 | j = xptr[i]; 12 | while (j < xptr[i + 1]){ 13 | x[yidx[j]] = x[yidx[j]] + vals[j]; 14 | j = j + 1; 15 | } 16 | 17 | j = xptr[i]; 18 | while (j < xptr[i + 1]){ 19 | x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1); 20 | j = j + 1; 21 | } 22 | i = i + 1; 23 | } 24 | } 25 | 26 | const int N = 100010; 27 | const int M = 3000000; 28 | 29 | int x[N], y[M], v[M]; 30 | int a[N], b[N], c[N]; 31 | 32 | int main(){ 33 | int n = getarray(x) - 1; 34 | int m = getarray(y); 35 | getarray(v); 36 | 37 | getarray(a); 38 | 39 | starttime(); 40 | 41 | int i = 0; 42 | while (i < 100){ 43 | spmv(n, x, y, v, a, b); 44 | spmv(n, x, y, v, b, a); 45 | i=i+1; 46 | } 47 | stoptime(); 48 | putarray(n, b); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /testcases/performance/04_spmv3.sy: -------------------------------------------------------------------------------- 1 | void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){ 2 | int i, j, k; 3 | i = 0; 4 | while (i < n){ 5 | x[i] = 0; 6 | i = i + 1; 7 | } 8 | 9 | i = 0; 10 | while (i < n){ 11 | j = xptr[i]; 12 | while (j < xptr[i + 1]){ 13 | x[yidx[j]] = x[yidx[j]] + vals[j]; 14 | j = j + 1; 15 | } 16 | 17 | j = xptr[i]; 18 | while (j < xptr[i + 1]){ 19 | x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1); 20 | j = j + 1; 21 | } 22 | i = i + 1; 23 | } 24 | } 25 | 26 | const int N = 100010; 27 | const int M = 3000000; 28 | 29 | int x[N], y[M], v[M]; 30 | int a[N], b[N], c[N]; 31 | 32 | int main(){ 33 | int n = getarray(x) - 1; 34 | int m = getarray(y); 35 | getarray(v); 36 | 37 | getarray(a); 38 | 39 | starttime(); 40 | 41 | int i = 0; 42 | while (i < 100){ 43 | spmv(n, x, y, v, a, b); 44 | spmv(n, x, y, v, b, a); 45 | i=i+1; 46 | } 47 | stoptime(); 48 | putarray(n, b); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorListener.h" 7 | 8 | antlr4::ANTLRErrorListener::~ANTLRErrorListener() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorStrategy.h" 7 | 8 | antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRFileStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | #include "ANTLRFileStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | ANTLRFileStream::ANTLRFileStream(const std::string &fileName) { 13 | _fileName = fileName; 14 | loadFromFile(fileName); 15 | } 16 | 17 | void ANTLRFileStream::loadFromFile(const std::string &fileName) { 18 | _fileName = fileName; 19 | if (_fileName.empty()) { 20 | return; 21 | } 22 | 23 | #ifdef _MSC_VER 24 | std::ifstream stream(antlrcpp::s2ws(fileName), std::ios::binary); 25 | #else 26 | std::ifstream stream(fileName, std::ios::binary); 27 | #endif 28 | 29 | ANTLRInputStream::load(stream); 30 | } 31 | 32 | std::string ANTLRFileStream::getSourceName() const { 33 | return _fileName; 34 | } 35 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ANTLRFileStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRInputStream.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// This is an ANTLRInputStream that is loaded from a file all at once 13 | /// when you construct the object (or call load()). 14 | // TODO: this class needs testing. 15 | class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { 16 | protected: 17 | std::string _fileName; // UTF-8 encoded file name. 18 | 19 | public: 20 | // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). 21 | ANTLRFileStream(const std::string &fileName); 22 | 23 | virtual void loadFromFile(const std::string &fileName); 24 | virtual std::string getSourceName() const override; 25 | }; 26 | 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/CharStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "CharStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | CharStream::~CharStream() { 11 | } 12 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/ConsoleErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ConsoleErrorListener.h" 7 | 8 | using namespace antlr4; 9 | 10 | ConsoleErrorListener ConsoleErrorListener::INSTANCE; 11 | 12 | void ConsoleErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 13 | size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) { 14 | std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InputMismatchException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "InputMismatchException.h" 9 | 10 | using namespace antlr4; 11 | 12 | InputMismatchException::InputMismatchException(Parser *recognizer) 13 | : RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(), 14 | recognizer->getCurrentToken()) { 15 | } 16 | 17 | InputMismatchException::~InputMismatchException() { 18 | } 19 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InputMismatchException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// 13 | /// This signifies any kind of mismatched input exceptions such as 14 | /// when the current input does not match the expected token. 15 | /// 16 | class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException { 17 | public: 18 | InputMismatchException(Parser *recognizer); 19 | InputMismatchException(InputMismatchException const&) = default; 20 | ~InputMismatchException(); 21 | InputMismatchException& operator=(InputMismatchException const&) = default; 22 | }; 23 | 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/IntStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "IntStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | const std::string IntStream::UNKNOWN_SOURCE_NAME = ""; 11 | 12 | IntStream::~IntStream() = default; 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/InterpreterRuleContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "InterpreterRuleContext.h" 7 | 8 | using namespace antlr4; 9 | 10 | InterpreterRuleContext::InterpreterRuleContext() : ParserRuleContext() { 11 | } 12 | 13 | InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex) 14 | : ParserRuleContext(parent, invokingStateNumber), _ruleIndex(ruleIndex) { 15 | } 16 | 17 | size_t InterpreterRuleContext::getRuleIndex() const { 18 | return _ruleIndex; 19 | } 20 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/LexerNoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "atn/ATNConfigSet.h" 10 | 11 | namespace antlr4 { 12 | 13 | class ANTLR4CPP_PUBLIC LexerNoViableAltException : public RecognitionException { 14 | public: 15 | LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs); 17 | 18 | virtual size_t getStartIndex(); 19 | virtual atn::ATNConfigSet* getDeadEndConfigs(); 20 | virtual std::string toString(); 21 | 22 | private: 23 | /// Matching attempted at what input index? 24 | const size_t _startIndex; 25 | 26 | /// Which configurations did we try at input.index() that couldn't match input.LA(1)? 27 | atn::ATNConfigSet *_deadEndConfigs; 28 | 29 | }; 30 | 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/RuleContextWithAltNum.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATN.h" 7 | 8 | #include "RuleContextWithAltNum.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() { 14 | altNum = ATN::INVALID_ALT_NUMBER; 15 | } 16 | 17 | RuleContextWithAltNum::RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber) 18 | : ParserRuleContext(parent, invokingStateNumber) { 19 | } 20 | 21 | size_t RuleContextWithAltNum::getAltNumber() const { 22 | return altNum; 23 | } 24 | 25 | void RuleContextWithAltNum::setAltNumber(size_t number) { 26 | altNum = number; 27 | } 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/RuleContextWithAltNum.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A handy class for use with 13 | /// 14 | /// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} 15 | /// 16 | /// that provides a backing field / impl for the outer alternative number 17 | /// matched for an internal parse tree node. 18 | /// 19 | /// I'm only putting into Java runtime as I'm certain I'm the only one that 20 | /// will really every use this. 21 | class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext { 22 | public: 23 | size_t altNum = 0; 24 | 25 | RuleContextWithAltNum(); 26 | RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber); 27 | 28 | virtual size_t getAltNumber() const override; 29 | virtual void setAltNumber(size_t altNum) override; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/Token.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | antlr4::Token::~Token() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/TokenSource.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenSource.h" 7 | 8 | antlr4::TokenSource::~TokenSource() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/TokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | TokenStream::~TokenStream() { 11 | } 12 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/WritableToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "WritableToken.h" 7 | 8 | antlr4::WritableToken::~WritableToken() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/WritableToken.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Token.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC WritableToken : public Token { 13 | public: 14 | virtual ~WritableToken(); 15 | virtual void setText(const std::string &text) = 0; 16 | virtual void setType(size_t ttype) = 0; 17 | virtual void setLine(size_t line) = 0; 18 | virtual void setCharPositionInLine(size_t pos) = 0; 19 | virtual void setChannel(size_t channel) = 0; 20 | virtual void setTokenIndex(size_t index) = 0; 21 | }; 22 | 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ATNType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Represents the type of recognizer an ATN applies to. 14 | enum class ATNType { 15 | LEXER = 0, 16 | PARSER = 1, 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AbstractPredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AbstractPredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | AbstractPredicateTransition::AbstractPredicateTransition(ATNState *target) : Transition(target) { 11 | } 12 | 13 | AbstractPredicateTransition::~AbstractPredicateTransition() { 14 | } 15 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AbstractPredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTState; 14 | 15 | class ANTLR4CPP_PUBLIC AbstractPredicateTransition : public Transition { 16 | 17 | public: 18 | AbstractPredicateTransition(ATNState *target); 19 | ~AbstractPredicateTransition(); 20 | 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ActionTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ActionTransition final : public Transition { 14 | public: 15 | const size_t ruleIndex; 16 | const size_t actionIndex; 17 | const bool isCtxDependent; // e.g., $i ref in action 18 | 19 | ActionTransition(ATNState *target, size_t ruleIndex); 20 | 21 | ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent); 22 | 23 | virtual SerializationType getSerializationType() const override; 24 | 25 | virtual bool isEpsilon() const override; 26 | 27 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 28 | 29 | virtual std::string toString() const override; 30 | }; 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AmbiguityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AmbiguityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | AmbiguityInfo::AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->ambigAlts = ambigAlts; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AtomTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/AtomTransition.h" 10 | 11 | using namespace antlr4::misc; 12 | using namespace antlr4::atn; 13 | 14 | AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) { 15 | } 16 | 17 | Transition::SerializationType AtomTransition::getSerializationType() const { 18 | return ATOM; 19 | } 20 | 21 | IntervalSet AtomTransition::label() const { 22 | return IntervalSet::of((int)_label); 23 | } 24 | 25 | bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 26 | return _label == symbol; 27 | } 28 | 29 | std::string AtomTransition::toString() const { 30 | return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }"; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/AtomTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// TODO: make all transitions sets? no, should remove set edges. 14 | class ANTLR4CPP_PUBLIC AtomTransition final : public Transition { 15 | public: 16 | /// The token type or character value; or, signifies special label. 17 | const size_t _label; 18 | 19 | AtomTransition(ATNState *target, size_t label); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicBlockStartState::getStateType() { 11 | return BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | #include "atn/BlockStartState.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC BasicBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicState::getStateType() { 11 | return BASIC; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BasicState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC BasicState final : public ATNState { 14 | 15 | public: 16 | virtual size_t getStateType() override; 17 | 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BlockEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | BlockEndState::BlockEndState() : startState(nullptr) { 11 | } 12 | 13 | size_t BlockEndState::getStateType() { 14 | return BLOCK_END; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Terminal node of a simple {@code (a|b|c)} block. 14 | class ANTLR4CPP_PUBLIC BlockEndState final : public ATNState { 15 | public: 16 | BlockStartState *startState = nullptr; 17 | 18 | BlockEndState(); 19 | 20 | virtual size_t getStateType() override; 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BlockStartState.h" 7 | 8 | antlr4::atn::BlockStartState::~BlockStartState() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/BlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The start of a regular {@code (...)} block. 14 | class ANTLR4CPP_PUBLIC BlockStartState : public DecisionState { 15 | public: 16 | ~BlockStartState(); 17 | BlockEndState *endState = nullptr; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ContextSensitivityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ContextSensitivityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | ContextSensitivityInfo::ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, 12 | size_t startIndex, size_t stopIndex) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, true) { 14 | } 15 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | DecisionEventInfo::DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, 12 | size_t stopIndex, bool fullCtx) 13 | : decision(decision), configs(configs), input(input), startIndex(startIndex), stopIndex(stopIndex), fullCtx(fullCtx) { 14 | } 15 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ErrorInfo.h" 7 | #include "atn/LookaheadEventInfo.h" 8 | 9 | #include "atn/DecisionInfo.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | DecisionInfo::DecisionInfo(size_t decision) : decision(decision) { 14 | } 15 | 16 | std::string DecisionInfo::toString() const { 17 | std::stringstream ss; 18 | 19 | ss << "{decision=" << decision << ", contextSensitivities=" << contextSensitivities.size() << ", errors="; 20 | ss << errors.size() << ", ambiguities=" << ambiguities.size() << ", SLL_lookahead=" << SLL_TotalLook; 21 | ss << ", SLL_ATNTransitions=" << SLL_ATNTransitions << ", SLL_DFATransitions=" << SLL_DFATransitions; 22 | ss << ", LL_Fallback=" << LL_Fallback << ", LL_lookahead=" << LL_TotalLook << ", LL_ATNTransitions=" << LL_ATNTransitions << '}'; 23 | 24 | return ss.str(); 25 | } 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | void DecisionState::InitializeInstanceFields() { 11 | decision = -1; 12 | nonGreedy = false; 13 | } 14 | 15 | std::string DecisionState::toString() const { 16 | return "DECISION " + ATNState::toString(); 17 | } 18 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/DecisionState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC DecisionState : public ATNState { 14 | public: 15 | int decision; 16 | bool nonGreedy; 17 | 18 | private: 19 | void InitializeInstanceFields(); 20 | 21 | public: 22 | DecisionState() { 23 | InitializeInstanceFields(); 24 | } 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/EmptyPredictionContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EmptyPredictionContext.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) { 11 | } 12 | 13 | bool EmptyPredictionContext::isEmpty() const { 14 | return true; 15 | } 16 | 17 | size_t EmptyPredictionContext::size() const { 18 | return 1; 19 | } 20 | 21 | Ref EmptyPredictionContext::getParent(size_t /*index*/) const { 22 | return nullptr; 23 | } 24 | 25 | size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const { 26 | return returnState; 27 | } 28 | 29 | bool EmptyPredictionContext::operator == (const PredictionContext &o) const { 30 | return this == &o; 31 | } 32 | 33 | std::string EmptyPredictionContext::toString() const { 34 | return "$"; 35 | } 36 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/EmptyPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SingletonPredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EmptyPredictionContext : public SingletonPredictionContext { 14 | public: 15 | EmptyPredictionContext(); 16 | 17 | virtual bool isEmpty() const override; 18 | virtual size_t size() const override; 19 | virtual Ref getParent(size_t index) const override; 20 | virtual size_t getReturnState(size_t index) const override; 21 | virtual std::string toString() const override; 22 | 23 | virtual bool operator == (const PredictionContext &o) const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/ErrorInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNConfigSet.h" 7 | 8 | #include "atn/ErrorInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | ErrorInfo::ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 14 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LexerAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "LexerAction.h" 7 | 8 | antlr4::atn::LexerAction::~LexerAction() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LookaheadEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LookaheadEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | LookaheadEventInfo::LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->predictedAlt = predictedAlt; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LoopEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LoopEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t LoopEndState::getStateType() { 11 | return LOOP_END; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/LoopEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Mark the end of a * or + loop. 14 | class ANTLR4CPP_PUBLIC LoopEndState final : public ATNState { 15 | public: 16 | ATNState *loopBackState = nullptr; 17 | 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/NotSetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/NotSetTransition.h" 7 | #include "atn/ATNState.h" 8 | #include "misc/IntervalSet.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) { 14 | } 15 | 16 | Transition::SerializationType NotSetTransition::getSerializationType() const { 17 | return NOT_SET; 18 | } 19 | 20 | bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 21 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 22 | && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol); 23 | } 24 | 25 | std::string NotSetTransition::toString() const { 26 | return "NOT_SET " + Transition::toString() + " { " + SetTransition::toString() + " }"; 27 | } 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/NotSetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SetTransition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC NotSetTransition final : public SetTransition { 14 | public: 15 | NotSetTransition(ATNState *target, const misc::IntervalSet &set); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/OrderedATNConfigSet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/OrderedATNConfigSet.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t OrderedATNConfigSet::getHash(ATNConfig *c) { 11 | return c->hashCode(); 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/OrderedATNConfigSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfigSet.h" 9 | #include "atn/ATNConfig.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC OrderedATNConfigSet : public ATNConfigSet { 15 | protected: 16 | virtual size_t getHash(ATNConfig *c) override; 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusBlockStartState::getStateType() { 11 | return PLUS_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Start of {@code (A|B|...)+} loop. Technically a decision state, but 14 | /// we don't use for code generation; somebody might need it, so I'm defining 15 | /// it for completeness. In reality, the node is the 16 | /// real decision-making note for {@code A+}. 17 | class ANTLR4CPP_PUBLIC PlusBlockStartState final : public BlockStartState { 18 | public: 19 | PlusLoopbackState *loopBackState = nullptr; 20 | 21 | virtual size_t getStateType() override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusLoopbackState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusLoopbackState::getStateType() { 11 | return PLUS_LOOP_BACK; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PlusLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions: 14 | /// one to the loop back to start of the block and one to exit. 15 | class ANTLR4CPP_PUBLIC PlusLoopbackState final : public DecisionState { 16 | 17 | public: 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PrecedencePredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC PrecedencePredicateTransition final : public AbstractPredicateTransition { 15 | public: 16 | const int precedence; 17 | 18 | PrecedencePredicateTransition(ATNState *target, int precedence); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | virtual bool isEpsilon() const override; 22 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 23 | Ref getPredicate() const; 24 | virtual std::string toString() const override; 25 | 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/PredicateEvalInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "SemanticContext.h" 7 | 8 | #include "atn/PredicateEvalInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, 14 | Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx) 15 | : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), 16 | semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) { 17 | } 18 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RangeTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | 8 | #include "atn/RangeTransition.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RangeTransition::RangeTransition(ATNState *target, size_t from, size_t to) : Transition(target), from(from), to(to) { 14 | } 15 | 16 | Transition::SerializationType RangeTransition::getSerializationType() const { 17 | return RANGE; 18 | } 19 | 20 | misc::IntervalSet RangeTransition::label() const { 21 | return misc::IntervalSet::of((int)from, (int)to); 22 | } 23 | 24 | bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 25 | return symbol >= from && symbol <= to; 26 | } 27 | 28 | std::string RangeTransition::toString() const { 29 | return "RANGE " + Transition::toString() + " { from: " + std::to_string(from) + ", to: " + std::to_string(to) + " }"; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RangeTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RangeTransition final : public Transition { 14 | public: 15 | const size_t from; 16 | const size_t to; 17 | 18 | RangeTransition(ATNState *target, size_t from, size_t to); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | 22 | virtual misc::IntervalSet label() const override; 23 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 24 | 25 | virtual std::string toString() const override; 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | RuleStartState::RuleStartState() { 11 | isLeftRecursiveRule = false; 12 | } 13 | 14 | size_t RuleStartState::getStateType() { 15 | return RULE_START; 16 | } 17 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleStartState final : public ATNState { 14 | public: 15 | RuleStartState(); 16 | 17 | RuleStopState *stopState = nullptr; 18 | bool isLeftRecursiveRule = false; 19 | 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStopState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStopState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t RuleStopState::getStateType() { 11 | return RULE_STOP; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/RuleStopState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The last node in the ATN for a rule, unless that rule is the start symbol. 14 | /// In that case, there is one transition to EOF. Later, we might encode 15 | /// references to all calls to this rule to compute FOLLOW sets for 16 | /// error handling. 17 | class ANTLR4CPP_PUBLIC RuleStopState final : public ATNState { 18 | 19 | public: 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/SetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | #include "misc/IntervalSet.h" 8 | 9 | #include "atn/SetTransition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | SetTransition::SetTransition(ATNState *target, const misc::IntervalSet &aSet) 15 | : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : aSet) { 16 | } 17 | 18 | Transition::SerializationType SetTransition::getSerializationType() const { 19 | return SET; 20 | } 21 | 22 | misc::IntervalSet SetTransition::label() const { 23 | return set; 24 | } 25 | 26 | bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return set.contains(symbol); 28 | } 29 | 30 | std::string SetTransition::toString() const { 31 | return "SET " + Transition::toString() + " { set: " + set.toString() + "}"; 32 | } 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/SetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// A transition containing a set of values. 15 | class ANTLR4CPP_PUBLIC SetTransition : public Transition { 16 | public: 17 | const misc::IntervalSet set; 18 | 19 | SetTransition(ATNState *target, const misc::IntervalSet &set); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t StarBlockStartState::getStateType() { 11 | return STAR_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The block that begins a closure loop. 14 | class ANTLR4CPP_PUBLIC StarBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopEntryState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | StarLoopEntryState::StarLoopEntryState() : DecisionState(), isPrecedenceDecision(false) { 11 | } 12 | 13 | size_t StarLoopEntryState::getStateType() { 14 | return STAR_LOOP_ENTRY; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopEntryState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopEntryState final : public DecisionState { 14 | public: 15 | StarLoopEntryState(); 16 | 17 | /** 18 | * Indicates whether this state can benefit from a precedence DFA during SLL 19 | * decision making. 20 | * 21 | *

This is a computed property that is calculated during ATN deserialization 22 | * and stored for use in {@link ParserATNSimulator} and 23 | * {@link ParserInterpreter}.

24 | * 25 | * @see DFA#isPrecedenceDfa() 26 | */ 27 | bool isPrecedenceDecision = false; 28 | 29 | StarLoopbackState *loopBackState = nullptr; 30 | 31 | virtual size_t getStateType() override; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/StarLoopbackState.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | StarLoopEntryState *StarLoopbackState::getLoopEntryState() { 14 | return dynamic_cast(transitions[0]->target); 15 | } 16 | 17 | size_t StarLoopbackState::getStateType() { 18 | return STAR_LOOP_BACK; 19 | } 20 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/StarLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopbackState final : public ATNState { 14 | public: 15 | StarLoopEntryState *getLoopEntryState(); 16 | 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/TokensStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/TokensStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t TokensStartState::getStateType() { 11 | return TOKEN_START; 12 | } 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/TokensStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The Tokens rule start state linking to each lexer rule start state. 14 | class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/WildcardTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNState.h" 7 | 8 | #include "atn/WildcardTransition.h" 9 | 10 | using namespace antlr4::atn; 11 | 12 | WildcardTransition::WildcardTransition(ATNState *target) : Transition(target) { 13 | } 14 | 15 | Transition::SerializationType WildcardTransition::getSerializationType() const { 16 | return WILDCARD; 17 | } 18 | 19 | bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 20 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol; 21 | } 22 | 23 | std::string WildcardTransition::toString() const { 24 | return "WILDCARD " + Transition::toString() + " {}"; 25 | } 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/atn/WildcardTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC WildcardTransition final : public Transition { 14 | public: 15 | WildcardTransition(ATNState *target); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/dfa/DFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Vocabulary.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | /// A DFA walker that knows how to dump them to serialized strings. 14 | class ANTLR4CPP_PUBLIC DFASerializer { 15 | public: 16 | DFASerializer(const DFA *dfa, const std::vector& tnames); 17 | DFASerializer(const DFA *dfa, const Vocabulary &vocabulary); 18 | virtual ~DFASerializer(); 19 | 20 | virtual std::string toString() const; 21 | 22 | protected: 23 | virtual std::string getEdgeLabel(size_t i) const; 24 | virtual std::string getStateString(DFAState *s) const; 25 | 26 | private: 27 | const DFA *_dfa; 28 | const Vocabulary &_vocabulary; 29 | }; 30 | 31 | } // namespace atn 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/dfa/LexerDFASerializer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Vocabulary.h" 7 | 8 | #include "dfa/LexerDFASerializer.h" 9 | 10 | using namespace antlr4::dfa; 11 | 12 | LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, Vocabulary::EMPTY_VOCABULARY) { 13 | } 14 | 15 | LexerDFASerializer::~LexerDFASerializer() { 16 | } 17 | 18 | std::string LexerDFASerializer::getEdgeLabel(size_t i) const { 19 | return std::string("'") + static_cast(i) + "'"; 20 | } 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/dfa/LexerDFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "dfa/DFASerializer.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | class ANTLR4CPP_PUBLIC LexerDFASerializer : public DFASerializer { 14 | public: 15 | LexerDFASerializer(DFA *dfa); 16 | virtual ~LexerDFASerializer(); 17 | 18 | protected: 19 | virtual std::string getEdgeLabel(size_t i) const override; 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/misc/InterpreterDataReader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | struct InterpreterData { 14 | atn::ATN atn; 15 | dfa::Vocabulary vocabulary; 16 | std::vector ruleNames; 17 | std::vector channels; // Only valid for lexer grammars. 18 | std::vector modes; // ditto 19 | 20 | InterpreterData() {}; // For invalid content. 21 | InterpreterData(std::vector const& literalNames, std::vector const& symbolicNames); 22 | }; 23 | 24 | // A class to read plain text interpreter data produced by ANTLR. 25 | class ANTLR4CPP_PUBLIC InterpreterDataReader { 26 | public: 27 | static InterpreterData parseFile(std::string const& fileName); 28 | }; 29 | 30 | } // namespace atn 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/misc/Predicate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | class ANTLR4CPP_PUBLIC Predicate { 14 | public: 15 | virtual ~Predicate(); 16 | 17 | virtual bool test(tree::ParseTree *t) = 0; 18 | }; 19 | 20 | } // namespace tree 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/Any.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Any.h" 7 | 8 | using namespace antlrcpp; 9 | 10 | Any::~Any() 11 | { 12 | delete _ptr; 13 | } 14 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/Arrays.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "Exceptions.h" 8 | 9 | #include "support/Arrays.h" 10 | 11 | using namespace antlrcpp; 12 | 13 | std::string Arrays::listToString(const std::vector &list, const std::string &separator) 14 | { 15 | std::stringstream ss; 16 | bool firstEntry = true; 17 | 18 | ss << '['; 19 | for (auto &entry : list) { 20 | ss << entry; 21 | if (firstEntry) { 22 | ss << separator; 23 | firstEntry = false; 24 | } 25 | } 26 | 27 | ss << ']'; 28 | return ss.str(); 29 | } 30 | 31 | template <> 32 | std::string Arrays::toString(const std::vector &source) { 33 | std::string result = "["; 34 | bool firstEntry = true; 35 | for (auto value : source) { 36 | result += value->toStringTree(); 37 | if (firstEntry) { 38 | result += ", "; 39 | firstEntry = false; 40 | } 41 | } 42 | return result + "]"; 43 | } 44 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/support/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | namespace antlrcpp { 9 | 10 | void replaceAll(std::string& str, std::string const& from, std::string const& to) 11 | { 12 | if (from.empty()) 13 | return; 14 | 15 | size_t start_pos = 0; 16 | while ((start_pos = str.find(from, start_pos)) != std::string::npos) { 17 | str.replace(start_pos, from.length(), to); 18 | start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'. 19 | } 20 | } 21 | 22 | std::string ws2s(std::wstring const& wstr) { 23 | std::wstring_convert> converter; 24 | std::string narrow = converter.to_bytes(wstr); 25 | 26 | return narrow; 27 | } 28 | 29 | std::wstring s2ws(const std::string &str) { 30 | std::wstring_convert> converter; 31 | std::wstring wide = converter.from_bytes(str); 32 | 33 | return wide; 34 | } 35 | 36 | } // namespace antrlcpp 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | 8 | antlr4::tree::ErrorNode::~ErrorNode() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ErrorNode : public virtual TerminalNode { 14 | public: 15 | ~ErrorNode() override; 16 | }; 17 | 18 | } // namespace tree 19 | } // namespace antlr4 20 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "tree/ParseTreeVisitor.h" 8 | 9 | #include "tree/ErrorNodeImpl.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::misc; 13 | using namespace antlr4::tree; 14 | 15 | ErrorNodeImpl::ErrorNodeImpl(Token *token) : TerminalNodeImpl(token) { 16 | } 17 | 18 | ErrorNodeImpl::~ErrorNodeImpl() { 19 | } 20 | 21 | antlrcpp::Any ErrorNodeImpl::accept(ParseTreeVisitor *visitor) { 22 | return visitor->visitErrorNode(this); 23 | } 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ErrorNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ErrorNode.h" 9 | #include "tree/TerminalNodeImpl.h" 10 | #include "misc/Interval.h" 11 | 12 | #include "support/Any.h" 13 | 14 | namespace antlr4 { 15 | namespace tree { 16 | 17 | /// 18 | /// Represents a token that was consumed during resynchronization 19 | /// rather than during a valid match operation. For example, 20 | /// we will create this kind of a node during single token insertion 21 | /// and deletion as well as during "consume until error recovery set" 22 | /// upon no viable alternative exceptions. 23 | /// 24 | class ANTLR4CPP_PUBLIC ErrorNodeImpl : public virtual TerminalNodeImpl, public virtual ErrorNode { 25 | public: 26 | ErrorNodeImpl(Token *token); 27 | ~ErrorNodeImpl() override; 28 | 29 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTree.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | 8 | using namespace antlr4::tree; 9 | 10 | ParseTree::ParseTree() : parent(nullptr) { 11 | } 12 | 13 | bool ParseTree::operator == (const ParseTree &other) const { 14 | return &other == this; 15 | } 16 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeListener.h" 7 | 8 | antlr4::tree::ParseTreeListener::~ParseTreeListener() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeVisitor.h" 7 | 8 | antlr4::tree::ParseTreeVisitor::~ParseTreeVisitor() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/ParseTreeWalker.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ParseTreeWalker { 14 | public: 15 | static ParseTreeWalker &DEFAULT; 16 | 17 | virtual ~ParseTreeWalker(); 18 | 19 | virtual void walk(ParseTreeListener *listener, ParseTree *t) const; 20 | 21 | protected: 22 | /// The discovery of a rule node, involves sending two events: the generic 23 | /// and a 24 | /// -specific event. First we trigger the generic and then 25 | /// the rule specific. We do them in reverse order upon finishing the node. 26 | virtual void enterRule(ParseTreeListener *listener, ParseTree *r) const; 27 | virtual void exitRule(ParseTreeListener *listener, ParseTree *r) const; 28 | }; 29 | 30 | } // namespace tree 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/TerminalNode.h" 7 | 8 | antlr4::tree::TerminalNode::~TerminalNode() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ParseTree.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNode : public ParseTree { 14 | public: 15 | ~TerminalNode() override; 16 | 17 | virtual Token* getSymbol() = 0; 18 | 19 | /** Set the parent for this leaf node. 20 | * 21 | * Technically, this is not backward compatible as it changes 22 | * the interface but no one was able to create custom 23 | * TerminalNodes anyway so I'm adding as it improves internal 24 | * code quality. 25 | * 26 | * @since 4.7 27 | */ 28 | virtual void setParent(RuleContext *parent) = 0; 29 | }; 30 | 31 | } // namespace tree 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/TerminalNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNodeImpl : public virtual TerminalNode { 14 | public: 15 | Token *symbol; 16 | 17 | TerminalNodeImpl(Token *symbol); 18 | 19 | virtual Token* getSymbol() override; 20 | virtual void setParent(RuleContext *parent) override; 21 | virtual misc::Interval getSourceInterval() override; 22 | 23 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 24 | 25 | virtual std::string getText() override; 26 | virtual std::string toStringTree(Parser *parser, bool pretty = false) override; 27 | virtual std::string toString() override; 28 | virtual std::string toStringTree(bool pretty = false) override; 29 | 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/Chunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/Chunk.h" 7 | 8 | antlr4::tree::pattern::Chunk::~Chunk() { 9 | } 10 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TagChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TagChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TagChunk::TagChunk(const std::string &tag) : TagChunk("", tag) { 13 | } 14 | 15 | TagChunk::TagChunk(const std::string &label, const std::string &tag) : _tag(tag), _label(label) { 16 | if (tag.empty()) { 17 | throw IllegalArgumentException("tag cannot be null or empty"); 18 | } 19 | 20 | } 21 | 22 | TagChunk::~TagChunk() { 23 | } 24 | 25 | std::string TagChunk::getTag() { 26 | return _tag; 27 | } 28 | 29 | std::string TagChunk::getLabel() { 30 | return _label; 31 | } 32 | 33 | std::string TagChunk::toString() { 34 | if (!_label.empty()) { 35 | return _label + ":" + _tag; 36 | } 37 | 38 | return _tag; 39 | } 40 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TextChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TextChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TextChunk::TextChunk(const std::string &text) : text(text) { 13 | if (text == "") { 14 | throw IllegalArgumentException("text cannot be nul"); 15 | } 16 | 17 | } 18 | 19 | TextChunk::~TextChunk() { 20 | } 21 | 22 | std::string TextChunk::getText() { 23 | return text; 24 | } 25 | 26 | std::string TextChunk::toString() { 27 | return std::string("'") + text + std::string("'"); 28 | } 29 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/pattern/TokenTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/TokenTagToken.h" 7 | 8 | using namespace antlr4::tree::pattern; 9 | 10 | TokenTagToken::TokenTagToken(const std::string &/*tokenName*/, int type) 11 | : CommonToken(type), tokenName(""), label("") { 12 | } 13 | 14 | TokenTagToken::TokenTagToken(const std::string &tokenName, int type, const std::string &label) 15 | : CommonToken(type), tokenName(tokenName), label(label) { 16 | } 17 | 18 | std::string TokenTagToken::getTokenName() const { 19 | return tokenName; 20 | } 21 | 22 | std::string TokenTagToken::getLabel() const { 23 | return label; 24 | } 25 | 26 | std::string TokenTagToken::getText() const { 27 | if (!label.empty()) { 28 | return "<" + label + ":" + tokenName + ">"; 29 | } 30 | 31 | return "<" + tokenName + ">"; 32 | } 33 | 34 | std::string TokenTagToken::toString() const { 35 | return tokenName + ":" + std::to_string(_type); 36 | } 37 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/CPPUtils.h" 7 | 8 | #include "XPathElement.h" 9 | 10 | using namespace antlr4::tree; 11 | using namespace antlr4::tree::xpath; 12 | 13 | XPathElement::XPathElement(const std::string &nodeName) { 14 | _nodeName = nodeName; 15 | } 16 | 17 | XPathElement::~XPathElement() { 18 | } 19 | 20 | std::vector XPathElement::evaluate(ParseTree * /*t*/) { 21 | return {}; 22 | } 23 | 24 | std::string XPathElement::toString() const { 25 | std::string inv = _invert ? "!" : ""; 26 | return antlrcpp::toString(*this) + "[" + inv + _nodeName + "]"; 27 | } 28 | 29 | void XPathElement::setInvert(bool value) { 30 | _invert = value; 31 | } 32 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexer.tokens: -------------------------------------------------------------------------------- 1 | TOKEN_REF=1 2 | RULE_REF=2 3 | ANYWHERE=3 4 | ROOT=4 5 | WILDCARD=5 6 | BANG=6 7 | ID=7 8 | STRING=8 9 | '//'=3 10 | '/'=4 11 | '*'=5 12 | '!'=6 13 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexerErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPathLexerErrorListener.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::tree::xpath; 10 | 11 | void XPathLexerErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 12 | size_t /*line*/, size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathLexerErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathLexerErrorListener : public BaseErrorListener { 15 | public: 16 | virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, 17 | size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override; 18 | }; 19 | 20 | } // namespace xpath 21 | } // namespace tree 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "tree/xpath/XPathRuleAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleAnywhereElement::XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllRuleNodes(t, _ruleIndex); 20 | } 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | /// Either {@code ID} at start of path or {@code ...//ID} in middle of path. 15 | class ANTLR4CPP_PUBLIC XPathRuleAnywhereElement : public XPathElement { 16 | public: 17 | XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex); 18 | 19 | virtual std::vector evaluate(ParseTree *t) override; 20 | 21 | protected: 22 | int _ruleIndex = 0; 23 | }; 24 | 25 | } // namespace xpath 26 | } // namespace tree 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathRuleElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleElement::XPathRuleElement(const std::string &ruleName, size_t ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleElement::evaluate(ParseTree *t) { 19 | // return all children of t that match nodeName 20 | std::vector nodes; 21 | for (auto c : t->children) { 22 | if (antlrcpp::is(c)) { 23 | ParserRuleContext *ctx = dynamic_cast(c); 24 | if ((ctx->getRuleIndex() == _ruleIndex && !_invert) || (ctx->getRuleIndex() != _ruleIndex && _invert)) { 25 | nodes.push_back(ctx); 26 | } 27 | } 28 | } 29 | return nodes; 30 | } 31 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathRuleElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathRuleElement : public XPathElement { 15 | public: 16 | XPathRuleElement(const std::string &ruleName, size_t ruleIndex); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _ruleIndex = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathTokenAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathTokenAnywhereElement::XPathTokenAnywhereElement(const std::string &tokenName, int tokenType) : XPathElement(tokenName) { 15 | this->tokenType = tokenType; 16 | } 17 | 18 | std::vector XPathTokenAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllTokenNodes(t, tokenType); 20 | } 21 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenAnywhereElement : public XPathElement { 15 | protected: 16 | int tokenType = 0; 17 | public: 18 | XPathTokenAnywhereElement(const std::string &tokenName, int tokenType); 19 | 20 | virtual std::vector evaluate(ParseTree *t) override; 21 | }; 22 | 23 | } // namespace xpath 24 | } // namespace tree 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathTokenElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenElement : public XPathElement { 15 | public: 16 | XPathTokenElement(const std::string &tokenName, size_t tokenType); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _tokenType = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardAnywhereElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardAnywhereElement::XPathWildcardAnywhereElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardAnywhereElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | return Trees::getDescendants(t); 23 | } 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardAnywhereElement : public XPathElement { 15 | public: 16 | XPathWildcardAnywhereElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardElement::XPathWildcardElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | 23 | return t->children; 24 | } 25 | -------------------------------------------------------------------------------- /third_party/antlr4-runtime/tree/xpath/XPathWildcardElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardElement : public XPathElement { 15 | public: 16 | XPathWildcardElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | --------------------------------------------------------------------------------