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 is a Nit extern class generator `in "Java"`.
18 # It takes a .class file and output a Nit file. For further details on installation and usage, refer to the README file.
20 # Here's an overview of the project design :
21 # * Grammar and lexer : `grammar/javap.sablecc`
22 # * The `javap_visitor` implements the visitor that extracts data from the AST
23 # * The `code_generator` takes these data and converts it to Nit code via the `jtype_converter` module and generate the output Nit file.
24 # * The `types` contains data structures used to represent the data
25 # * The `jwrapper` module implements the user interface
29 import javap_test_parser
33 var opts
= new OptionContext
35 var opt_attr
= new OptionBool("Generate attributes", "-a", "--with-attributes")
36 var opt_comment
= new OptionBool("Comment methods/attributes containing unknown types", "-c", "--comment")
37 var opt_wrap
= new OptionBool("Create extern classes wrapping unknown types (Default)", "-w", "--wrap")
38 var opt_help
= new OptionBool("Show this help message", "-h", "--help")
40 opts
.add_option
(opt_attr
, opt_comment
, opt_wrap
, opt_help
)
44 if opt_wrap
.value
and opt_comment
.value
then
45 print
"Error: Can't use both '-c' and '-w'"
49 if not opts
.errors
.is_empty
or opts
.rest
.length
!= 2 or opt_help
.value
then
50 print
"USAGE: jwrapper [OPTIONS] class_file nit_file"
54 if opt_help
.value
then exit
0
58 var dot_class
= opts
.rest
[0]
59 var out_file
= opts
.rest
[1]
61 if not "javap".program_is_in_path
then
62 print
"ERROR: 'javap' not found."
66 var javap
= new IProcess("javap", "-public", dot_class
)
68 # Eat the superfluous output line
71 var p
= new TestParser_javap
72 var tree
= p
.work
(javap
.read_all
)
74 var converter
= new JavaTypeConverter
76 var visitor
= new JavaVisitor(converter
)
77 visitor
.enter_visit
(tree
)
79 var generator
= new CodeGenerator(out_file
, visitor
.java_class
, opt_attr
.value
, opt_comment
.value
)