var opt_unknown = new OptionEnum(["comment", "stub", "ignore"], "How to deal with unknown types", 0, "-u")
var opt_verbose = new OptionCount("Verbosity", "-v")
var opt_output = new OptionString("Output file", "-o")
+var opt_regex = new OptionString("Regex pattern to filter classes in Jar archives", "-r")
var opt_help = new OptionBool("Show this help message", "-h", "--help")
-opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_verbose, opt_help)
+opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_libs, opt_regex, opt_cast_objects, opt_arrays, opt_save_model, opt_load_models, opt_no_properties, opt_verbose, opt_help)
opts.parse args
if opts.errors.not_empty or opts.rest.is_empty or opt_help.value then
exit 1
end
+var regex = null
+var regex_code = opt_regex.value
+if regex_code != null then
+ regex = regex_code.to_re
+ var error = regex.compile
+ if error != null then
+ print_error "Regex Error: {error}"
+ exit 1
+ end
+end
+
# List of bytecode Java classes and javap output files
var class_files = new Array[String]
var javap_files = new Array[String]
else if ext == "javap" then
javap_files.add input
else if ext == "jar" then
- var out_dir = "tmp"
clock.lapse
+ var out_dir = "tmp"
+ if not out_dir.file_exists then out_dir.mkdir
+
if opt_verbose.value > 0 then print "# Extracting {input}"
# Extract all files
javap.wait
for path in output.split("\n") do
if path.file_extension == "class" then
+
+ # Filter out the classes that do not answer to the Regex
+ if regex != null and not path.has(regex) then continue
+
class_files.add out_dir / path
end
end
visitor.enter_visit root_node
sys.perfs["core model"].add clock.lapse
+# Resolve types
+model.resolve_types
+sys.perfs["core resolve"].add clock.lapse
+
+# Build class hierarchy
+model.build_class_hierarchy
+sys.perfs["core hierarchy"].add clock.lapse
+
if opt_verbose.value > 0 then print "# Generating Nit code"
+# Generate the Nit module
var use_comment = opt_unknown.value == 0
var use_stub = opt_unknown.value == 1
var generator = new CodeGenerator(out_file, model, use_comment, use_stub)
generator.generate
sys.perfs["code generator"].add clock.lapse
+# Write the model to a file, for use by subsequent passes
+generator.write_model_to_file
+sys.perfs["writing model"].add clock.lapse
+
if opt_verbose.value > 1 then
print "# Performance Analysis:"
print sys.perfs
+
+ print "# {model.unknown_types.length} unknown types:"
+ var c = 0
+ for id, ntype in model.unknown_types do
+ print "* {id}"
+ c += 1
+ if c > 100 then
+ print "* ..."
+ break
+ end
+ end
end