123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113(* Copyright (C) 2008 Yoann Padioleau
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL)
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* file license.txt for more details.
*)openCommonopenAst_javamodulePI=Parse_infomoduleV=Visitor_java(*****************************************************************************)(* Subsystem testing *)(*****************************************************************************)lettest_parsexs=letfullxs=Lib_parsing_java.find_source_files_of_dir_or_filesxsinletext="java"inletstat_list=ref[]inletnewscore=Common2.empty_score()inCommon2.check_stack_nbfiles(List.lengthfullxs);fullxs|>List.iter(funfile->pr2("PARSING: "^file);let(_xs,stat)=Common.save_excursionFlag_parsing.error_recoverytrue(fun()->Parse_java.parsefile)inCommon.pushstatstat_list;lets=spf"bad = %d"stat.PI.badinifstat.PI.bad=0thenHashtbl.addnewscorefile(Common2.Ok)elseHashtbl.addnewscorefile(Common2.Pbs););flushstdout;flushstderr;PI.print_parsing_stat_list!stat_list;letdirname_opt=matchxswith|[x]whenCommon2.is_directoryx->Some(Common.fullpathx)|_->Noneinletscore_path=Filename.concatConfig_pfff.path"tmp"indirname_opt|>Common.do_option(fundirname->pr2"--------------------------------";pr2"regression testing information";pr2"--------------------------------";letstr=Str.global_replace(Str.regexp"/")"__"dirnameinCommon2.regression_testingnewscore(Filename.concatscore_path("score_parsing__"^str^ext^".marshalled")));()lettest_lexerfile=letlexbuf=Lexing.from_channel(open_infile)inwhiletruedoletresult=Lexer_java.tokenlexbufinpr2_genresult;ifToken_helpers_java.is_eofresultthenexit0donelettest_dumpfile=letast=Parse_java.parse_programfileinletv=Meta_ast_java.vof_any(Ast_java.AProgramast)inletstr=Ocaml.string_of_vvinprstrlettest_visitorfile=letvisitor=V.mk_visitor{V.default_visitorwithV.kexpr=(fun(k,_)e->matchewith|Ast_java.Literal(Ast_java.Int(s,_))->pr2("int:"^s);ke|Ast_java.Dot(e,(_s,_))->pr2"dot: s";ke|_->ke);}inletast=Parse_java.parse_programfileinvisitor(AProgramast);()(*****************************************************************************)(* Main entry for Arg *)(*****************************************************************************)letactions()=["-tokens_java"," <file>",Common.mk_action_1_argtest_lexer;"-parse_java"," <file or dir>",Common.mk_action_n_argtest_parse;"-dump_java"," <file>",Common.mk_action_1_argtest_dump;"-visitor_java"," <file>",Common.mk_action_1_argtest_visitor;]