comparison libinterp/parse-tree/token.cc @ 30723:08b08b7f05b2

Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753) Define 4 new inline functions in error.h (panic_if, panic_unless, error_if, error_unless) that call either assert() or Octave's own error() function. Replace calls to assert() in code that maintains state and for which no recovery on detection of a problem is possible with calls to panic_XXX. Replace calls to assert() in interpreter code which could simply return to the Octave prompt when a problem is detected with calls to error_XXX. * error.h (panic_if, panic_unless): New functions which eventually call can call assert(). panic_if (COND) calls assert if COND is true. panic_unless (COND) calls assert if COND is false. * error.h (error_if, error_unless): New functions which eventually call can call Octave's error() function. error_if (COND) calls assert if COND is true. error_unless (COND) calls assert if COND is false. * cellfun.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, dot.cc, error.cc, graphics.cc, kron.cc, mex.cc, oct-map.cc, oct-stream.cc, pr-output.cc, schur.cc, stack-frame.cc, typecast.cc, variables.cc, ov-base.cc, ov-class.cc, ov-fcn-handle.cc, ov-struct.cc, ov-usr-fcn.cc, ov.h, ovl.cc, ops.h, profiler.cc, pt-classdef.cc, pt-eval.cc, pt-idx.cc, pt-pr-code.cc, pt-tm-const.cc, token.cc: Replace direct calls to C library assert() with Octave specialty functions.
author Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
date Mon, 07 Feb 2022 21:47:53 -0800
parents 796f54d4ddbf
children e88a07dec498
comparison
equal deleted inserted replaced
30720:25de51cb4123 30723:08b08b7f05b2
27 # include "config.h" 27 # include "config.h"
28 #endif 28 #endif
29 29
30 #include <cassert> 30 #include <cassert>
31 31
32 #include "error.h"
32 #include "token.h" 33 #include "token.h"
33 34
34 namespace octave 35 namespace octave
35 { 36 {
36 token::token (int tv, const filepos& beg_pos, const filepos& end_pos) 37 token::token (int tv, const filepos& beg_pos, const filepos& end_pos)
93 } 94 }
94 95
95 std::string 96 std::string
96 token::text (void) const 97 token::text (void) const
97 { 98 {
98 assert (m_type_tag == string_token); 99 panic_if (m_type_tag != string_token);
99 return *m_tok_info.m_str; 100 return *m_tok_info.m_str;
100 } 101 }
101 102
102 octave_value 103 octave_value
103 token::number (void) const 104 token::number (void) const
104 { 105 {
105 assert (m_type_tag == numeric_token); 106 panic_if (m_type_tag != numeric_token);
106 return *m_tok_info.m_num; 107 return *m_tok_info.m_num;
107 } 108 }
108 109
109 token::token_type 110 token::token_type
110 token::ttype (void) const 111 token::ttype (void) const
113 } 114 }
114 115
115 token::end_tok_type 116 token::end_tok_type
116 token::ettype (void) const 117 token::ettype (void) const
117 { 118 {
118 assert (m_type_tag == ettype_token); 119 panic_if (m_type_tag != ettype_token);
119 return m_tok_info.m_et; 120 return m_tok_info.m_et;
120 } 121 }
121 122
122 std::string 123 std::string
123 token::superclass_method_name (void) const 124 token::superclass_method_name (void) const
124 { 125 {
125 assert (m_type_tag == scls_name_token); 126 panic_if (m_type_tag != scls_name_token);
126 return m_tok_info.m_superclass_info->m_method_name; 127 return m_tok_info.m_superclass_info->m_method_name;
127 } 128 }
128 129
129 std::string 130 std::string
130 token::superclass_class_name (void) const 131 token::superclass_class_name (void) const
131 { 132 {
132 assert (m_type_tag == scls_name_token); 133 panic_if (m_type_tag != scls_name_token);
133 return m_tok_info.m_superclass_info->m_class_name; 134 return m_tok_info.m_superclass_info->m_class_name;
134 } 135 }
135 136
136 std::string 137 std::string
137 token::text_rep (void) const 138 token::text_rep (void) const