Doxygen
Loading...
Searching...
No Matches
definition.cpp File Reference
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <string>
#include <optional>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include "anchor.h"
#include "md5.h"
#include "regex.h"
#include "config.h"
#include "definitionimpl.h"
#include "doxygen.h"
#include "language.h"
#include "message.h"
#include "portable.h"
#include "outputlist.h"
#include "code.h"
#include "util.h"
#include "groupdef.h"
#include "pagedef.h"
#include "section.h"
#include "htags.h"
#include "parserintf.h"
#include "debug.h"
#include "vhdldocgen.h"
#include "memberlist.h"
#include "namespacedef.h"
#include "filedef.h"
#include "dirdef.h"
#include "reflist.h"
#include "utf8.h"
#include "indexlist.h"
#include "fileinfo.h"
Include dependency graph for definition.cpp:

Go to the source code of this file.

Classes

class  DefinitionImpl::Private
 Private data associated with a Symbol DefinitionImpl object. More...
class  FilterCache
struct  FilterCache::FilterCacheItem

Functions

static bool matchExcludedSymbols (const QCString &name)
static void addToMap (const QCString &name, Definition *d)
static void removeFromMap (const QCString &name, Definition *d)
bool readCodeFragment (const QCString &fileName, bool isMacro, int &startLine, int &endLine, QCString &result)
 Reads a fragment from file fileName starting with line startLine and ending with line endLine.
static MemberVector refMapToVector (const std::unordered_map< std::string, MemberDef * > &map)
static bool stripWord (QCString &s, QCString w)
static QCString abbreviate (const QCString &s, const QCString &name)
DefinitiontoDefinition (DefinitionMutable *dm)
DefinitionMutabletoDefinitionMutable (Definition *d)

Variables

static std::recursive_mutex g_qualifiedNameMutex
static std::mutex g_memberReferenceMutex

Function Documentation

◆ abbreviate()

QCString abbreviate ( const QCString & s,
const QCString & name )
static

Definition at line 1620 of file definition.cpp.

1621{
1622 QCString scopelessName=name;
1623 int i=scopelessName.findRev("::");
1624 if (i!=-1) scopelessName=scopelessName.mid(i+2);
1625 QCString result=s;
1626 result=result.stripWhiteSpace();
1627 // strip trailing .
1628 if (!result.isEmpty() && result.at(result.length()-1)=='.')
1629 result=result.left(result.length()-1);
1630
1631 // strip any predefined prefix
1632 const StringVector &briefDescAbbrev = Config_getList(ABBREVIATE_BRIEF);
1633 for (const auto &p : briefDescAbbrev)
1634 {
1635 QCString str = substitute(p,"$name",scopelessName); // replace $name with entity name
1636 str += " ";
1637 stripWord(result,str);
1638 }
1639
1640 // capitalize first character
1641 if (!result.isEmpty())
1642 {
1643 char c = result[0];
1644 if (c >= 'a' && c <= 'z') result[0] += 'A' - 'a';
1645 }
1646
1647 return result;
1648}
This is an alternative implementation of QCString.
Definition qcstring.h:101
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:593
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:96
QCString left(size_t len) const
Definition qcstring.h:229
#define Config_getList(name)
Definition config.h:38
std::vector< std::string > StringVector
Definition containers.h:33
static bool stripWord(QCString &s, QCString w)
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:571

References QCString::at(), Config_getList, QCString::findRev(), QCString::isEmpty(), QCString::left(), QCString::length(), QCString::mid(), QCString::stripWhiteSpace(), stripWord(), and substitute().

Referenced by Definition::briefDescription(), DefinitionAliasMixin< Base >::briefDescription(), DefinitionImpl::briefDescription(), DefinitionMixin< Base >::briefDescription(), and DefinitionImpl::operator=().

◆ addToMap()

void addToMap ( const QCString & name,
Definition * d )
static

Definition at line 219 of file definition.cpp.

220{
221 bool vhdlOpt = Config_getBool(OPTIMIZE_OUTPUT_VHDL);
222 QCString symbolName = name;
223 int index=computeQualifiedIndex(symbolName);
224 if (!vhdlOpt && index!=-1) symbolName=symbolName.mid(index+2);
225 if (!symbolName.isEmpty())
226 {
227 //printf("adding symbol %s\n",qPrint(symbolName));
228 Doxygen::symbolMap->add(symbolName,d);
229
230 d->_setSymbolName(symbolName);
231 }
232}
virtual void _setSymbolName(const QCString &name)=0
static SymbolMap< Definition > * symbolMap
Definition doxygen.h:124
#define Config_getBool(name)
Definition config.h:33
int computeQualifiedIndex(const QCString &name)
Return the index of the last :: in the string name that is still before the first <.
Definition util.cpp:6824

