octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compound operators


From: John W. Eaton
Subject: compound operators
Date: Thu, 08 May 2008 11:46:56 -0400

On  7-May-2008, Jaroslav Hajek wrote:

| I've made first attempt to elaborate on the idea John W. Eaton gave on
| this list a while ago: having Octave's parser to recognize expressions
| like `expr1' * expr2' as special, to allow more efficient mapping of
| operations onto BLAS routines.
| 
| The initial commit is in my public repo:
| https://tw-math.de/highegg

OK, this looks like an excellent start.

In functions like

  static octave_value::unary_op 
  strip_trans_herm (tree_expression *&exp)
  {
    if (exp->is_unary_expression ())
      {
        tree_unary_expression *uexp = 
          dynamic_cast<tree_unary_expression *> (exp);
        octave_value::unary_op op = uexp->op_type ();
        if (op == octave_value::op_transpose
            || op == octave_value::op_hermitian)
          {
            exp = uexp->operand ();
          }
        else
          {
            op = octave_value::unknown_unary_op;
          }
        return op;
      }
    else
      return octave_value::unknown_unary_op;
  }

it looks like there will be a memory leak if you replace exp (which
was dynamically allocated by the parser) with another part of the
parse tree.  So maybe this should be

  static octave_value::unary_op 
  strip_trans_herm (tree_expression *&exp)
  {
    octave_value::unary_op retval = octave_value::unknown_unary_op;

    if (exp->is_unary_expression ())
      {
        tree_unary_expression *uexp = 
          dynamic_cast<tree_unary_expression *> (exp);

        octave_value::unary_op op = uexp->op_type ();

        if (op == octave_value::op_transpose
            || op == octave_value::op_hermitian)
          {
            tree_expression *tmp = exp;
            exp = uexp->operand ();
            delete tmp;

            retval = op;
          }
      }

    return retval
  }

?

Also, if you add a new parse tree class, you need to add it to the
tree_walker class in pt-walk.h and then create corresponding visitor
functions in all the classes that can walk the tree.  Currently, those
are in the pt-pr-code, pt-bp, and pt-check files.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]