Hi all -- this is (hopefully) a quick question.

I'd like to use octave's parser to rewrite some Matlab code.  Ideally,
I'd simply load up the .m file using the octave parser, and then walk
the resulting tree to spit out the new source code.

I've figured out to do most of that, using load_fcn_from_file and
a custom tree_walker based on tree_print_code.

Everything is great, with one exception: subfunctions.

I can't figure out to get a pointer to the octave_function for
subfunctions which are defined in a single .m file.

Here's what I know:

* In parser.cc, when a subfunction is finished parsing, the parser
   calls "install_subfunction" in the symbol_table class.  This
   creates an entry in the fcn_table table.

* If I could simply walk the fcn_table object, I'd be done -- but I
   can't, since it's private.  So I need to find another way to
   get at the appropriate octave_function pointer.

* The function subfunctions_defined_in_scope looks perfect.  But
   again, it's private.  (Argh!)

* I thought that perhaps I could take a look at all of the symbols
   defined in each scope and figure out which one corresponds to the
   subfunction defined.  No luck with this approach:

* None of the following functions return anything:

   symbol_table::user_function_names();
   symbol_table::top_level_variable_names();
   symbol_table::built_in_function_names();
   symbol_table::global_variable_names();
   symbol_table::variable_names();
   symbol_table::built_in_function_names();

* Using     symbol_table::all_variables( scope, -1, false) I can
   iterate over all of the variables defined in each scope.

* I had hoped that I would then be able to use the resulting names,
   combined with find_function(), to get at what I need.  No luck --
   I've tried to follow the chain of logic, but I end up getting
   pretty confused by the logic.  It appears that some test fails,
   and a new, empty octave_value ends up being returned.

So: I'm a bit frustrated that there isn't a simpler way to get
at the subfunctions that get parsed out of a .m file.  I'm hoping
that there's an easy way to accomplish what I want to, and that
since I'm not an octave developer, I'm just missing it.

Obviously, I could just patch octave to make 
subfunctions_defined_in_scope a public method, or make the
fcn_table public, but I'd rather not do that; ideally, my code would
build against the standard octave library.

Any help and/or hints would be greatly appreciated.

I can send along source code, if it would help.

Thanks,

                -- David


-- 
David Wingate     | Computational Cognitive Science Group
[email protected]  | Brain and Cognitive Sciences
(617) 324-2894    |   Quantum materiae materietur marmota monax si
46-4053H BCS      |   marmota monax materiam possit materiari?

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to