comparison gcc/edit-context.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Determining the results of applying fix-it hints. 1 /* Determining the results of applying fix-it hints.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc. 2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
180 180
181 class line_event 181 class line_event
182 { 182 {
183 public: 183 public:
184 line_event (int start, int next, int len) : m_start (start), 184 line_event (int start, int next, int len) : m_start (start),
185 m_next (next), m_delta (len - (next - start)) {} 185 m_delta (len - (next - start)) {}
186 186
187 int get_effective_column (int orig_column) const 187 int get_effective_column (int orig_column) const
188 { 188 {
189 if (orig_column >= m_start) 189 if (orig_column >= m_start)
190 return orig_column += m_delta; 190 return orig_column += m_delta;
192 return orig_column; 192 return orig_column;
193 } 193 }
194 194
195 private: 195 private:
196 int m_start; 196 int m_start;
197 int m_next;
198 int m_delta; 197 int m_delta;
199 }; 198 };
200 199
201 /* Forward decls. */ 200 /* Forward decls. */
202 201
420 edited_line *el = get_line (line_num); 419 edited_line *el = get_line (line_num);
421 if (el) 420 if (el)
422 el->print_content (pp); 421 el->print_content (pp);
423 else 422 else
424 { 423 {
425 int len; 424 char_span line = location_get_source_line (m_filename, line_num);
426 const char *line
427 = location_get_source_line (m_filename, line_num, &len);
428 if (!line) 425 if (!line)
429 return false; 426 return false;
430 for (int i = 0; i < len; i++) 427 for (size_t i = 0; i < line.length (); i++)
431 pp_character (pp, line[i]); 428 pp_character (pp, line[i]);
432 } 429 }
433 if (line_num < line_count) 430 if (line_num < line_count)
434 pp_character (pp, '\n'); 431 pp_character (pp, '\n');
435 } 432 }
541 last_changed_line_in_run); 538 last_changed_line_in_run);
542 } 539 }
543 else 540 else
544 { 541 {
545 /* Unchanged line. */ 542 /* Unchanged line. */
546 int line_len; 543 char_span old_line = location_get_source_line (m_filename, line_num);
547 const char *old_line 544 print_diff_line (pp, ' ', old_line.get_buffer (), old_line.length ());
548 = location_get_source_line (m_filename, line_num, &line_len);
549 print_diff_line (pp, ' ', old_line, line_len);
550 line_num++; 545 line_num++;
551 } 546 }
552 } 547 }
553 548
554 return new_num_lines - old_num_lines; 549 return new_num_lines - old_num_lines;
572 { 567 {
573 edited_line *el_in_run = get_line (line_num); 568 edited_line *el_in_run = get_line (line_num);
574 gcc_assert (el_in_run); 569 gcc_assert (el_in_run);
575 if (el_in_run->actually_edited_p ()) 570 if (el_in_run->actually_edited_p ())
576 { 571 {
577 int line_len; 572 char_span old_line = location_get_source_line (m_filename, line_num);
578 const char *old_line 573 print_diff_line (pp, '-', old_line.get_buffer (),
579 = location_get_source_line (m_filename, line_num, &line_len); 574 old_line.length ());
580 print_diff_line (pp, '-', old_line, line_len);
581 } 575 }
582 } 576 }
583 pp_string (pp, colorize_stop (pp_show_color (pp))); 577 pp_string (pp, colorize_stop (pp_show_color (pp)));
584 578
585 /* Show new version of lines. */ 579 /* Show new version of lines. */
669 if (m_num_lines == -1) 663 if (m_num_lines == -1)
670 { 664 {
671 m_num_lines = 0; 665 m_num_lines = 0;
672 while (true) 666 while (true)
673 { 667 {
674 int line_size; 668 char_span line
675 const char *line 669 = location_get_source_line (m_filename, m_num_lines + 1);
676 = location_get_source_line (m_filename, m_num_lines + 1,
677 &line_size);
678 if (line) 670 if (line)
679 m_num_lines++; 671 m_num_lines++;
680 else 672 else
681 break; 673 break;
682 } 674 }
693 : m_line_num (line_num), 685 : m_line_num (line_num),
694 m_content (NULL), m_len (0), m_alloc_sz (0), 686 m_content (NULL), m_len (0), m_alloc_sz (0),
695 m_line_events (), 687 m_line_events (),
696 m_predecessors () 688 m_predecessors ()
697 { 689 {
698 const char *line = location_get_source_line (filename, line_num, 690 char_span line = location_get_source_line (filename, line_num);
699 &m_len);
700 if (!line) 691 if (!line)
701 return; 692 return;
693 m_len = line.length ();
702 ensure_capacity (m_len); 694 ensure_capacity (m_len);
703 memcpy (m_content, line, m_len); 695 memcpy (m_content, line.get_buffer (), m_len);
704 ensure_terminated (); 696 ensure_terminated ();
705 } 697 }
706 698
707 /* edited_line's dtor. */ 699 /* edited_line's dtor. */
708 700