Skip to content
This repository
Browse code

[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...
commit 1babcacfd63ed0fd99f4ce70697ad5da8b321237 1 parent 982ce53
awhitworth authored

Showing 2 changed files with 86 additions and 0 deletions. Show diff stats Hide diff stats

  1. +4 0 setup.winxed
  2. +82 0 src/utilities/dump_pbc.winxed
4 setup.winxed
@@ -473,6 +473,10 @@ function setup_utilities(var rosella)
473 473 "rosella_doc" : {
474 474 "install_name" : "rosella_doc",
475 475 "includes" : ["Core", "CommandLine", "FileSystem", "Query", "Reflect"]
  476 + },
  477 + "dump_pbc" : {
  478 + "install_name" : "rosella_dump_pbc",
  479 + "includes" : ["Core", "FileSystem", "String", "CommandLine", "Query", "Reflect"]
476 480 }
477 481 };
478 482 string src_prefix = "src/utilities/";
82 src/utilities/dump_pbc.winxed
... ... @@ -0,0 +1,82 @@
  1 +// Main entry point. Parse arguments and dispatch to the main handler
  2 +function main[main](var args)
  3 +{
  4 + Rosella.Query.install_to_parrot_types();
  5 + var p = new Rosella.CommandLine.Program(args.shift());
  6 + p.define_arguments({
  7 + "help|h" : "Show help message",
  8 + "class|c" : "Dump classes",
  9 + "namespace|n" : "Dump namespaces",
  10 + "function|f" : "Dump functions (implies -n)"
  11 + });
  12 + p.default_mode().set_function(dump_pbc_main);
  13 + p.add_mode("help").require_flag("h").set_function(usage_and_exit);
  14 + p.on_error(usage_and_exit);
  15 + p.run(args);
  16 +}
  17 +
  18 +function usage_and_exit(var args)
  19 +{
  20 + say(args.program.get_help_text());
  21 +}
  22 +
  23 +function dump_pbc_main(var args)
  24 +{
  25 + string libpath = args[0];
  26 + int dump_classes = args["class"];
  27 + int dump_namespaces = args["namespace"];
  28 + int dump_functions = args["function"];
  29 +
  30 + // TODO: Dump some header information in all modes
  31 +
  32 + var module = Rosella.Reflect.Module.load(libpath);
  33 +
  34 + if (dump_namespaces) {
  35 + say("Namespaces:");
  36 + if (dump_functions) {
  37 + dump_functions = false;
  38 + module.functions_by_ns()
  39 + .iterable()
  40 + .filter(function(kvp) { return elements(kvp.value()) > 0; })
  41 + .foreach(function(kvp) {
  42 + string nsname = kvp.key();
  43 + Rosella.IO.sayf("\t%s", nsname);
  44 + kvp.value().iterable().foreach(function(sub) {
  45 + Rosella.IO.sayf("\t\t%s", string(sub));
  46 + });
  47 + });
  48 + } else {
  49 + module.functions_by_ns()
  50 + .iterable()
  51 + .filter(function(kvp) { return elements(kvp.value()) > 0; })
  52 + .foreach(function(kvp) {
  53 + var subs = kvp.value();
  54 + string nsname = kvp.key();
  55 + Rosella.IO.sayf("\t%s", nsname);
  56 + });
  57 + }
  58 + }
  59 +
  60 + if (dump_functions) {
  61 + say("Functions: ");
  62 + module.functions_by_ns()
  63 + .iterable()
  64 + .filter(function(kvp) { return elements(kvp.value()) > 0; })
  65 + .foreach(function(kvp) {
  66 + string nsname = kvp.key();
  67 + kvp.value().iterable().foreach(function(sub) {
  68 + Rosella.IO.sayf("\t\t%s.%s", nsname, string(sub));
  69 + });
  70 + });
  71 + }
  72 +
  73 + if (dump_classes) {
  74 + say("Classes:");
  75 + module.classes()
  76 + .iterable()
  77 + .foreach(function(kvp) {
  78 + string classname = kvp.key();
  79 + Rosella.IO.sayf("\t%s", classname);
  80 + });
  81 + }
  82 +}

0 comments on commit 1babcac

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