References Definition::_setSymbolName(), computeQualifiedIndex(), Config_getBool, QCString::isEmpty(), QCString::mid(), DefinitionImpl::name(), Doxygen::symbolMap, and DefinitionImpl::symbolName().

Referenced by DefinitionImpl::DefinitionImpl(), DefinitionImpl::DefinitionImpl(), and DefinitionAliasImpl::init().

◆ matchExcludedSymbols()

bool matchExcludedSymbols ( const QCString & name)
static

Definition at line 158 of file definition.cpp.

159{
160 const StringVector &exclSyms = Config_getList(EXCLUDE_SYMBOLS);
161 if (exclSyms.empty()) return FALSE; // nothing specified
162 const std::string &symName = name.str();
163 for (const auto &pat : exclSyms)
164 {
165 QCString pattern = pat;
166 bool forceStart=FALSE;
167 bool forceEnd=FALSE;
168 if (pattern.at(0)=='^')
169 {
170 pattern = pattern.mid(1);
171 forceStart = true;
172 }
173 if (pattern.at(pattern.length() - 1) == '$')
174 {
175 pattern = pattern.left(pattern.length() - 1);
176 forceEnd = true;
177 }
178 if (pattern.find('*')!=-1) // wildcard mode
179 {
180 const reg::Ex re(substitute(pattern,"*",".*").str());
182 if (reg::search(symName,match,re)) // wildcard match
183 {
184 size_t ui = match.position();
185 size_t pl = match.length();
186 size_t sl = symName.length();
187 if ((ui==0 || pattern.at(0)=='*' || (!isId(symName.at(ui-1)) && !forceStart)) &&
188 (ui+pl==sl || pattern.at(pattern.length()-1)=='*' || (!isId(symName.at(ui+pl)) && !forceEnd))
189 )
190 {
191 //printf("--> name=%s pattern=%s match at %d\n",qPrint(symName),qPrint(pattern),i);
192 return TRUE;
193 }
194 }
195 }
196 else if (!pattern.isEmpty()) // match words
197 {
198 size_t i = symName.find(pattern.str());
199 if (i!=std::string::npos) // we have a match!
200 {
201 size_t ui=i;
202 size_t pl=pattern.length();
203 size_t sl=symName.length();
204 // check if it is a whole word match
205 if ((ui==0 || (!isId(symName.at(ui-1)) && !forceStart)) &&
206 (ui+pl==sl || (!isId(symName.at(ui+pl)) && !forceEnd))
207 )
208 {
209 //printf("--> name=%s pattern=%s match at %d\n",qPrint(symName),qPrint(pattern),i);
210 return TRUE;
211 }
212 }
213 }
214 }
215 //printf("--> name=%s: no match\n",name);
216 return FALSE;
217}
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
const std::string & str() const
Definition qcstring.h:552
Class representing a regular expression.
Definition regex.h:39
Object representing the matching results.
Definition regex.h:151
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:844
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:855
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
bool isId(int c)
Definition util.h:207

References QCString::at(), Config_getList, FALSE, QCString::find(), QCString::isEmpty(), isId(), QCString::left(), QCString::length(), QCString::mid(), DefinitionImpl::name(), reg::search(), QCString::str(), substitute(), and TRUE.

Referenced by DefinitionImpl::DefinitionImpl().

◆ readCodeFragment()

bool readCodeFragment ( const QCString & fileName,
bool isMacro,
int & startLine,
int & endLine,
QCString & result )

Reads a fragment from file fileName starting with line startLine and ending with line endLine.

Reads a fragment of code from file fileName starting at line startLine and ending at line endLine (inclusive). The fragment is stored in result. If FALSE is returned the code fragment could not be found.

The file is scanned for a opening bracket ('{') from startLine onward The line actually containing the bracket is returned via startLine. The file is scanned for a closing bracket ('}') from endLine backward. The line actually containing the bracket is returned via endLine. Note that for VHDL code the bracket search is not done.

Definition at line 756 of file definition.cpp.

