Skip to content
Browse files

[Utilities] Add in a new dump_pbc program, showcasing the new Command…

…line setup. This utility dumps class, namespace and function information from an existing pbc file to the console.
  • Loading branch information...
1 parent 982ce53 commit 1babcacfd63ed0fd99f4ce70697ad5da8b321237 awhitworth committed
Showing with 86 additions and 0 deletions.
  1. +4 −0 setup.winxed
  2. +82 −0 src/utilities/dump_pbc.winxed
View
4 setup.winxed
@@ -473,6 +473,10 @@ function setup_utilities(var rosella)
"rosella_doc" : {
"install_name" : "rosella_doc",
"includes" : ["Core", "CommandLine", "FileSystem", "Query", "Reflect"]
+ },
+ "dump_pbc" : {
+ "install_name" : "rosella_dump_pbc",
+ "includes" : ["Core", "FileSystem", "String", "CommandLine", "Query", "Reflect"]
}
};
string src_prefix = "src/utilities/";
View
82 src/utilities/dump_pbc.winxed
@@ -0,0 +1,82 @@
+// Main entry point. Parse arguments and dispatch to the main handler
+function main[main](var args)
+{
+ Rosella.Query.install_to_parrot_types();
+ var p = new Rosella.CommandLine.Program(args.shift());
+ p.define_arguments({
+ "help|h" : "Show help message",
+ "class|c" : "Dump classes",
+ "namespace|n" : "Dump namespaces",
+ "function|f" : "Dump functions (implies -n)"
+ });
+ p.default_mode().set_function(dump_pbc_main);
+ p.add_mode("help").require_flag("h").set_function(usage_and_exit);
+ p.on_error(usage_and_exit);
+ p.run(args);
+}
+
+function usage_and_exit(var args)
+{
+ say(args.program.get_help_text());
+}
+
+function dump_pbc_main(var args)
+{
+ string libpath = args[0];
+ int dump_classes = args["class"];
+ int dump_namespaces = args["namespace"];
+ int dump_functions = args["function"];
+
+ // TODO: Dump some header information in all modes
+
+ var module = Rosella.Reflect.Module.load(libpath);
+
+ if (dump_namespaces) {
+ say("Namespaces:");
+ if (dump_functions) {
+ dump_functions = false;
+ module.functions_by_ns()
+ .iterable()
+ .filter(function(kvp) { return elements(kvp.value()) > 0; })
+ .foreach(function(kvp) {
+ string nsname = kvp.key();
+ Rosella.IO.sayf("\t%s", nsname);
+ kvp.value().iterable().foreach(function(sub) {
+ Rosella.IO.sayf("\t\t%s", string(sub));
+ });
+ });
+ } else {
+ module.functions_by_ns()
+ .iterable()
+ .filter(function(kvp) { return elements(kvp.value()) > 0; })
+ .foreach(function(kvp) {
+ var subs = kvp.value();
+ string nsname = kvp.key();
+ Rosella.IO.sayf("\t%s", nsname);
+ });
+ }
+ }
+
+ if (dump_functions) {
+ say("Functions: ");
+ module.functions_by_ns()
+ .iterable()
+ .filter(function(kvp) { return elements(kvp.value()) > 0; })
+ .foreach(function(kvp) {
+ string nsname = kvp.key();
+ kvp.value().iterable().foreach(function(sub) {
+ Rosella.IO.sayf("\t\t%s.%s", nsname, string(sub));
+ });
+ });
+ }
+
+ if (dump_classes) {
+ say("Classes:");
+ module.classes()
+ .iterable()
+ .foreach(function(kvp) {
+ string classname = kvp.key();
+ Rosella.IO.sayf("\t%s", classname);
+ });
+ }
+}

0 comments on commit 1babcac

Please sign in to comment.
Something went wrong with that request. Please try again.