1 /* -----------------------------------------------------------------------------
2 * This file is part of SWIG, which is licensed as a whole under version 3
3 * (or any later version) of the GNU General Public License. Some additional
4 * terms also apply to certain portions of SWIG. The full details of the SWIG
5 * license and copyrights can be found in the LICENSE and COPYRIGHT files
6 * included with the SWIG source code as distributed by the SWIG developers
7 * and at http://www.swig.org/legal.html.
8 *
9 * doxytranslator.cxx
10 *
11 * Module to return documentation for nodes formatted for various documentation
12 * systems.
13 * ----------------------------------------------------------------------------- */
14
15 #include "doxytranslator.h"
16
DoxygenTranslator(int flags)17 DoxygenTranslator::DoxygenTranslator(int flags) : m_flags(flags), parser((flags &debug_parser) != 0) {
18 }
19
20
~DoxygenTranslator()21 DoxygenTranslator::~DoxygenTranslator() {
22 }
23
24
hasDocumentation(Node * node)25 bool DoxygenTranslator::hasDocumentation(Node *node) {
26 return getDoxygenComment(node) != NULL;
27 }
28
29
getDoxygenComment(Node * node)30 String *DoxygenTranslator::getDoxygenComment(Node *node) {
31 return Getattr(node, "doxygen");
32 }
33
34 /**
35 * Indent all lines in the comment by given indentation string
36 */
extraIndentation(String * comment,const_String_or_char_ptr indentationString)37 void DoxygenTranslator::extraIndentation(String *comment, const_String_or_char_ptr indentationString) {
38 if (indentationString || Len(indentationString) > 0) {
39 int len = Len(comment);
40 bool trailing_newline = len > 0 && *(Char(comment) + len - 1) == '\n';
41 Insert(comment, 0, indentationString);
42 String *replace = NewStringf("\n%s", indentationString);
43 Replaceall(comment, "\n", replace);
44 if (trailing_newline) {
45 len = Len(comment);
46 Delslice(comment, len - 2, len); // Remove added trailing spaces on last line
47 }
48 Delete(replace);
49 }
50 }
51
getDocumentation(Node * node,const_String_or_char_ptr indentationString)52 String *DoxygenTranslator::getDocumentation(Node *node, const_String_or_char_ptr indentationString) {
53
54 if (!hasDocumentation(node)) {
55 return NewString("");
56 }
57
58 String *documentation = makeDocumentation(node);
59 extraIndentation(documentation, indentationString);
60 return documentation;
61 }
62
63
printTree(const DoxygenEntityList & entityList)64 void DoxygenTranslator::printTree(const DoxygenEntityList &entityList) {
65
66 for (DoxygenEntityListCIt p = entityList.begin(); p != entityList.end(); p++) {
67 p->printEntity(0);
68 }
69 }
70