758{
759 bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
760 QCString filter = getFileFilter(fileName,TRUE);
761 bool usePipe = !filter.isEmpty() && filterSourceFiles;
762 int tabSize = Config_getInt(TAB_SIZE);
763 SrcLangExt lang = getLanguageFromFileName(fileName);
764 const int blockSize = 4096;
765 std::string str;
767 static_cast<size_t>(std::max(1,startLine)),
768 static_cast<size_t>(std::max({1,startLine,endLine})),str);
769 //printf("readCodeFragment(%s,startLine=%d,endLine=%d)=\n[[[\n%s]]]\n",qPrint(fileName),startLine,endLine,qPrint(str));
770
771 bool found = lang==SrcLangExt::VHDL ||
772 lang==SrcLangExt::Python ||
773 lang==SrcLangExt::Fortran ||
774 isMacro;
775 // for VHDL, Python, and Fortran no bracket search is possible
776 char *p=str.data();
777 if (p && *p)
778 {
779 char c=0;
780 int col=0;
781 int lineNr=startLine;
782 // skip until the opening bracket or lonely : is found
783 char cn=0;
784 while (*p && !found)
785 {
786 int pc=0;
787 while ((c=*p++)!='{' && c!=':' && c!='=' && c!=0)
788 {
789 //printf("parsing char '%c'\n",c);
790 if (c=='\n')
791 {
792 lineNr++;
793 col = 0;
794 }
795 else if (c=='\t')
796 {
797 col+=tabSize - (col%tabSize);
798 }
799 else if (pc=='/' && c=='/') // skip single line comment
800 {
801 while ((c=*p++)!='\n' && c!=0);
802 if (c == '\n')
803 {
804 lineNr++;
805 col = 0;
806 }
807 }
808 else if (pc=='/' && c=='*') // skip C style comment
809 {
810 while (((c=*p++)!='/' || pc!='*') && c!=0)
811 {
812 if (c == '\n')
813 {
814 lineNr++;
815 col = 0;
816 }
817 pc=c;
818 }
819 }
820 else
821 {
822 col++;
823 }
824 pc = c;
825 }
826 if (c==':')
827 {
828 cn=*p++;
829 if (cn!=':') found=TRUE;
830 }
831 else if (c=='=')
832 {
833 cn=*p++;
834 if (cn=='>') // C# Expression body
835 {
836 found=TRUE;
837 }
838 }
839 else if (c=='{')
840 {
841 found=TRUE;
842 }
843 else if (c==0)
844 {
845 break;
846 }
847 }
848 //printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr);
849 if (found)
850 {
851 // For code with more than one line,
852 // fill the line with spaces until we are at the right column
853 // so that the opening brace lines up with the closing brace
854 if (endLine!=startLine)
855 {
856 QCString spaces;
857 spaces.fill(' ',col);
858 result+=spaces;
859 }
860 // copy until end of line
861 if (c) result+=c;
862 startLine=lineNr;
863 if (c==':' || c=='=')
864 {
865 result+=cn;
866 if (cn=='\n') lineNr++;
867 }
868 char lineStr[blockSize];
869 do
870 {
871 //printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine);
872 int size_read=0;
873 do
874 {
875 // read up to blockSize-1 non-zero characters
876 int i=0;
877 while ((c=*p) && i<blockSize-1)
878 {
879 lineStr[i++]=c;
880 p++;
881 if (c=='\n') break; // stop at end of the line
882 }
883 lineStr[i]=0;
884 size_read=i;
885 result+=lineStr; // append line to the output
886 } while (size_read == (blockSize-1)); // append more if line does not fit in buffer
887 lineNr++;
888 } while (*p);
889
890 // strip stuff after closing bracket
891 int newLineIndex = result.findRev('\n');
892 int braceIndex = result.findRev('}');
893 if (braceIndex > newLineIndex)
894 {
895 result.resize(static_cast<size_t>(braceIndex+1));
896 }
897 endLine=lineNr-1;
898 }
899 if (usePipe)
900 {
901 Debug::print(Debug::FilterOutput, 0, "Filter output\n");
902 Debug::print(Debug::FilterOutput,0,"-------------\n{}\n-------------\n",result);
903 }
904 }
905 QCString encoding = getEncoding(FileInfo(fileName.str()));
906 if (encoding!="UTF-8")
907 {
908 std::string encBuf = result.str();
909 bool ok = transcodeCharacterStringToUTF8(encBuf,encoding.data());
910 if (ok)
911 {
912 result = encBuf;
913 }
914 else
915 {
916 err("failed to transcode characters in code fragment in file {} lines {} to {}, from input encoding {} to UTF-8\n",
917 fileName,startLine,endLine,encoding);
918
919 }
920 }
921 if (!result.isEmpty() && result.at(result.length()-1)!='\n') result += "\n";
922 //printf("readCodeFragment(%d-%d)=%s\n",startLine,endLine,qPrint(result));
923 return found;
924}
@ FilterOutput
Definition debug.h:38
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:76
Minimal replacement for QFileInfo.
Definition fileinfo.h:23
static FilterCache & instance()
bool getFileContents(const QCString &fileName, size_t startLine, size_t endLine, std::string &str)
void resize(size_t newlen)
Definition qcstring.h:180
QCString fill(char c, int len=-1)
Fills a string with a predefined character.
Definition qcstring.h:193
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:172
#define Config_getInt(name)
Definition config.h:34
#define err(fmt,...)
Definition message.h:127
SrcLangExt
Definition types.h:207
SrcLangExt getLanguageFromFileName(const QCString &fileName, SrcLangExt defLang)
Definition util.cpp:5191
bool transcodeCharacterStringToUTF8(std::string &input, const char *inputEncoding)
Definition util.cpp:1433
QCString getEncoding(const FileInfo &fi)
Definition util.cpp:5691
QCString getFileFilter(const QCString &name, bool isSourceCode)
Definition util.cpp:1399

