Skip to content

Commit 8014a1e

Browse files
extract comments
1 parent 95ba740 commit 8014a1e

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/Cppyy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ namespace Cppyy {
9090
CPPYY_IMPORT
9191
TCppScope_t GetTypeScope(TCppScope_t klass);
9292
CPPYY_IMPORT
93+
std::string GetDoc(TCppScope_t scope);
94+
CPPYY_IMPORT
9395
TCppScope_t GetNamed(const std::string& scope_name,
9496
TCppScope_t parent_scope = 0);
9597
CPPYY_IMPORT

src/TypeHints.cxx

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ void handle_variable(Cppyy::TCppScope_t var, std::ostringstream &file, int inden
104104
void handle_variable(Cppyy::TCppScope_t var, std::ostringstream &file, int indent = 0) {
105105
std::string indentation_str = indentation(indent);
106106

107+
std::string doc = Cppyy::GetDoc(var);
108+
if (!doc.empty()) {
109+
file << indentation_str
110+
<< "# "
111+
<< replace_all(doc, "\n", "\n# ")
112+
<< "\n";
113+
}
107114
file << indentation_str
108115
<< Cppyy::GetFinalName(var)
109116
<< ": "
@@ -114,6 +121,14 @@ void handle_variable(Cppyy::TCppScope_t var, std::ostringstream &file, int inden
114121
void handle_typedef(Cppyy::TCppScope_t var, std::ostringstream &file, int indent) {
115122
std::string indentation_str = indentation(indent);
116123

124+
std::string doc = Cppyy::GetDoc(var);
125+
if (!doc.empty()) {
126+
file << indentation_str
127+
<< "# "
128+
<< replace_all(doc, "\n", "\n# ")
129+
<< "\n";
130+
}
131+
117132
file << indentation_str
118133
<< Cppyy::GetMethodName(var)
119134
<< " = "
@@ -147,8 +162,7 @@ void handle_function(Cppyy::TCppScope_t fn, std::ostringstream &file, int indent
147162
bool prepend_comma = false;
148163
if (Cppyy::IsMethod(fn) && !Cppyy::IsStaticMethod(fn)) {
149164
// add the implicit self argument
150-
file << "self: "
151-
<< pythonize_type_name(class_name);
165+
file << "self: Self";
152166
prepend_comma = true;
153167
}
154168
for (size_t i = 0, nArgs = Cppyy::GetMethodNumArgs(fn); i < nArgs; i++) {
@@ -168,7 +182,16 @@ void handle_function(Cppyy::TCppScope_t fn, std::ostringstream &file, int indent
168182
}
169183
file << ") -> "
170184
<< pythonize_type_name(Cppyy::GetMethodReturnTypeAsString(fn))
171-
<< ": ...\n";
185+
<< ":\n";
186+
std::string doc = Cppyy::GetDoc(fn);
187+
if (!doc.empty()) {
188+
file << indentation_str
189+
<< " \"\"\""
190+
<< replace_all(doc, "\"\"\"", "\\\"\\\"\\\"") // replace """ -> \"\"\"
191+
<< "\"\"\"\n";
192+
}
193+
file << indentation_str
194+
<< " ...\n";
172195
}
173196

174197
void handle_templates(Cppyy::TCppScope_t tmpl, std::ostringstream &file, int indent) {
@@ -231,9 +254,18 @@ void handle_templates(Cppyy::TCppScope_t tmpl, std::ostringstream &file, int ind
231254
}
232255
file << ") -> "
233256
<< pythonize_type_name(Cppyy::GetMethodReturnTypeAsString(tmpl))
234-
<< ": ...\n";
257+
<< ":\n";
258+
std::string doc = Cppyy::GetDoc(tmpl);
259+
if (!doc.empty()) {
260+
file << indentation_str
261+
<< " \"\"\""
262+
<< replace_all(doc, "\"\"\"", "\\\"\\\"\\\"") // replace """ -> \"\"\"
263+
<< "\"\"\"\n";
264+
}
265+
file << indentation_str
266+
<< " ...\n";
235267
} else {
236-
// is templated class
268+
// is templated class ???
237269
}
238270
}
239271

@@ -257,6 +289,13 @@ void handle_class(Cppyy::TCppScope_t cls, std::ostringstream &file, int indent)
257289
file << "]";
258290
}
259291
file << ":\n";
292+
std::string doc = Cppyy::GetDoc(cls);
293+
if (!doc.empty()) {
294+
file << indentation_str
295+
<< " \"\"\""
296+
<< replace_all(doc, "\"\"\"", "\\\"\\\"\\\"") // replace """ -> \"\"\"
297+
<< "\"\"\"\n\n";
298+
}
260299

261300
std::vector<Cppyy::TCppScope_t> members;
262301
Cppyy::GetDatamembers(cls, members);
@@ -284,9 +323,17 @@ void handle_class(Cppyy::TCppScope_t cls, std::ostringstream &file, int indent)
284323
}
285324

286325
void handle_namespace(Cppyy::TCppScope_t ns, std::ostringstream &file, int indent) {
326+
std::string indentation_str = indentation(indent);
287327
std::vector<Cppyy::TCppScope_t> members;
288328
Cppyy::GetMemberInNamespace(ns, members);
289329
file << "class " << Cppyy::GetMethodName(ns) << ":\n";
330+
std::string doc = Cppyy::GetDoc(ns);
331+
if (!doc.empty()) {
332+
file << indentation_str
333+
<< " \"\"\""
334+
<< replace_all(doc, "\"\"\"", "\\\"\\\"\\\"") // replace """ -> \"\"\"
335+
<< "\"\"\"\n\n";
336+
}
290337
for (Cppyy::TCppScope_t s: members)
291338
handle_scope(s, file, indent + 1);
292339
}

0 commit comments

Comments
 (0)