1 # This file is part of NIT (http://www.nitlanguage.org).
3 # Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # jwrapper wraps Java classes in extern Nit classes
19 # This tool takes class file, Jar archives and javap files as input,
20 # and it outputs a Nit source file.
21 # For further details on installation and usage, refer to the README file.
23 # Here's an overview of the project design :
24 # * Grammar and lexer : `grammar/javap.sablecc`
25 # * The `javap_visitor` implements the visitor that extracts data from the AST
26 # * The `code_generator` takes these data and converts it to Nit code via the `jtype_converter` module and generate the output Nit file.
27 # * The `model` contains data structures used to represent the data
28 # * The `jwrapper` module implements the user interface
32 import javap_test_parser
36 var opts
= new OptionContext
38 var opt_unknown
= new OptionEnum(["comment", "stub", "ignore"], "How to deal with unknown types", 0, "-u")
39 var opt_verbose
= new OptionCount("Verbosity", "-v")
40 var opt_output
= new OptionString("Output file", "-o")
41 var opt_help
= new OptionBool("Show this help message", "-h", "--help")
43 opts
.add_option
(opt_output
, opt_unknown
, opt_verbose
, opt_help
)
46 if opts
.errors
.not_empty
or opts
.rest
.is_empty
or opt_help
.value
then
48 Usage: jwrapper [options] file [other_file [...]]
49 Input files: bytecode Java class (.class), Jar archive (.jar) or javap output (.javap)
53 if opt_help
.value
then exit
0
57 var out_file
= opt_output
.value
58 if out_file
== null then out_file
= "out.nit"
60 if not "javap".program_is_in_path
then
61 print
"Error: 'javap' must be in PATH"
65 var javap
= new ProcessReader("javap", "-public", dot_class
)
67 var p
= new TestParser_javap
68 var tree
= p
.work
(javap
.read_all
)
70 var converter
= new JavaTypeConverter
72 var visitor
= new JavaVisitor(converter
)
73 visitor
.enter_visit
(tree
)
75 var generator
= new CodeGenerator(out_file
, visitor
.java_class
, opt_attr
.value
, opt_comment
.value
)