Debian Codegraph @

CodeLite/cpp_comment_creator.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2008 by Eran Ifrah
5 // file name : cpp_comment_creator.cpp
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25 #include "cpp_comment_creator.h"
26 #include "language.h"
27 #include "precompiled_header.h"
28 #include <vector>
29 #include <wx/datetime.h>
30
31 #define trimMe(str) \
32 { \
33 str = str.Trim(); \
34 str = str.Trim(false); \
35 }
36
37 CppCommentCreator::CppCommentCreator(TagEntryPtr tag, wxChar keyPrefix)
38 : CommentCreator(keyPrefix)
39 , m_tag(tag)
40 {
41 }
42
43 CppCommentCreator::~CppCommentCreator() {}
44
45 wxString CppCommentCreator::CreateComment()
46 {
47 if(m_tag->GetKind() == wxT("class") || m_tag->GetKind() == wxT("struct")) {
48 return wxT("$(ClassPattern)\n");
49 } else if(m_tag->IsMethod()) {
50 return FunctionComment();
51 } else {
52 return wxEmptyString;
53 }
54 }
55
56 wxString CppCommentCreator::FunctionComment()
57 {
58 wxString comment;
59
60 // parse the function signature
61 std::vector<TagEntryPtr> tags;
62 Language* lang = LanguageST::Get();
63 lang->GetLocalVariables(m_tag->GetSignature(), tags, true);
64
65 comment << wxT("$(FunctionPattern)\n");
66 for(size_t i = 0; i < tags.size(); i++)
67 comment << wxT(" * ") << m_keyPrefix << wxT("param ") << tags.at(i)->GetName() << wxT("\n");
68
69 if(m_tag->GetKind() == wxT("function")) {
70 clFunction f;
71 if(lang->FunctionFromPattern(m_tag, f)) {
72 wxString type = _U(f.m_returnValue.m_type.c_str());
73 trimMe(type);
74 if(type != wxT("void")) { // void has no return value
75 comment << wxT(" * ") << m_keyPrefix << wxT("return \n");
76 }
77 }
78
79 } else {
80 Variable var;
81 lang->VariableFromPattern(m_tag->GetPattern(), m_tag->GetName(), var);
82 wxString type = _U(var.m_type.c_str());
83 wxString name = _U(var.m_name.c_str());
84 trimMe(type);
85 trimMe(name);
86
87 if(type != wxT("void") // void has no return value
88 && name != type) { // and not a constructor
89 comment << wxT(" * ") << m_keyPrefix << wxT("return \n");
90 }
91 }
92 return comment;
93 }