Skip to content

Commit c5d8415

Browse files
author
Zachary Scott
authored
Merge pull request #445 from aycabta/remove-offset
Remove offset from CodeObject
2 parents dd8b1a9 + 52e89c4 commit c5d8415

File tree

6 files changed

+3
-50
lines changed

6 files changed

+3
-50
lines changed

lib/rdoc/code_object.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ class RDoc::CodeObject
6969

7070
attr_reader :metadata
7171

72-
##
73-
# Offset in #file where this CodeObject was defined
74-
#--
75-
# TODO character or byte?
76-
77-
attr_accessor :offset
78-
7972
##
8073
# Sets the parent CodeObject
8174

lib/rdoc/parser/c.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
670670
tk.set_text body
671671
meth_obj.add_token tk
672672
meth_obj.comment = comment
673-
meth_obj.offset = offset
674673
meth_obj.line = file_content[0, offset].count("\n") + 1
675674

676675
body
@@ -689,7 +688,6 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
689688
tk.set_text body
690689
meth_obj.add_token tk
691690
meth_obj.comment = comment
692-
meth_obj.offset = offset
693691
meth_obj.line = file_content[0, offset].count("\n") + 1
694692

695693
body

lib/rdoc/parser/ruby.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ def new_comment comment
589589
# +comment+.
590590

591591
def parse_attr(context, single, tk, comment)
592-
offset = tk.seek
593592
line_no = tk.line_no
594593

595594
args = parse_symbol_arg 1
@@ -606,7 +605,6 @@ def parse_attr(context, single, tk, comment)
606605
end
607606

608607
att = create_attr context, single, name, rw, comment
609-
att.offset = offset
610608
att.line = line_no
611609

612610
read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
@@ -620,7 +618,6 @@ def parse_attr(context, single, tk, comment)
620618
# comment for each to +comment+.
621619

622620
def parse_attr_accessor(context, single, tk, comment)
623-
offset = tk.seek
624621
line_no = tk.line_no
625622

626623
args = parse_symbol_arg
@@ -642,7 +639,6 @@ def parse_attr_accessor(context, single, tk, comment)
642639

643640
for name in args
644641
att = create_attr context, single, name, rw, comment
645-
att.offset = offset
646642
att.line = line_no
647643
end
648644
end
@@ -651,7 +647,6 @@ def parse_attr_accessor(context, single, tk, comment)
651647
# Parses an +alias+ in +context+ with +comment+
652648

653649
def parse_alias(context, single, tk, comment)
654-
offset = tk.seek
655650
line_no = tk.line_no
656651

657652
skip_tkspace
@@ -680,7 +675,6 @@ def parse_alias(context, single, tk, comment)
680675
al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
681676
single == SINGLE)
682677
record_location al
683-
al.offset = offset
684678
al.line = line_no
685679

686680
read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
@@ -733,7 +727,6 @@ def parse_call_parameters(tk)
733727
# Parses a class in +context+ with +comment+
734728

735729
def parse_class container, single, tk, comment
736-
offset = tk.seek
737730
line_no = tk.line_no
738731

739732
declaration_context = container
@@ -748,7 +741,7 @@ def parse_class container, single, tk, comment
748741
case name = get_class_specification
749742
when 'self', container.name
750743
parse_statements container, SINGLE
751-
return # don't update offset or line
744+
return # don't update line
752745
else
753746
parse_class_singleton container, name, comment
754747
end
@@ -757,7 +750,6 @@ def parse_class container, single, tk, comment
757750
return
758751
end
759752

760-
cls.offset = offset
761753
cls.line = line_no
762754

763755
cls
@@ -845,7 +837,6 @@ def parse_class_singleton container, name, comment # :nodoc:
845837
# true, no found constants will be added to RDoc.
846838

847839
def parse_constant container, tk, comment, ignore_constants = false
848-
offset = tk.seek
849840
line_no = tk.line_no
850841

851842
name = tk.name
@@ -885,7 +876,6 @@ def parse_constant container, tk, comment, ignore_constants = false
885876

886877
value.replace body
887878
record_location con
888-
con.offset = offset
889879
con.line = line_no
890880
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
891881

