changeset 31079:f0343b3685df

maint: merge stable to default
author Torsten Lilge <ttl-octave@mailbox.org>
date Tue, 07 Jun 2022 19:44:07 +0200
parents bcadacfac44f (current diff) 4d45392387ec (diff)
children 56ee6a223c51
files libgui/src/m-editor/file-editor-tab.cc libinterp/parse-tree/lex.ll
diffstat 3 files changed, 41 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/numbers.txi	Mon Jun 06 14:28:06 2022 +0200
+++ b/doc/interpreter/numbers.txi	Tue Jun 07 19:44:07 2022 +0200
@@ -102,7 +102,7 @@
 * Integer Data Types::
 * Bit Manipulations::
 * Logical Values::
-* Promotion and Demotion of Data Types::
+* Automatic Conversion of Data Types::
 * Predicates for Numeric Objects::
 @end menu
 
@@ -709,8 +709,8 @@
 
 @DOCSTRING(false)
 
-@node Promotion and Demotion of Data Types
-@section Promotion and Demotion of Data Types
+@node Automatic Conversion of Data Types
+@section Automatic Conversion of Data Types
 
 Many operators and functions can work with mixed data types.  For example,
 
@@ -719,38 +719,22 @@
 uint8 (1) + 1
     @result{} 2
 @end group
-@end example
 
-@noindent
-where the above operator works with an 8-bit integer and a double precision
-value and returns an 8-bit integer value.  Note that the type is demoted
-to an 8-bit integer, rather than promoted to a double precision value as
-might be expected.  The reason is that if Octave promoted values in
-expressions like the above with all numerical constants would need to be
-explicitly cast to the appropriate data type like
+@group
+single (1) + 1
+    @result{} 2
+@end group
 
-@example
 @group
-uint8 (1) + uint8 (1)
-    @result{} 2
+min (single (1), 0)
+   @result{} 0
 @end group
 @end example
 
 @noindent
-which becomes difficult for the user to apply uniformly and might allow
-hard to find bugs to be introduced.  The same applies to single precision
-values where a mixed operation such as
-
-@example
-@group
-single (1) + 1
-    @result{} 2
-@end group
-@end example
-
-@noindent
-returns a single precision value.  The mixed operations that are valid
-and their returned data types are
+where the results are respectively of types uint8, single, and single
+respectively.  This is done for Matlab compatibility.  Valid mixed operations
+are defined as follows:
 
 @multitable @columnfractions .2 .3 .3 .2
 @headitem @tab Mixed Operation @tab Result @tab
@@ -763,20 +747,8 @@
 @item @tab single OP logical @tab single @tab
 @end multitable
 
-The same logic applies to functions with mixed arguments such as
-
-@example
-@group
-min (single (1), 0)
-   @result{} 0
-@end group
-@end example
-
-@noindent
-where the returned value is single precision.
-
-Many functions and operators will also promote integer or logical types to
-double, or single to double, especially if they take only one argument.
+When functions expect a double but are passed other types, automatic
+conversion is function-dependent:
 
 @example
 @group
@@ -785,22 +757,15 @@
 class (a)
     @result{} double
 @end group
-@end example
 
-But there are also exceptions for promoting to double, especially if the
-function or operator in question can take multiple arguments.
-
-@example
 @group
 a = eig (int8 ([1 2; 3 4]))
     @result{} error: eig: wrong type argument 'int8 matrix'
 @end group
 @end example
 
-When the two operands are both integers but of different widths, then the
-behavior depends on the operator or the function in question.  For some
-operators and functions, narrow-bitwidth operands are promoted to a wider
-bitwidth:
+When two operands are both integers but of different widths, then some cases
+convert them to the wider bitwidth, and other cases throw an error:
 
 @example
 @group
@@ -809,12 +774,7 @@
 class (a)
     @result{} int16
 @end group
-@end example
 
-However, not all functions or operators will accept integer operands of
-differing types:
-
-@example
 @group
 int8 (100) + int16 (200)
    @result{} error: binary operator '+' not implemented
@@ -822,14 +782,14 @@
 @end group
 @end example
 
-Further, in most cases, both operands need to be signed or both need to be
+For two integer operands, they typically need to both be signed or both be
 unsigned.  Mixing signed and unsigned usually causes an error, even if they
 are of the same bitwidth.
 
 @example
 @group
-min (int8 (100), uint16 (200))
-   @result{} error: min: cannot compute min (int8 scalar, uint16 scalar)
+min (int16 (100), uint16 (200))
+   @result{} error: min: cannot compute min (int16 scalar, uint16 scalar)
 @end group
 @end example
 
