Doxygen
Loading...
Searching...
No Matches
definition.cpp File Reference
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <string>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#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  DeepCopyUniquePtr< T >
 Helper class add copy/assignment support to std::unique_ptr by making a deep copy Note that T may not be a polymorphic type. More...
 
class  DefinitionImpl::IMPL
 Private data associated with a Symbol DefinitionImpl object. More...
 
class  FilterCache
 
struct  FilterCache::FilterCacheItem
 

Functions

template<typename T , typename... Args>
DeepCopyUniquePtr< T > make_DeepCopyUnique (Args &&... args)
 Helper to create an object wrapped in a DeepCopyUniquePtr.
 
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()

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

Definition at line 1517 of file definition.cpp.

1518{
1519 QCString scopelessName=name;
1520 int i=scopelessName.findRev("::");
1521 if (i!=-1) scopelessName=scopelessName.mid(i+2);
1522 QCString result=s;
1523 result=result.stripWhiteSpace();
1524 // strip trailing .
1525 if (!result.isEmpty() && result.at(result.length()-1)=='.')
1526 result=result.left(result.length()-1);
1527
1528 // strip any predefined prefix
1529 const StringVector &briefDescAbbrev = Config_getList(ABBREVIATE_BRIEF);
1530 for (const auto &p : briefDescAbbrev)
1531 {
1532 QCString str = substitute(p.c_str(),"$name",scopelessName); // replace $name with entity name
1533 str += " ";
1534 stripWord(result,str);
1535 }
1536
1537 // capitalize first word
1538 if (!result.isEmpty())
1539 {
1540 char c=result[0];
1541 if (c>='a' && c<='z') c+='A'-'a';
1542 result[0]=c;
1543 }
1544 return result;
1545}
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:153
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:567
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:245
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString left(size_t len) const
Definition qcstring.h:214
#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:477

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

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

◆ addToMap()

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

Definition at line 244 of file definition.cpp.

245{
246 bool vhdlOpt = Config_getBool(OPTIMIZE_OUTPUT_VHDL);
247 QCString symbolName = name;
248 int index=computeQualifiedIndex(symbolName);
249 if (!vhdlOpt && index!=-1) symbolName=symbolName.mid(index+2);
250 if (!symbolName.isEmpty())
251 {
252 //printf("adding symbol %s\n",qPrint(symbolName));
253 Doxygen::symbolMap->add(symbolName,d);
254
255 d->_setSymbolName(symbolName);
256 }
257}
virtual void _setSymbolName(const QCString &name)=0
static SymbolMap< Definition > * symbolMap
Definition doxygen.h:125
#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:7151

References Definition::_setSymbolName(), SymbolMap< T >::add(), computeQualifiedIndex(), Config_getBool, DefinitionImpl::name(), Doxygen::symbolMap, and DefinitionImpl::symbolName().

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

◆ make_DeepCopyUnique()

template<typename T , typename... Args>
DeepCopyUniquePtr< T > make_DeepCopyUnique ( Args &&... args)

Helper to create an object wrapped in a DeepCopyUniquePtr.

Definition at line 83 of file definition.cpp.

84{
85 return DeepCopyUniquePtr<T>(new T(std::forward<Args>(args)...));
86}
Helper class add copy/assignment support to std::unique_ptr by making a deep copy Note that T may not...

Referenced by DefinitionImpl::_setBriefDescription(), DefinitionImpl::_setDocumentation(), DefinitionImpl::_setInbodyDocumentation(), DefinitionImpl::setBodyDef(), and DefinitionImpl::setBodySegment().

◆ matchExcludedSymbols()

static bool matchExcludedSymbols ( const QCString & name)
static

Definition at line 189 of file definition.cpp.

