annotate scripts/legacy/@inline/inline.m @ 30911:b7edac56a810

Add functions to @inline class for Matlab compatibility (Bug #62260). * scripts/legacy/@inline/cat.m, scripts/legacy/@inline/cat.m, scripts/legacy/@inline/disp.m, scripts/legacy/@inline/exist.m, scripts/legacy/@inline/horzcat.m, scripts/legacy/@inline/nargin.m, scripts/legacy/@inline/nargout.m, scripts/legacy/@inline/symvar.m, scripts/legacy/@inline/vertcat.m: New functions * scripts/legacy/module.mk: Add new functions to build system. * scripts/legacy/@inline/argnames.m: scripts/legacy/@inline/char.m, scripts/legacy/@inline/feval.m, scripts/legacy/@inline/formula.m, scripts/legacy/@inline/subsref.m, scripts/legacy/@inline/vectorize.m: Redo documentation. Change FCN input name to FOBJ. * scripts/legacy/@inline/inline.m: Single tweak to documentation. * scripts/legacy/__vectorize__.m: Add note that this function was translated from C++. * scripts/legacy/vectorize.m: Remove incorrect note about function being translated from C++.
author Rik <rik@octave.org>
date Wed, 06 Apr 2022 21:25:58 -0700
parents 5d3faba0342e
children ec5b57af230a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ########################################################################
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
3 ## Copyright (C) 2020-2022 The Octave Project Developers
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## This file is part of Octave.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## (at your option) any later version.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 ## GNU General Public License for more details.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 ## <https://www.gnu.org/licenses/>.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ########################################################################
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ## -*- texinfo -*-
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
27 ## @deftypefn {} {@var{fobj} =} inline (@var{str})
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
28 ## @deftypefnx {} {@var{fobj} =} inline (@var{str}, @var{arg1}, @dots{})
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
29 ## @deftypefnx {} {@var{fobj} =} inline (@var{str}, @var{n})
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 ## This function is obsolete. Use anonymous functions
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 ## (@pxref{Anonymous Functions}) instead.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 ##
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
34 ## Create an inline function object from the character string @var{str}.
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 ## If called with a single argument, the arguments of the generated
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 ## function are extracted from the function itself. The generated
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 ## function arguments will then be in alphabetical order. It should be
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 ## noted that i and j are ignored as arguments due to the ambiguity
30911
b7edac56a810 Add functions to @inline class for Matlab compatibility (Bug #62260).
Rik <rik@octave.org>
parents: 30875
diff changeset
40 ## between their use as a variable and their use as an built-in constant.
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 ## All arguments followed by a parenthesis are considered to be
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 ## functions. If no arguments are found, a function taking a single
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 ## argument named @code{x} will be created.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 ## If the second and subsequent arguments are character strings, they
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 ## are the names of the arguments of the function.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 ## If the second argument is an integer @var{n}, the arguments are
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 ## @qcode{"x"}, @qcode{"P1"}, @dots{}, @qcode{"P@var{N}"}.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 ##
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 ## @strong{Caution:} the use of @code{inline} is discouraged and it may
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 ## be removed from a future version of Octave. The preferred way to
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 ## create functions from strings is through the use of anonymous
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 ## functions (@pxref{Anonymous Functions}) or @code{str2func}.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 ## @seealso{argnames, formula, vectorize, str2func}
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 ## @end deftypefn
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
58 function fobj = inline (expr, varargin)
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
28458
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
60 persistent warned = false;
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
61 if (! warned)
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
62 warned = true;
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
63 warning ("Octave:legacy-function",
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
64 "inline is obsolete; use anonymous functions instead\n");
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
65 endif
ef8cf8dda0ba warn if legacy inline, genvarname or vectorize functions are used
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
66
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 if (nargin == 0)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 print_usage ();
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 if (! ischar (expr))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 error ("inline: EXPR must be a string");
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 if (nargin == 1)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 args = parse_expr_for_args (expr);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 elseif (nargin == 2)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 n = varargin{1};
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 if (isnumeric (n))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 if (isscalar (n) && fix (n) == n)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 if (n > 0)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 args = strsplit (["x", sprintf(":P%d", 1:n)], ":");
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 error ("inline: N must be a positive integer");
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 error ("inline: N must be an integer");
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 args = {"x"};
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 elseif (iscellstr (varargin))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 args = varargin;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 error ("inline: additional arguments must be strings");
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 p.expr = expr;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 p.args = args(:);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 p.numArgs = numel (args);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 tmp = [args; num2cell(1:numel(args))];
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 p.inputExpr = sprintf ("%s = INLINE_INPUTS_{%d}; ", tmp{:});
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 p.isEmpty = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 p.version = 1;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
106 fobj = __inline_ctor__ (p);
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 endfunction
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 ## The following function was translated directly from the original C++
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 ## version. Yes, it will be slow, but the use of inline functions is
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 ## strongly discouraged anyway, and most expressions will probably be
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 ## short. It may also be buggy. Well, don't use this object! Use
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 ## function handles instead!
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 function args = parse_expr_for_args (expr)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 persistent symbols_to_skip = {"i", "j", "NaN", "nan", "Inf", "inf", ...
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 "NA", "pi", "e", "eps"};
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 is_arg = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 in_string = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 tmp_arg = "";
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 i = 1;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 expr_length = length (expr);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 args = {};
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 while (i <= expr_length)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 terminate_arg = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 c = expr(i++);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 if (in_string)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 if (c == "'" || c == '"')
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 in_string = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 elseif (c == "'" || c == '"')
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 in_string = true;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 if (is_arg)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 terminate_arg = true;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 elseif (! isalpha (c) && c != "_")
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 if (! is_arg)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 continue;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 elseif (isdigit (c))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 tmp_arg(end+1) = c;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 ## Before we do anything remove trailing whitespaces.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 while (i <= expr_length && isspace (c))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 c = expr(i++);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 endwhile
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 ## Do we have a variable or a function?
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 if (c != "(")
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 terminate_arg = true;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 tmp_arg = "";
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 is_arg = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 elseif (! is_arg)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 if (c == "e" || c == "E")
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 ## Possible number in exponent form, not arg.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 if (isdigit (expr(i)) || expr(i) == "-" || expr(i) == "+")
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 continue;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 is_arg = true;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 tmp_arg(end+1) = c;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 else
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 tmp_arg(end+1) = c;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 if (terminate_arg || (i == expr_length+1 && is_arg))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 have_arg = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 if (any (strcmp (tmp_arg, args)))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 have_arg = true;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 if (! (have_arg || any (strcmp (tmp_arg, symbols_to_skip))))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 args{end+1} = tmp_arg;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 tmp_arg = "";
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 is_arg = false;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 endwhile
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 ## Sort the arguments into ASCII order.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 args = sort (args);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 if (isempty (args))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 args = {"x"};
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 endif
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 endfunction