Mercurial > octave
comparison libinterp/parse-tree/lex.ll @ 29572:aef11bb4e6d1
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
Files affected: make_int.cc, file-editor-tab.cc, octave-qscintilla.cc,
Cell.cc, Cell.h, call-stack.cc, call-stack.h, cellfun.cc, data.cc,
debug.cc, dlmread.cc, error.cc, event-queue.h, fcn-info.cc,
fcn-info.h, file-io.cc, ft-text-renderer.cc, gl2ps-print.cc,
graphics.cc, graphics.in.h, help.cc, hex2num.cc, input.cc,
latex-text-renderer.cc, load-path.cc, load-save.cc, load-save.h,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat5.cc, ls-oct-text.cc, mex.cc,
mexproto.h, mxarray.h, oct-map.cc, oct-stream.cc, oct-stream.h,
pager.cc, pager.h, pr-output.cc, regexp.cc, settings.h,
stack-frame.cc, stack-frame.h, strfns.cc, syminfo.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, sysdep.cc, toplev.cc, utils.cc,
utils.h, variables.cc, __fltk_uigetfile__.cc, __init_fltk__.cc,
audioread.cc, gzip.cc, cdef-class.cc, cdef-manager.cc, cdef-method.cc,
cdef-object.cc, cdef-object.h, ov-base-diag.cc, ov-base-diag.h,
ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h,
ov-base-sparse.h, ov-base.cc, ov-base.h, ov-cell.cc, ov-cell.h,
ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-fcn-handle.cc, ov-java.cc, ov-lazy-idx.h, ov-perm.cc, ov-perm.h,
ov-range.h, ov-str-mat.cc, ov-struct.cc, ov-struct.h, ov-usr-fcn.cc,
ov-usr-fcn.h, ov.cc, ov.h, ovl.cc, octave.cc, bp-table.cc, jit-ir.cc,
jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.h, lex.h, lex.ll,
oct-lvalue.cc, oct-parse.yy, parse.h, profiler.h, pt-eval.cc,
pt-eval.h, pt-jit.cc, pt-jit.h, pt-pr-code.cc, pt-tm-const.cc,
pt-tm-const.h, Array.h, CMatrix.cc, DiagArray2.h, PermMatrix.h,
Sparse.h, dMatrix.cc, fCMatrix.cc, fMatrix.cc, bsxfun-defs.cc,
oct-fftw.cc, oct-fftw.h, randpoisson.cc, sparse-chol.cc,
mx-inlines.cc, file-ops.cc, lo-sysdep.cc, oct-env.cc, oct-time.cc,
action-container.cc, action-container.h, base-list.h, caseless-str.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, data-conv.h, f77-fcn.h,
file-info.cc, file-info.h, kpse.cc, kpse.h, lo-cutils.h, lo-hash.h,
lo-regexp.cc, oct-base64.cc, oct-base64.h, oct-binmap.h, oct-glob.cc,
oct-shlib.cc, oct-shlib.h, oct-sort.cc, oct-sparse.h, oct-string.cc,
quit.cc, unwind-prot.h, url-transfer.cc, main.in.cc, mkoctfile.in.cc,
and shared-fcns.h.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 28 Apr 2021 22:57:42 -0400 |
parents | 30afb3804d6e |
children | 32f4357ac8d9 |
comparison
equal
deleted
inserted
replaced
29571:76deb8194590 | 29572:aef11bb4e6d1 |
---|---|
849 curr_lexer->lexer_debug ("<LINE_COMMENT_START>{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}"); | 849 curr_lexer->lexer_debug ("<LINE_COMMENT_START>{S}*{CCHAR}{ANY_EXCEPT_NL}*{NL}"); |
850 | 850 |
851 // Grab text of comment without leading space or comment | 851 // Grab text of comment without leading space or comment |
852 // characters. | 852 // characters. |
853 | 853 |
854 size_t i = 0; | 854 std::size_t i = 0; |
855 while (i < yyleng && is_space_or_tab (yytext[i])) | 855 while (i < yyleng && is_space_or_tab (yytext[i])) |
856 i++; | 856 i++; |
857 | 857 |
858 bool have_space = (i > 0); | 858 bool have_space = (i > 0); |
859 | 859 |
1366 { | 1366 { |
1367 if (curr_lexer->m_at_beginning_of_statement) | 1367 if (curr_lexer->m_at_beginning_of_statement) |
1368 { | 1368 { |
1369 std::string txt = yytext; | 1369 std::string txt = yytext; |
1370 | 1370 |
1371 size_t at_or_dot_pos = txt.find_first_of ("@."); | 1371 std::size_t at_or_dot_pos = txt.find_first_of ("@."); |
1372 | 1372 |
1373 if (at_or_dot_pos != std::string::npos) | 1373 if (at_or_dot_pos != std::string::npos) |
1374 { | 1374 { |
1375 size_t spc_pos = txt.find_first_of (" \t"); | 1375 std::size_t spc_pos = txt.find_first_of (" \t"); |
1376 | 1376 |
1377 if (spc_pos != std::string::npos && spc_pos < at_or_dot_pos) | 1377 if (spc_pos != std::string::npos && spc_pos < at_or_dot_pos) |
1378 { | 1378 { |
1379 yyless (spc_pos); | 1379 yyless (spc_pos); |
1380 curr_lexer->m_filepos.increment_column (spc_pos); | 1380 curr_lexer->m_filepos.increment_column (spc_pos); |
2201 } | 2201 } |
2202 | 2202 |
2203 symbol_scope | 2203 symbol_scope |
2204 lexical_feedback::symbol_table_context::parent_scope (void) const | 2204 lexical_feedback::symbol_table_context::parent_scope (void) const |
2205 { | 2205 { |
2206 size_t sz = size (); | 2206 std::size_t sz = size (); |
2207 | 2207 |
2208 return (sz > 1 | 2208 return (sz > 1 |
2209 ? m_frame_stack[1] | 2209 ? m_frame_stack[1] |
2210 : (sz == 1 ? m_frame_stack[0] : symbol_scope ())); | 2210 : (sz == 1 ? m_frame_stack[0] : symbol_scope ())); |
2211 } | 2211 } |
2373 return false; | 2373 return false; |
2374 | 2374 |
2375 // Comment characters have been stripped but whitespace | 2375 // Comment characters have been stripped but whitespace |
2376 // (including newlines) remains. | 2376 // (including newlines) remains. |
2377 | 2377 |
2378 size_t offset = s.find_first_not_of (" \t\n\r"); | 2378 std::size_t offset = s.find_first_not_of (" \t\n\r"); |
2379 | 2379 |
2380 return (offset != std::string::npos | 2380 return (offset != std::string::npos |
2381 && (s.substr (offset, 9) == "Copyright" | 2381 && (s.substr (offset, 9) == "Copyright" |
2382 || s.substr (offset, 6) == "Author" | 2382 || s.substr (offset, 6) == "Author" |
2383 || s.substr (offset, 23) == "SPDX-License-Identifier")); | 2383 || s.substr (offset, 23) == "SPDX-License-Identifier")); |
2400 m_eof = eof_arg; | 2400 m_eof = eof_arg; |
2401 } | 2401 } |
2402 | 2402 |
2403 // If BY_LINES is true, return chunks to the lexer line by line. | 2403 // If BY_LINES is true, return chunks to the lexer line by line. |
2404 int | 2404 int |
2405 base_lexer::input_buffer::copy_chunk (char *buf, size_t max_size, | 2405 base_lexer::input_buffer::copy_chunk (char *buf, std::size_t max_size, |
2406 bool by_lines) | 2406 bool by_lines) |
2407 { | 2407 { |
2408 static const char * const eol = "\n"; | 2408 static const char * const eol = "\n"; |
2409 | 2409 |
2410 size_t len = 0; | 2410 std::size_t len = 0; |
2411 if (by_lines) | 2411 if (by_lines) |
2412 { | 2412 { |
2413 size_t newline_pos = m_buffer.find ('\n', m_offset); | 2413 std::size_t newline_pos = m_buffer.find ('\n', m_offset); |
2414 len = (newline_pos != std::string::npos | 2414 len = (newline_pos != std::string::npos |
2415 ? newline_pos - m_offset + 1 | 2415 ? newline_pos - m_offset + 1 |
2416 : (max_size > m_chars_left ? m_chars_left : max_size)); | 2416 : (max_size > m_chars_left ? m_chars_left : max_size)); |
2417 } | 2417 } |
2418 else | 2418 else |
2918 } | 2918 } |
2919 | 2919 |
2920 bool | 2920 bool |
2921 base_lexer::fq_identifier_contains_keyword (const std::string& s) | 2921 base_lexer::fq_identifier_contains_keyword (const std::string& s) |
2922 { | 2922 { |
2923 size_t p1 = 0; | 2923 std::size_t p1 = 0; |
2924 size_t p2; | 2924 std::size_t p2; |
2925 | 2925 |
2926 std::string s_part; | 2926 std::string s_part; |
2927 | 2927 |
2928 do | 2928 do |
2929 { | 2929 { |
3026 std::string yytxt (flex_yytext () + 2); | 3026 std::string yytxt (flex_yytext () + 2); |
3027 | 3027 |
3028 yytxt.erase (std::remove (yytxt.begin (), yytxt.end (), '_'), | 3028 yytxt.erase (std::remove (yytxt.begin (), yytxt.end (), '_'), |
3029 yytxt.end ()); | 3029 yytxt.end ()); |
3030 | 3030 |
3031 size_t pos = yytxt.find_first_of ("su"); | 3031 std::size_t pos = yytxt.find_first_of ("su"); |
3032 | 3032 |
3033 bool unsigned_val = true; | 3033 bool unsigned_val = true; |
3034 int bytes = -1; | 3034 int bytes = -1; |
3035 | 3035 |
3036 if (pos == std::string::npos) | 3036 if (pos == std::string::npos) |
3037 { | 3037 { |
3038 size_t num_digits = yytxt.length (); | 3038 std::size_t num_digits = yytxt.length (); |
3039 | 3039 |
3040 if (num_digits <= 8) | 3040 if (num_digits <= 8) |
3041 bytes = 1; | 3041 bytes = 1; |
3042 else if (num_digits <= 16) | 3042 else if (num_digits <= 16) |
3043 bytes = 2; | 3043 bytes = 2; |
3049 else | 3049 else |
3050 { | 3050 { |
3051 unsigned_val = (yytxt[pos] == 'u'); | 3051 unsigned_val = (yytxt[pos] == 'u'); |
3052 std::string size_str = yytxt.substr (pos+1); | 3052 std::string size_str = yytxt.substr (pos+1); |
3053 yytxt = yytxt.substr (0, pos); | 3053 yytxt = yytxt.substr (0, pos); |
3054 size_t num_digits = yytxt.length (); | 3054 std::size_t num_digits = yytxt.length (); |
3055 | 3055 |
3056 if (size_str == "8" && num_digits <= 8) | 3056 if (size_str == "8" && num_digits <= 8) |
3057 bytes = 1; | 3057 bytes = 1; |
3058 else if (size_str == "16" && num_digits <= 16) | 3058 else if (size_str == "16" && num_digits <= 16) |
3059 bytes = 2; | 3059 bytes = 2; |
3117 { | 3117 { |
3118 bool imag = false; | 3118 bool imag = false; |
3119 bool digits_only = true; | 3119 bool digits_only = true; |
3120 | 3120 |
3121 char *yytxt = flex_yytext (); | 3121 char *yytxt = flex_yytext (); |
3122 size_t yylng = flex_yyleng (); | 3122 std::size_t yylng = flex_yyleng (); |
3123 | 3123 |
3124 OCTAVE_LOCAL_BUFFER (char, tmptxt, yylng + 1); | 3124 OCTAVE_LOCAL_BUFFER (char, tmptxt, yylng + 1); |
3125 char *rp = yytxt; | 3125 char *rp = yytxt; |
3126 char *p = &tmptxt[0]; | 3126 char *p = &tmptxt[0]; |
3127 | 3127 |
3234 std::string yytxt (flex_yytext () + 2); | 3234 std::string yytxt (flex_yytext () + 2); |
3235 | 3235 |
3236 yytxt.erase (std::remove (yytxt.begin (), yytxt.end (), '_'), | 3236 yytxt.erase (std::remove (yytxt.begin (), yytxt.end (), '_'), |
3237 yytxt.end ()); | 3237 yytxt.end ()); |
3238 | 3238 |
3239 size_t pos = yytxt.find_first_of ("su"); | 3239 std::size_t pos = yytxt.find_first_of ("su"); |
3240 | 3240 |
3241 bool unsigned_val = true; | 3241 bool unsigned_val = true; |
3242 int bytes = -1; | 3242 int bytes = -1; |
3243 | 3243 |
3244 if (pos == std::string::npos) | 3244 if (pos == std::string::npos) |
3245 { | 3245 { |
3246 size_t num_digits = yytxt.length (); | 3246 std::size_t num_digits = yytxt.length (); |
3247 | 3247 |
3248 if (num_digits <= 2) | 3248 if (num_digits <= 2) |
3249 bytes = 1; | 3249 bytes = 1; |
3250 else if (num_digits <= 4) | 3250 else if (num_digits <= 4) |
3251 bytes = 2; | 3251 bytes = 2; |
3257 else | 3257 else |
3258 { | 3258 { |
3259 unsigned_val = (yytxt[pos] == 'u'); | 3259 unsigned_val = (yytxt[pos] == 'u'); |
3260 std::string size_str = yytxt.substr (pos+1); | 3260 std::string size_str = yytxt.substr (pos+1); |
3261 yytxt = yytxt.substr (0, pos); | 3261 yytxt = yytxt.substr (0, pos); |
3262 size_t num_digits = yytxt.length (); | 3262 std::size_t num_digits = yytxt.length (); |
3263 | 3263 |
3264 if (size_str == "8" && num_digits <= 2) | 3264 if (size_str == "8" && num_digits <= 2) |
3265 bytes = 1; | 3265 bytes = 1; |
3266 else if (size_str == "16" && num_digits <= 4) | 3266 else if (size_str == "16" && num_digits <= 4) |
3267 bytes = 2; | 3267 bytes = 2; |
3426 std::string txt = flex_yytext (); | 3426 std::string txt = flex_yytext (); |
3427 | 3427 |
3428 txt.erase (std::remove_if (txt.begin (), txt.end (), is_space_or_tab), | 3428 txt.erase (std::remove_if (txt.begin (), txt.end (), is_space_or_tab), |
3429 txt.end ()); | 3429 txt.end ()); |
3430 | 3430 |
3431 size_t pos = txt.find ("@"); | 3431 std::size_t pos = txt.find ("@"); |
3432 | 3432 |
3433 std::string meth = txt.substr (0, pos); | 3433 std::string meth = txt.substr (0, pos); |
3434 std::string cls = txt.substr (pos + 1); | 3434 std::string cls = txt.substr (pos + 1); |
3435 | 3435 |
3436 if (iskeyword (meth) || fq_identifier_contains_keyword (cls)) | 3436 if (iskeyword (meth) || fq_identifier_contains_keyword (cls)) |
3673 { | 3673 { |
3674 YYSTYPE *lval = yyget_lval (m_scanner); | 3674 YYSTYPE *lval = yyget_lval (m_scanner); |
3675 return lval->tok_val; | 3675 return lval->tok_val; |
3676 } | 3676 } |
3677 | 3677 |
3678 size_t | 3678 std::size_t |
3679 base_lexer::pending_token_count (void) const | 3679 base_lexer::pending_token_count (void) const |
3680 { | 3680 { |
3681 return m_tokens.size (); | 3681 return m_tokens.size (); |
3682 } | 3682 } |
3683 | 3683 |