190{
191 const StringVector &exclSyms = Config_getList(EXCLUDE_SYMBOLS);
192 if (exclSyms.empty()) return FALSE; // nothing specified
193 std::string symName = name.str();
194 for (const auto &pat : exclSyms)
195 {
196 QCString pattern = pat.c_str();
197 bool forceStart=FALSE;
198 bool forceEnd=FALSE;
199 if (pattern.at(0)=='^')
200 pattern=pattern.mid(1),forceStart=TRUE;
201 if (pattern.at(pattern.length()-1)=='$')
202 pattern=pattern.left(pattern.length()-1),forceEnd=TRUE;
203 if (pattern.find('*')!=-1) // wildcard mode
204 {
205 const reg::Ex re(substitute(pattern,"*",".*").str());
207 if (reg::search(symName,match,re)) // wildcard match
208 {
209 size_t ui = match.position();
210 size_t pl = match.length();
211 size_t sl = symName.length();
212 if ((ui==0 || pattern.at(0)=='*' || (!isId(symName.at(ui-1)) && !forceStart)) &&
213 (ui+pl==sl || pattern.at(pattern.length()-1)=='*' || (!isId(symName.at(ui+pl)) && !forceEnd))
214 )
215 {
216 //printf("--> name=%s pattern=%s match at %d\n",qPrint(symName),qPrint(pattern),i);
217 return TRUE;
218 }
219 }
220 }
221 else if (!pattern.isEmpty()) // match words
222 {
223 size_t i = symName.find(pattern.str());
224 if (i!=std::string::npos) // we have a match!
225 {
226 size_t ui=i;
227 size_t pl=pattern.length();
228 size_t sl=symName.length();
229 // check if it is a whole word match
230 if ((ui==0 || (!isId(symName.at(ui-1)) && !forceStart)) &&
231 (ui+pl==sl || (!isId(symName.at(ui+pl)) && !forceEnd))
232 )
233 {
234 //printf("--> name=%s pattern=%s match at %d\n",qPrint(symName),qPrint(pattern),i);
235 return TRUE;
236 }
237 }
238 }
239 }
240 //printf("--> name=%s: no match\n",name);
241 return FALSE;
242}
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
const std::string & str() const
Definition qcstring.h:526
Class representing a regular expression.
Definition regex.h:39
Object representing the matching results.
Definition regex.h:153
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:748
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:759
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
bool isId(int c)
Definition util.h:202

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 776 of file definition.cpp.

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

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

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

◆ refMapToVector()

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

Definition at line 1081 of file definition.cpp.

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

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

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

◆ removeFromMap()

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

◆ stripWord()

static bool stripWord ( QCString & s,
QCString w )
static

Definition at line 1504 of file definition.cpp.

1505{
1506 bool success=FALSE;
1507 if (s.left(w.length())==w)
1508 {
1509 success=TRUE;
1510 s=s.right(s.length()-w.length());
1511 }
1512 return success;
1513}
QCString right(size_t len) const
Definition qcstring.h:219

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

Referenced by abbreviate().

◆ toDefinition()

Definition * toDefinition ( DefinitionMutable * dm)

Definition at line 1889 of file definition.cpp.

1890{
1891 if (dm==nullptr) return nullptr;
1892 return dm->toDefinition_();
1893}
virtual Definition * toDefinition_()=0

Referenced by buildScopeFromQualifiedName(), findScopeFromQualifiedName(), toConceptDef(), toMemberDef(), toNamespaceDef(), and MemberList::writeDocumentationPage().

◆ toDefinitionMutable()

DefinitionMutable * toDefinitionMutable ( Definition * d)

Definition at line 1895 of file definition.cpp.

1896{
1897 if (d==nullptr) return nullptr;
1898 return d->toDefinitionMutable_();
1899}
virtual DefinitionMutable * toDefinitionMutable_()=0

Referenced by addConceptToContext(), buildNamespaceList(), buildScopeFromQualifiedName(), computeTooltipTexts(), createTagLessInstance(), and resolveClassNestingRelations().

Variable Documentation

◆ g_memberReferenceMutex

std::mutex g_memberReferenceMutex
static

◆ g_qualifiedNameMutex

std::recursive_mutex g_qualifiedNameMutex
static