--- a/doc/interpreter/octave.texi	Mon Jun 06 14:28:06 2022 +0200
+++ b/doc/interpreter/octave.texi	Tue Jun 07 19:44:07 2022 +0200
@@ -291,7 +291,7 @@
 * Integer Data Types::
 * Bit Manipulations::
 * Logical Values::
-* Promotion and Demotion of Data Types::
+* Automatic Conversion of Data Types::
 * Predicates for Numeric Objects::
 
 Matrices
--- a/libinterp/parse-tree/lex.ll	Mon Jun 06 14:28:06 2022 +0200
+++ b/libinterp/parse-tree/lex.ll	Tue Jun 07 19:44:07 2022 +0200
@@ -2705,53 +2705,50 @@
             return 0;
           }
 
-        tok_val = new token (end_kw, token::simple_end, m_tok_beg, m_tok_end);
+        tok_val = new token (kw->tok, token::simple_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case end_try_catch_kw:
-        tok_val = new token (end_try_catch_kw, token::try_catch_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::try_catch_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case end_unwind_protect_kw:
-        tok_val = new token (end_unwind_protect_kw,
-                             token::unwind_protect_end, m_tok_beg, m_tok_end);
+        tok_val = new token (kw->tok, token::unwind_protect_end, m_tok_beg,
+                             m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endfor_kw:
-        tok_val = new token (endfor_kw, token::for_end, m_tok_beg, m_tok_end);
+        tok_val = new token (kw->tok, token::for_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endfunction_kw:
-        tok_val = new token (endfunction_kw, token::function_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::function_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endif_kw:
-        tok_val = new token (endif_kw, token::if_end, m_tok_beg, m_tok_end);
+        tok_val = new token (kw->tok, token::if_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endparfor_kw:
-        tok_val = new token (endparfor_kw, token::parfor_end, m_tok_beg,
-                             m_tok_end);
+        tok_val = new token (kw->tok, token::parfor_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endswitch_kw:
-        tok_val = new token (endswitch_kw, token::switch_end, m_tok_beg,
-                             m_tok_end);
+        tok_val = new token (kw->tok, token::switch_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endwhile_kw:
-        tok_val = new token (endwhile_kw, token::while_end, m_tok_beg,
-                             m_tok_end);
+        tok_val = new token (kw->tok, token::while_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
@@ -2759,38 +2756,38 @@
 #if defined (DISABLE_ARGUMENTS_VALIDATION_BLOCK)
         return 0;
 #else
-        tok_val = new token (endarguments_kw, token::arguments_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::arguments_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 #endif
 
       case endclassdef_kw:
-        tok_val = new token (endclassdef_kw, token::classdef_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::classdef_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endenumeration_kw:
-        tok_val = new token (endenumeration_kw, token::enumeration_end,
-                             m_tok_beg, m_tok_end);
+        tok_val = new token (kw->tok, token::enumeration_end, m_tok_beg,
+                             m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endevents_kw:
-        tok_val = new token (endevents_kw, token::events_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::events_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endmethods_kw:
-        tok_val = new token (endmethods_kw, token::methods_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::methods_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
       case endproperties_kw:
-        tok_val = new token (endproperties_kw, token::properties_end, m_tok_beg,
+        tok_val = new token (kw->tok, token::properties_end, m_tok_beg,
                              m_tok_end);
         m_at_beginning_of_statement = true;
         break;
@@ -2894,7 +2891,7 @@
         break;
 
       case endspmd_kw:
-        tok_val = new token (endspmd_kw, token::spmd_end, m_tok_beg, m_tok_end);
+        tok_val = new token (kw->tok, token::spmd_end, m_tok_beg, m_tok_end);
         m_at_beginning_of_statement = true;
         break;
 
@@ -2903,10 +2900,10 @@
           if ((m_reading_fcn_file || m_reading_script_file
                || m_reading_classdef_file)
               && ! m_fcn_file_full_name.empty ())
-            tok_val = new token (magic_file_kw, m_fcn_file_full_name,
+            tok_val = new token (kw->tok, m_fcn_file_full_name,
                                  m_tok_beg, m_tok_end);
           else
-            tok_val = new token (magic_file_kw, "stdin", m_tok_beg, m_tok_end);
+            tok_val = new token (kw->tok, "stdin", m_tok_beg, m_tok_end);
         }
         break;
 
@@ -2914,8 +2911,7 @@
         {
           int l = m_tok_beg.line ();
           octave_value ov_value (static_cast<double> (l));
-          tok_val = new token (magic_line_kw, ov_value, "",
-                               m_tok_beg, m_tok_end);
+          tok_val = new token (kw->tok, ov_value, "", m_tok_beg, m_tok_end);
         }
         break;