# HG changeset patch # User jwe # Date 1089652453 0 # Node ID 1242acab4246452d1c8eb486f7170077d57212d6 # Parent 5c9e36402f1734fc49b50e712906c39771d1a30d [project @ 2004-07-12 17:14:13 by jwe] diff -r 5c9e36402f17 -r 1242acab4246 src/ChangeLog --- a/src/ChangeLog Mon Jul 12 17:10:29 2004 +0000 +++ b/src/ChangeLog Mon Jul 12 17:14:13 2004 +0000 @@ -1,3 +1,27 @@ +2004-07-12 John W. Eaton + + * ov-intx.h: N-d array and scalar extractor functions take no args. + + * ov.h (octave_value::int8_scalar_value, + octave_value::int16_scalar_value, octave_value::int32_scalar_value, + octave_value::int64_scalar_value, octave_value::uint8_scalar_value, + octave_value::uint16_scalar_value, octave_value::uint32_scalar_value, + octave_value::uint64_scalar_value): New functions. + * ov-base.cc (octave_base_value::int8_scalar_value, + octave_base_value::int16_scalar_value, + octave_base_value::int32_scalar_value, + octave_base_value::int64_scalar_value, + octave_base_value::uint8_scalar_value, + octave_base_value::uint16_scalar_value, + octave_base_value::uint32_scalar_value, + octave_base_value::uint64_scalar_value): New functions. + * ov-base.h: Provide decls. + + * lex.l: (Vtoken_count): New static variable. + (COUNT_TOK_AND_RETURN): New macro. Use it everywhere a token is + returned to the parser. + (F__token_count__): New function. + 2004-06-25 John W. Eaton * OPERATORS/op-int-conv.cc: Add conversions for range type. diff -r 5c9e36402f17 -r 1242acab4246 src/lex.l --- a/src/lex.l Mon Jul 12 17:10:29 2004 +0000 +++ b/src/lex.l Mon Jul 12 17:14:13 2004 +0000 @@ -48,6 +48,7 @@ #include "cmd-edit.h" #include "quit.h" +#include "lo-mappers.h" #include "lo-sstream.h" // These would be alphabetical, but y.tab.h must be included before @@ -60,6 +61,7 @@ #include "comment-list.h" #include "defun.h" #include "error.h" +#include "gripes.h" #include "input.h" #include "lex.h" #include "ov.h" @@ -106,6 +108,14 @@ } \ while (0) +#define COUNT_TOK_AND_RETURN(tok) \ + do \ + { \ + Vtoken_count++; \ + return tok; \ + } \ + while (0) + #define TOK_RETURN(tok) \ do \ { \ @@ -113,7 +123,7 @@ lexer_flags.quote_is_transpose = false; \ lexer_flags.cant_be_identifier = false; \ lexer_flags.convert_spaces_to_comma = true; \ - return (tok); \ + COUNT_TOK_AND_RETURN (tok); \ } \ while (0) @@ -136,7 +146,7 @@ lexer_flags.quote_is_transpose = false; \ lexer_flags.cant_be_identifier = true; \ lexer_flags.convert_spaces_to_comma = convert; \ - return (tok); \ + COUNT_TOK_AND_RETURN (tok); \ } \ while (0) @@ -223,6 +233,8 @@ static bool Vwarn_single_quote_string = false; +static unsigned int Vtoken_count = 0; + // Forward declarations for functions defined at the bottom of this // file. @@ -280,14 +292,14 @@ . { BEGIN (NESTED_FUNCTION_BEGIN); yyunput (yytext[0], yytext); - return ';'; + COUNT_TOK_AND_RETURN (';'); } . { BEGIN (INITIAL); yyunput (yytext[0], yytext); prep_for_nested_function (); - return FCN; + COUNT_TOK_AND_RETURN (FCN); } %{ @@ -302,7 +314,7 @@ lexer_flags.quote_is_transpose = false; lexer_flags.cant_be_identifier = false; lexer_flags.convert_spaces_to_comma = true; - return '\n'; + COUNT_TOK_AND_RETURN ('\n'); } [\;\,] { @@ -322,7 +334,7 @@ [\"\'] { current_input_column++; - return handle_string (yytext[0], true); + COUNT_TOK_AND_RETURN (handle_string (yytext[0], true)); } [^#% \t\n\;\,\"\'][^ \t\n\;\,]*{S}* { @@ -348,7 +360,7 @@ int c = yytext[yyleng-1]; int cont_is_spc = eat_continuation (); bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); - return handle_close_bracket (spc_gobbled, ']'); + COUNT_TOK_AND_RETURN (handle_close_bracket (spc_gobbled, ']')); } {SNLCMT}*\}{S}* { @@ -357,7 +369,7 @@ int c = yytext[yyleng-1]; int cont_is_spc = eat_continuation (); bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); - return handle_close_bracket (spc_gobbled, '}'); + COUNT_TOK_AND_RETURN (handle_close_bracket (spc_gobbled, '}')); } %{ @@ -382,7 +394,7 @@ yyunput (';', yytext); } - return (','); + COUNT_TOK_AND_RETURN (','); } %{ @@ -416,7 +428,7 @@ maybe_warn_separator_insert (','); - return (','); + COUNT_TOK_AND_RETURN (','); } } @@ -433,7 +445,7 @@ lexer_flags.quote_is_transpose = false; lexer_flags.cant_be_identifier = false; lexer_flags.convert_spaces_to_comma = true; - return ';'; + COUNT_TOK_AND_RETURN (';'); } %{ @@ -459,7 +471,7 @@ { maybe_warn_separator_insert (';'); - return ';'; + COUNT_TOK_AND_RETURN (';'); } } @@ -483,13 +495,13 @@ if (lexer_flags.plotting && ! lexer_flags.past_plot_range) { lexer_flags.in_plot_range = true; - return OPEN_BRACE; + COUNT_TOK_AND_RETURN (OPEN_BRACE); } else { lexer_flags.bracketflag++; BEGIN (MATRIX_START); - return '['; + COUNT_TOK_AND_RETURN ('['); } } @@ -511,7 +523,7 @@ {NUMBER}{Im} { handle_number (); - return IMAG_NUM; + COUNT_TOK_AND_RETURN (IMAG_NUM); } %{ @@ -522,7 +534,7 @@ {D}+/\.[\*/\\^'] | {NUMBER} { handle_number (); - return NUM; + COUNT_TOK_AND_RETURN (NUM); } %{ @@ -556,12 +568,12 @@ if (lexer_flags.looking_at_parameter_list) { warning ("`...' is deprecated; use varargin instead"); - return VARARGIN; + COUNT_TOK_AND_RETURN (VARARGIN); } else if (lexer_flags.looking_at_return_list) { warning ("`...' is deprecated; use varargout instead"); - return VARARGOUT; + COUNT_TOK_AND_RETURN (VARARGOUT); } else return LEXICAL_ERROR; @@ -584,7 +596,7 @@ int id_tok = handle_identifier (); if (id_tok >= 0) - return id_tok; + COUNT_TOK_AND_RETURN (id_tok); } %{ @@ -608,7 +620,7 @@ lexer_flags.convert_spaces_to_comma = true; if (nesting_level.none ()) - return '\n'; + COUNT_TOK_AND_RETURN ('\n'); else if (nesting_level.is_paren ()) gripe_matlab_incompatible ("bare newline inside parentheses"); else if (nesting_level.is_bracket_or_brace ()) @@ -627,10 +639,10 @@ if (lexer_flags.quote_is_transpose) { do_comma_insert_check (); - return QUOTE; + COUNT_TOK_AND_RETURN (QUOTE); } else - return handle_string ('\''); + COUNT_TOK_AND_RETURN (handle_string ('\'')); } %{ @@ -639,7 +651,7 @@ \" { current_input_column++; - return handle_string ('"'); + COUNT_TOK_AND_RETURN (handle_string ('"')); } %{ @@ -710,9 +722,9 @@ BEGIN (INITIAL); if (nesting_level.none ()) - return '\n'; + COUNT_TOK_AND_RETURN ('\n'); else if (nesting_level.is_bracket_or_brace ()) - return ';'; + COUNT_TOK_AND_RETURN (';'); } %{ @@ -790,7 +802,7 @@ lexer_flags.quote_is_transpose = true; lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); do_comma_insert_check (); - return ')'; + COUNT_TOK_AND_RETURN (')'); } "." { @@ -827,7 +839,7 @@ lexer_flags.braceflag++; BEGIN (MATRIX_START); - return '{'; + COUNT_TOK_AND_RETURN ('{'); } "}" { @@ -2757,6 +2769,16 @@ gripe_matlab_incompatible (t + " used as operator"); } +DEFUN (__token_count__, , , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} disp (@var{x})\n\ +@deftypefn {Built-in Function} {} __token_count__\n\ +Number of language tokens processed since Octave startup.\n\ +@end deftypefn") +{ + return octave_value (Vtoken_count); +} + static int warn_matlab_incompatible (void) { diff -r 5c9e36402f17 -r 1242acab4246 src/ov-base.cc --- a/src/ov-base.cc Mon Jul 12 17:10:29 2004 +0000 +++ b/src/ov-base.cc Mon Jul 12 17:14:13 2004 +0000 @@ -409,12 +409,85 @@ return retval; } +octave_int8 +octave_base_value::int8_scalar_value (void) const +{ + octave_int8 retval; + gripe_wrong_type_arg ("octave_base_value::int8_scalar_value()", + type_name ()); + return retval; +} + +octave_int16 +octave_base_value::int16_scalar_value (void) const +{ + octave_int16 retval; + gripe_wrong_type_arg ("octave_base_value::int16_scalar_value()", + type_name ()); + return retval; +} + +octave_int32 +octave_base_value::int32_scalar_value (void) const +{ + octave_int32 retval; + gripe_wrong_type_arg ("octave_base_value::int32_scalar_value()", + type_name ()); + return retval; +} + +octave_int64 +octave_base_value::int64_scalar_value (void) const +{ + octave_int64 retval; + gripe_wrong_type_arg ("octave_base_value::int64_scalar_value()", + type_name ()); + return retval; +} + +octave_uint8 +octave_base_value::uint8_scalar_value (void) const +{ + octave_uint8 retval; + gripe_wrong_type_arg ("octave_base_value::uint8_scalar_value()", + type_name ()); + return retval; +} + +octave_uint16 +octave_base_value::uint16_scalar_value (void) const +{ + octave_uint16 retval; + gripe_wrong_type_arg ("octave_base_value::uint16_scalar_value()", + type_name ()); + return retval; +} + +octave_uint32 +octave_base_value::uint32_scalar_value (void) const +{ + octave_uint32 retval; + gripe_wrong_type_arg ("octave_base_value::uint32_scalar_value()", + type_name ()); + return retval; +} + +octave_uint64 +octave_base_value::uint64_scalar_value (void) const +{ + octave_uint64 retval; + gripe_wrong_type_arg ("octave_base_value::uint64_scalar_value()", + type_name ()); + return retval; +} + int8NDArray octave_base_value::int8_array_value (void) const { int8NDArray retval; gripe_wrong_type_arg ("octave_base_value::int8_array_value()", type_name ()); + return retval; } int16NDArray @@ -423,6 +496,7 @@ int16NDArray retval; gripe_wrong_type_arg ("octave_base_value::int16_array_value()", type_name ()); + return retval; } int32NDArray @@ -431,6 +505,7 @@ int32NDArray retval; gripe_wrong_type_arg ("octave_base_value::int32_array_value()", type_name ()); + return retval; } int64NDArray @@ -439,6 +514,7 @@ int64NDArray retval; gripe_wrong_type_arg ("octave_base_value::int64_array_value()", type_name ()); + return retval; } uint8NDArray @@ -447,6 +523,7 @@ uint8NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint8_array_value()", type_name ()); + return retval; } uint16NDArray @@ -455,6 +532,7 @@ uint16NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint16_array_value()", type_name ()); + return retval; } uint32NDArray @@ -463,6 +541,7 @@ uint32NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint32_array_value()", type_name ()); + return retval; } uint64NDArray @@ -471,6 +550,7 @@ uint64NDArray retval; gripe_wrong_type_arg ("octave_base_value::uint64_array_value()", type_name ()); + return retval; } string_vector diff -r 5c9e36402f17 -r 1242acab4246 src/ov-base.h --- a/src/ov-base.h Mon Jul 12 17:10:29 2004 +0000 +++ b/src/ov-base.h Mon Jul 12 17:14:13 2004 +0000 @@ -216,6 +216,22 @@ charNDArray char_array_value (bool = false) const; + octave_int8 int8_scalar_value (void) const; + + octave_int16 int16_scalar_value (void) const; + + octave_int32 int32_scalar_value (void) const; + + octave_int64 int64_scalar_value (void) const; + + octave_uint8 uint8_scalar_value (void) const; + + octave_uint16 uint16_scalar_value (void) const; + + octave_uint32 uint32_scalar_value (void) const; + + octave_uint64 uint64_scalar_value (void) const; + int8NDArray int8_array_value (void) const; int16NDArray int16_array_value (void) const; diff -r 5c9e36402f17 -r 1242acab4246 src/ov-intx.h --- a/src/ov-intx.h Mon Jul 12 17:10:29 2004 +0000 +++ b/src/ov-intx.h Mon Jul 12 17:14:13 2004 +0000 @@ -58,7 +58,7 @@ { return new OCTAVE_VALUE_INT_MATRIX_T (); } OCTAVE_INT_NDARRAY_T - OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (bool = false) const + OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const { return matrix; } private: @@ -91,12 +91,12 @@ { return new OCTAVE_VALUE_INT_SCALAR_T (); } OCTAVE_INT_T - OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (bool = false) const + OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (void) const { return scalar; } OCTAVE_INT_NDARRAY_T - OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (bool = false) const - { return scalar; } + OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION (void) const + { return OCTAVE_INT_NDARRAY_T (dim_vector (1, 1), scalar); } private: diff -r 5c9e36402f17 -r 1242acab4246 src/ov.h --- a/src/ov.h Mon Jul 12 17:10:29 2004 +0000 +++ b/src/ov.h Mon Jul 12 17:14:13 2004 +0000 @@ -213,20 +213,20 @@ octave_value (const charMatrix& chm, bool is_string = false); octave_value (const charNDArray& chnda, bool is_string = false); octave_value (const octave_int8& i); + octave_value (const octave_int16& i); + octave_value (const octave_int32& i); + octave_value (const octave_int64& i); octave_value (const octave_uint8& i); - octave_value (const octave_int16& i); octave_value (const octave_uint16& i); - octave_value (const octave_int32& i); octave_value (const octave_uint32& i); - octave_value (const octave_int64& i); octave_value (const octave_uint64& i); octave_value (const int8NDArray& inda); + octave_value (const int16NDArray& inda); + octave_value (const int32NDArray& inda); + octave_value (const int64NDArray& inda); octave_value (const uint8NDArray& inda); - octave_value (const int16NDArray& inda); octave_value (const uint16NDArray& inda); - octave_value (const int32NDArray& inda); octave_value (const uint32NDArray& inda); - octave_value (const int64NDArray& inda); octave_value (const uint64NDArray& inda); octave_value (double base, double limit, double inc); octave_value (const Range& r); @@ -557,6 +557,30 @@ virtual charNDArray char_array_value (bool frc_str_conv = false) const { return rep->char_array_value (frc_str_conv); } + virtual octave_int8 int8_scalar_value (void) const + { return rep->int8_scalar_value (); } + + virtual octave_int16 int16_scalar_value (void) const + { return rep->int16_scalar_value (); } + + virtual octave_int32 int32_scalar_value (void) const + { return rep->int32_scalar_value (); } + + virtual octave_int64 int64_scalar_value (void) const + { return rep->int64_scalar_value (); } + + virtual octave_uint8 uint8_scalar_value (void) const + { return rep->uint8_scalar_value (); } + + virtual octave_uint16 uint16_scalar_value (void) const + { return rep->uint16_scalar_value (); } + + virtual octave_uint32 uint32_scalar_value (void) const + { return rep->uint32_scalar_value (); } + + virtual octave_uint64 uint64_scalar_value (void) const + { return rep->uint64_scalar_value (); } + virtual int8NDArray int8_array_value (void) const { return rep->int8_array_value (); }