-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyard_extensions.rb
103 lines (95 loc) · 3.76 KB
/
yard_extensions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# frozen_string_literal: true
unless defined?(RICE_EXT_LOADED)
RICE_EXT_LOADED = true
# handle rice classes
class RiceClassHandler < YARD::Handlers::C::Base
MATCH = /(rb_c[\w.]+)\s* = \s*(?:Rice::)?define_class<(.+?)>\s*
\(
\s*"(\w[\wd:]+)"\s*
(?:,\s*(\w[\wd]*)\s*)?
\)/mx.freeze
MATCH_UNDER = /(rb_c[\w.]+)\s* = \s*(?:Rice::)?define_class_under<(.+?)>\s*
\(
\s*([\w.]+)\s*,
\s*"(\w[\wd]+)"
(?:\s*,\s*(\w[\wd]*)\s*)?
\s*\)/mx.freeze
MATCH_ENUM = /(rb_c[\w.]+)\s* = \s*(?:Rice::)?define_enum<(.+?)>\s*
\(
\s*"(\w[\wd:]+)"\s*
(?:,\s*([\w.]+)\s*)?
\)/mx.freeze
handles MATCH
handles MATCH_UNDER
handles MATCH_ENUM
statement_class BodyStatement
process do
statement.source.scan(MATCH) do |var_name, cpp_type, class_name, parent|
cls = handle_class(var_name, class_name, parent&.strip || "rb_cObject")
register_docstring(cls, "Wraps +#{cpp_type}+")
end
statement.source.scan(MATCH_UNDER) do |var_name, cpp_type, in_module, class_name, parent|
cls = handle_class(var_name, class_name, parent&.strip || "rb_cObject", in_module)
register_docstring(cls, "Wraps +#{cpp_type}+")
end
statement.source.scan(MATCH_ENUM) do |var_name, cpp_type, class_name, in_module|
cls = handle_class(var_name, class_name, "rb_cObject", in_module&.strip || "rb_cObject")
register_docstring(cls, "Wraps +#{cpp_type}+")
from_int = handle_method("singleton_method", var_name, "from_int", "rice_from_int")
register_docstring(
from_int,
[
"Returns ruby representation of a +#{cpp_type}+ enum member",
"@param value [Integer] a valid +#{cpp_type}+",
"@return [#{cls}]"
]
)
each = handle_method("singleton_method", var_name, "each", "rice_each")
register_docstring(
each,
[
"Iterates over all +#{cpp_type}+ enum members",
"@yieldparam value [#{cls}] ruby representation of a +#{cpp_type}+ enum member",
"@return [nil]"
]
)
end
end
end
# handle rice modules
class RiceModuleHandler < YARD::Handlers::C::Base
MATCH = /(rb_m[\w.]+)\s* = \s*(?:Rice::)?define_module\s*
\(
\s*"(\w[\wd:]+)"\s*
\)/mx.freeze
MATCH_UNDER = /(rb_m[\w.]+)\s* = \s*(?:Rice::)?define_module_under\s*
\(
\s*([\w.]+)\s*,
\s*"(\w[\wd]+)"
\s*\)/mx.freeze
handles MATCH
handles MATCH_UNDER
statement_class BodyStatement
process do
statement.source.scan(MATCH) do |var_name, module_name|
handle_module(var_name, module_name)
end
statement.source.scan(MATCH_UNDER) do |var_name, in_module, module_name|
handle_module(var_name, module_name, in_module)
end
end
end
# Handles methods
# class RiceMethodHandler < YARD::Handlers::C::Base
# handles(/./)
#
# statement_class BodyStatement # Comment # ToplevelStatement # BodyStatement
#
# process do
# puts statement.source
# puts "----------------------------------------------------"
# # source = RbGCCXML.parse("/home/vladimir/jsoncons/ext/jsoncons/jsoncons.cpp", includes: ["/home/vladimir/jsoncons/lib/jsoncons/jsoncons/include", "/home/vladimir/.rvm/gems/ruby-2.7.0/gems/rice-4.0.4/include", "/home/vladimir/.rvm/rubies/ruby-2.7.0/include/ruby-2.7.0", "/home/vladimir/.rvm/rubies/ruby-2.7.0/include/ruby-2.7.0/x86_64-linux"], cxxflags: ['-x c++', '-fpermissive'], clangpp_path: '/usr/bin/g++')
# # source.functions(/Init_jsoncons/).return_type.to_cpp
# end
# end
end