summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2024-12-03 09:03:17 +0900
committerHiroshi SHIBATA <[email protected]>2024-12-03 10:59:32 +0900
commitd85e8b53393779f7cc7aa5779387fc68ac85dc47 (patch)
tree1a6bb1b716cff14f434ab6eae92cc7b07b208d8a
parent59d23174c01d201b4a1bbc0eaab32b167a3cb975 (diff)
Reapply "[ruby/rdoc] fix: C variables should never show up in Ancestors tree"
This reverts commit 0fe82ae087130d7f360cc0607be93995cedbdb16.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12233
-rw-r--r--lib/rdoc/rdoc.rb2
-rw-r--r--lib/rdoc/store.rb12
-rw-r--r--test/rdoc/test_rdoc_store.rb20
3 files changed, 34 insertions, 0 deletions
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index 88ae55b409..a910215ff6 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -415,6 +415,8 @@ The internal error was:
parse_file filename
end.compact
+ @store.resolve_c_superclasses
+
@stats.done_adding
@options = original_options
diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb
index cd27d47dd1..e85bc9d33a 100644
--- a/lib/rdoc/store.rb
+++ b/lib/rdoc/store.rb
@@ -198,6 +198,18 @@ class RDoc::Store
end
##
+ # Make sure any references to C variable names are resolved to the corresponding class.
+ #
+
+ def resolve_c_superclasses
+ @classes_hash.each_value do |klass|
+ if klass.superclass.is_a?(String) && (candidate = find_c_enclosure(klass.superclass))
+ klass.superclass = candidate
+ end
+ end
+ end
+
+ ##
# Sets the parser of +absolute_name+, unless it from a source code file.
def update_parser_of_file(absolute_name, parser)
diff --git a/test/rdoc/test_rdoc_store.rb b/test/rdoc/test_rdoc_store.rb
index 50e8667d81..2665f163e4 100644
--- a/test/rdoc/test_rdoc_store.rb
+++ b/test/rdoc/test_rdoc_store.rb
@@ -281,6 +281,26 @@ class TestRDocStore < XrefTestCase
assert_nil @s.find_c_enclosure('cObject')
end
+ def test_resolve_c_superclasses
+ # first parse a child that references an unknown parent
+ c_file1 = @s.add_file 'ext1.c'
+ c_file1.add_class RDoc::NormalClass, 'Child', 'cExternParent'
+
+ # then parse the parent and register the C variable name as a C enclosure
+ c_file2 = @s.add_file 'ext2.c'
+ parent = c_file2.add_class RDoc::NormalClass, 'Parent', 'rb_cObject'
+
+ @s.add_c_enclosure('cExternParent', parent)
+
+ # at this point, the child's superclass is still the name of the C variable
+ assert_equal("cExternParent", @s.classes_hash['Child'].superclass)
+
+ @s.resolve_c_superclasses
+
+ # now the ancestor tree correctly references the NormalClass objects
+ assert_equal(parent, @s.classes_hash['Child'].superclass)
+ end
+
def test_find_class_named
assert_equal @c1, @store.find_class_named('C1')