References QCString::at(), Config_getBool, Config_getInt, QCString::data(), err, QCString::fill(), Debug::FilterOutput, QCString::findRev(), getEncoding(), FilterCache::getFileContents(), getFileFilter(), getLanguageFromFileName(), FilterCache::instance(), QCString::isEmpty(), QCString::length(), Debug::print(), QCString::resize(), QCString::str(), transcodeCharacterStringToUTF8(), and TRUE.

Referenced by VhdlDocGen::createFlowChart(), DefinitionMutable::toDefinition_(), and DefinitionImpl::writeInlineCode().

◆ refMapToVector()

MemberVector refMapToVector ( const std::unordered_map< std::string, MemberDef * > & map)
inlinestatic

Definition at line 1084 of file definition.cpp.

1085{
1086 // convert map to a vector of values
1087 MemberVector result;
1088 std::transform(map.begin(),map.end(), // iterate over map
1089 std::back_inserter(result), // add results to vector
1090 [](const auto &item)
1091 { return item.second; } // extract value to add from map Key,Value pair
1092 );
1093 // and sort it
1094 std::stable_sort(result.begin(),result.end(),
1095 [](const auto &m1,const auto &m2) { return genericCompareMembers(m1,m2)<0; });
1096 return result;
1097}
A vector of MemberDef object.
Definition memberlist.h:35
iterator end() noexcept
Definition memberlist.h:56
iterator begin() noexcept
Definition memberlist.h:54

References MemberVector::begin(), and MemberVector::end().

Referenced by DefinitionImpl::_writeSourceRefList(), DefinitionImpl::getReferencedByMembers(), and DefinitionImpl::getReferencesMembers().

◆ removeFromMap()

void removeFromMap ( const QCString & name,
Definition * d )
static

Definition at line 234 of file definition.cpp.

235{
236 Doxygen::symbolMap->remove(name,d);
237}

References DefinitionImpl::name(), and Doxygen::symbolMap.

Referenced by DefinitionAliasImpl::deinit(), and DefinitionImpl::~DefinitionImpl().

◆ stripWord()

bool stripWord ( QCString & s,
QCString w )
static

Definition at line 1607 of file definition.cpp.

1608{
1609 bool success=FALSE;
1610 if (s.left(w.length())==w)
1611 {
1612 success=TRUE;
1613 s=s.right(s.length()-w.length());
1614 }
1615 return success;
1616}
QCString right(size_t len) const
Definition qcstring.h:234

References FALSE, QCString::left(), QCString::length(), QCString::right(), and TRUE.

Referenced by abbreviate().

◆ toDefinition()

◆ toDefinitionMutable()

DefinitionMutable * toDefinitionMutable ( Definition * d)

Variable Documentation

◆ g_memberReferenceMutex

std::mutex g_memberReferenceMutex
static

◆ g_qualifiedNameMutex

std::recursive_mutex g_qualifiedNameMutex
static