@@ -950,7 +940,6 @@ def parse_constant_body container, constant # :nodoc:
950940
def parse_comment container, tk, comment
951941
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
952942
column = tk.char_no
953-
offset = tk.seek
954943
line_no = tk.line_no
955944

956945
text = comment.text
@@ -966,7 +955,6 @@ def parse_comment container, tk, comment
966955

967956
if co then
968957
co.singleton = singleton
969-
co.offset = offset
970958
co.line = line_no
971959
end
972960

@@ -1031,19 +1019,18 @@ def parse_comment_ghost container, text, name, column, line_no, # :nodoc:
10311019

10321020
def parse_comment_tomdoc container, tk, comment
10331021
return unless signature = RDoc::TomDoc.signature(comment)
1034-
offset = tk.seek
1022+
column = tk.char_no
10351023
line_no = tk.line_no
10361024

10371025
name, = signature.split %r%[ \(]%, 2
10381026

10391027
meth = RDoc::GhostMethod.new get_tkread, name
10401028
record_location meth
1041-
meth.offset = offset
10421029
meth.line = line_no
10431030

10441031
meth.start_collecting_tokens
10451032
indent = TkSPACE.new 0, 1, 1
1046-
indent.set_text " " * offset
1033+
indent.set_text " " * column
10471034

10481035
position_comment = TkCOMMENT.new 0, line_no, 1
10491036
position_comment.set_text "# File #{@top_level.relative_name}, line #{line_no}"
@@ -1183,7 +1170,6 @@ def parse_meta_attr(context, single, tk, comment)
11831170

11841171
def parse_meta_method(container, single, tk, comment)
11851172
column = tk.char_no
1186-
offset = tk.seek
11871173
line_no = tk.line_no
11881174

11891175
start_collecting_tokens
@@ -1200,7 +1186,6 @@ def parse_meta_method(container, single, tk, comment)
12001186

12011187
meth = RDoc::MetaMethod.new get_tkread, name
12021188
record_location meth
1203-
meth.offset = offset
12041189
meth.line = line_no
12051190
meth.singleton = singleton
12061191

@@ -1291,7 +1276,6 @@ def parse_method(container, single, tk, comment)
12911276
added_container = false
12921277
name = nil
12931278
column = tk.char_no
1294-
offset = tk.seek
12951279
line_no = tk.line_no
12961280

12971281
start_collecting_tokens
@@ -1309,7 +1293,6 @@ def parse_method(container, single, tk, comment)
13091293
meth.singleton = single == SINGLE ? true : singleton
13101294

13111295
record_location meth
1312-
meth.offset = offset
13131296
meth.line = line_no
13141297

13151298
meth.start_collecting_tokens

test/test_rdoc_code_object.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@ def test_metadata
276276
assert_equal 'not_rdoc', @co.metadata['markup']
277277
end
278278

279-
def test_offset
280-
@c1_m.offset = 5
281-
282-
assert_equal 5, @c1_m.offset
283-
end
284-
285279
def test_options
286280
assert_kind_of RDoc::Options, @co.options
287281

test/test_rdoc_parser_c.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,6 @@ def test_find_body_define
11391139
assert_equal 'my_method', other_function.name
11401140
assert_equal 'a comment for rb_other_function', other_function.comment.text
11411141
assert_equal '()', other_function.params
1142-
assert_equal 118, other_function.offset
11431142
assert_equal 8, other_function.line
11441143

11451144
code = other_function.token_stream.first.text
@@ -1173,7 +1172,6 @@ def test_find_body_define_comment
11731172
assert_equal 'my_method', other_function.name
11741173
assert_equal 'a comment for other_function', other_function.comment.text
11751174
assert_equal '()', other_function.params
1176-
assert_equal 39, other_function.offset
11771175
assert_equal 4, other_function.line
11781176

11791177
code = other_function.token_stream.first.text
@@ -1402,7 +1400,6 @@ def test_handle_method_args_minus_1
14021400

14031401
assert_equal 'm', m.name
14041402
assert_equal @top_level, m.file
1405-
assert_equal 115, m.offset
14061403
assert_equal 7, m.line
14071404

14081405
assert_equal '(p1)', m.params

test/test_rdoc_parser_ruby.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ def test_parse_alias
297297
assert_equal klass, alas.parent
298298
assert_equal 'comment', alas.comment
299299
assert_equal @top_level, alas.file
300-
assert_equal 0, alas.offset
301300
assert_equal 1, alas.line
302301
end
303302

@@ -365,7 +364,6 @@ def test_parse_attr
365364
assert_equal 'foo', foo.name
366365
assert_equal 'my attr', foo.comment.text
367366
assert_equal @top_level, foo.file
368-
assert_equal 0, foo.offset
369367
assert_equal 1, foo.line
370368
end
371369

@@ -404,7 +402,6 @@ def test_parse_attr_accessor
404402
assert_equal 'RW', foo.rw
405403
assert_equal 'my attr', foo.comment.text
406404
assert_equal @top_level, foo.file
407-
assert_equal 0, foo.offset
408405
assert_equal 1, foo.line
409406

410407
bar = klass.attributes.last
@@ -617,7 +614,6 @@ def test_parse_class
617614
assert_equal 'Foo', foo.full_name
618615
assert_equal 'my class', foo.comment.text
619616
assert_equal [@top_level], foo.in_files
620-
assert_equal 0, foo.offset
621617
assert_equal 1, foo.line
622618
end
623619

@@ -637,7 +633,6 @@ class << self
637633

638634
c = @top_level.classes.first
639635
assert_equal 'C', c.full_name
640-
assert_equal 0, c.offset
641636
assert_equal 1, c.line
642637
end
643638

@@ -727,7 +722,6 @@ def test_parse_class_nodoc
727722
assert_equal 'Foo', foo.full_name
728723
assert_empty foo.comment
729724
assert_equal [@top_level], foo.in_files
730-
assert_equal 0, foo.offset
731725
assert_equal 1, foo.line
732726
end
733727

@@ -920,7 +914,6 @@ def foo; end
920914
assert_equal %w[A::B A::d], modules.map { |c| c.full_name }
921915

922916
b = modules.first
923-
assert_equal 10, b.offset
924917
assert_equal 2, b.line
925918

926919
# make sure method/alias was not added to enclosing class/module
@@ -1083,7 +1076,6 @@ def test_parse_comment_attr
10831076
assert_equal 'RW', foo.rw
10841077
assert_equal 'my attr', foo.comment.text
10851078
assert_equal @top_level, foo.file
1086-
assert_equal 0, foo.offset
10871079
assert_equal 1, foo.line
10881080

10891081
assert_equal nil, foo.viewer
@@ -1147,7 +1139,6 @@ def test_parse_comment_method
11471139
assert_equal 'foo', foo.name
11481140
assert_equal 'my method', foo.comment.text
11491141
assert_equal @top_level, foo.file
1150-
assert_equal 0, foo.offset
11511142
assert_equal 1, foo.line
11521143

11531144
assert_equal [], foo.aliases
@@ -1223,7 +1214,6 @@ def test_parse_constant
12231214

12241215
assert_equal 'A', foo.name
12251216
assert_equal @top_level, foo.file
1226-
assert_equal 0, foo.offset
12271217
assert_equal 1, foo.line
12281218
end
12291219

@@ -1389,7 +1379,6 @@ def test_parse_meta_method
13891379
assert_equal 'foo', foo.name
13901380
assert_equal 'my method', foo.comment.text
13911381
assert_equal @top_level, foo.file
1392-
assert_equal 0, foo.offset
13931382
assert_equal 1, foo.line
13941383

13951384
assert_equal [], foo.aliases
@@ -1587,7 +1576,6 @@ def test_parse_method
15871576
assert_equal 'foo', foo.name
15881577
assert_equal 'my method', foo.comment.text
15891578
assert_equal @top_level, foo.file
1590-
assert_equal 0, foo.offset
15911579
assert_equal 1, foo.line
15921580

15931581
assert_equal [], foo.aliases

0 commit comments

Comments
 (0)