Skip to main content

The definition.cpp File Reference

Included Headers

#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"

Classes Index

classPrivate

Private data associated with a Symbol DefinitionImpl object. More...

classFilterCache
structFilterCacheItem

Functions Index

static boolmatchExcludedSymbols (const QCString &name)
static voidaddToMap (const QCString &name, Definition *d)
static voidremoveFromMap (const QCString &name, Definition *d)
boolreadCodeFragment (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. More...

static MemberVectorrefMapToVector (const std::unordered_map< std::string, MemberDef * > &map)
static boolstripWord (QCString &s, QCString w)
static QCStringabbreviate (const QCString &s, const QCString &name)
Definition *toDefinition (DefinitionMutable *dm)
DefinitionMutable *toDefinitionMutable (Definition *d)

Variables Index

static std::recursive_mutexg_qualifiedNameMutex
static std::mutexg_memberReferenceMutex

Functions

abbreviate()

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

Definition at line 1547 of file definition.cpp.

1547static QCString abbreviate(const QCString &s,const QCString &name)
1548{
1549 QCString scopelessName=name;
1550 int i=scopelessName.findRev("::");
1551 if (i!=-1) scopelessName=scopelessName.mid(i+2);
1552 QCString result=s;
1553 result=result.stripWhiteSpace();
1554 // strip trailing .
1555 if (!result.isEmpty() && result.at(result.length()-1)=='.')
1556 result=result.left(result.length()-1);
1557
1558 // strip any predefined prefix
1559 const StringVector &briefDescAbbrev = Config_getList(ABBREVIATE_BRIEF);
1560 for (const auto &p : briefDescAbbrev)
1561 {
1562 QCString str = substitute(p.c_str(),"$name",scopelessName); // replace $name with entity name
1563 str += " ";
1564 stripWord(result,str);
1565 }
1566
1567 // capitalize first word
1568 if (!result.isEmpty())
1569 {
1570 char c=result[0];
1571 if (c>='a' && c<='z') c+='A'-'a';
1572 result[0]=c;
1573 }
1574 return result;
1575}

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

212static void addToMap(const QCString &name,Definition *d)
213{
214 bool vhdlOpt = Config_getBool(OPTIMIZE_OUTPUT_VHDL);
217 if (!vhdlOpt && index!=-1) symbolName=symbolName.mid(index+2);
218 if (!symbolName.isEmpty())
219 {
220 //printf("adding symbol %s\n",qPrint(symbolName));
222
224 }
225}

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

158{
159 const StringVector &exclSyms = Config_getList(EXCLUDE_SYMBOLS);
160 if (exclSyms.empty()) return FALSE; // nothing specified
161 std::string symName = name.str();
162 for (const auto &pat : exclSyms)
163 {
164 QCString pattern = pat.c_str();
165 bool forceStart=FALSE;
166 bool forceEnd=FALSE;
167 if (pattern.at(0)=='^')
168 pattern=pattern.mid(1),forceStart=TRUE;
169 if (pattern.at(pattern.length()-1)=='$')
170 pattern=pattern.left(pattern.length()-1),forceEnd=TRUE;
171 if (pattern.find('*')!=-1) // wildcard mode
172 {
173 const reg::Ex re(substitute(pattern,"*",".*").str());
174 reg::Match match;
175 if (reg::search(symName,match,re)) // wildcard match
176 {
177 size_t ui = match.position();
178 size_t pl = match.length();
179 size_t sl = symName.length();
180 if ((ui==0 || pattern.at(0)=='*' || (!isId(symName.at(ui-1)) && !forceStart)) &&
181 (ui+pl==sl || pattern.at(pattern.length()-1)=='*' || (!isId(symName.at(ui+pl)) && !forceEnd))
182 )
183 {
184 //printf("--> name=%s pattern=%s match at %d\n",qPrint(symName),qPrint(pattern),i);
185 return TRUE;
186 }
187 }
188 }
189 else if (!pattern.isEmpty()) // match words
190 {
191 size_t i = symName.find(pattern.str());
192 if (i!=std::string::npos) // we have a match!
193 {
194 size_t ui=i;
195 size_t pl=pattern.length();
196 size_t sl=symName.length();
197 // check if it is a whole word match
198 if ((ui==0 || (!isId(symName.at(ui-1)) && !forceStart)) &&
199 (ui+pl==sl || (!isId(symName.at(ui+pl)) && !forceEnd))
200 )
201 {
202 //printf("--> name=%s pattern=%s match at %d\n",qPrint(symName),qPrint(pattern),i);
203 return TRUE;
204 }
205 }
206 }
207 }
208 //printf("--> name=%s: no match\n",name);
209 return FALSE;
210}

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

749bool readCodeFragment(const QCString &fileName,bool isMacro,
750 int &startLine,int &endLine,QCString &result)
751{
752 bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
753 QCString filter = getFileFilter(fileName,TRUE);
754 bool usePipe = !filter.isEmpty() && filterSourceFiles;
755 int tabSize = Config_getInt(TAB_SIZE);
756 SrcLangExt lang = getLanguageFromFileName(fileName);
757 const int blockSize = 4096;
758 std::string str;
760 static_cast<size_t>(std::max(1,startLine)),
761 static_cast<size_t>(std::max({1,startLine,endLine})),str);
762 //printf("readCodeFragment(%s,startLine=%d,endLine=%d)=\n[[[\n%s]]]\n",qPrint(fileName),startLine,endLine,qPrint(str));
763
764 bool found = lang==SrcLangExt::VHDL ||
765 lang==SrcLangExt::Python ||
766 lang==SrcLangExt::Fortran ||
767 isMacro;
768 // for VHDL, Python, and Fortran no bracket search is possible
769 char *p=str.data();
770 if (p && *p)
771 {
772 char c=0;
773 int col=0;
774 int lineNr=startLine;
775 // skip until the opening bracket or lonely : is found
776 char cn=0;
777 while (*p && !found)
778 {
779 int pc=0;
780 while ((c=*p++)!='{' && c!=':' && c!=0)
781 {
782 //printf("parsing char '%c'\n",c);
783 if (c=='\n')
784 {
785 lineNr++,col=0;
786 }
787 else if (c=='\t')
788 {
789 col+=tabSize - (col%tabSize);
790 }
791 else if (pc=='/' && c=='/') // skip single line comment
792 {
793 while ((c=*p++)!='\n' && c!=0);
794 if (c=='\n') lineNr++,col=0;
795 }
796 else if (pc=='/' && c=='*') // skip C style comment
797 {
798 while (((c=*p++)!='/' || pc!='*') && c!=0)
799 {
800 if (c=='\n') lineNr++,col=0;
801 pc=c;
802 }
803 }
804 else
805 {
806 col++;
807 }
808 pc = c;
809 }
810 if (c==':')
811 {
812 cn=*p++;
813 if (cn!=':') found=TRUE;
814 }
815 else if (c=='{')
816 {
817 found=TRUE;
818 }
819 else if (c==0)
820 {
821 break;
822 }
823 }
824 //printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr);
825 if (found)
826 {
827 // For code with more than one line,
828 // fill the line with spaces until we are at the right column
829 // so that the opening brace lines up with the closing brace
830 if (endLine!=startLine)
831 {
832 QCString spaces;
833 spaces.fill(' ',col);
834 result+=spaces;
835 }
836 // copy until end of line
837 if (c) result+=c;
838 startLine=lineNr;
839 if (c==':')
840 {
841 result+=cn;
842 if (cn=='\n') lineNr++;
843 }
844 char lineStr[blockSize];
845 do
846 {
847 //printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine);
848 int size_read=0;
849 do
850 {
851 // read up to blockSize-1 non-zero characters
852 int i=0;
853 while ((c=*p) && i<blockSize-1)
854 {
855 lineStr[i++]=c;
856 p++;
857 if (c=='\n') break; // stop at end of the line
858 }
859 lineStr[i]=0;
860 size_read=i;
861 result+=lineStr; // append line to the output
862 } while (size_read == (blockSize-1)); // append more if line does not fit in buffer
863 lineNr++;
864 } while (*p);
865
866 // strip stuff after closing bracket
867 int newLineIndex = result.findRev('\n');
868 int braceIndex = result.findRev('}');
869 if (braceIndex > newLineIndex)
870 {
871 result.resize(static_cast<size_t>(braceIndex+1));
872 }
873 endLine=lineNr-1;
874 }
875 if (usePipe)
876 {
877 Debug::print(Debug::FilterOutput, 0, "Filter output\n");
878 Debug::print(Debug::FilterOutput,0,"-------------\n{}\n-------------\n",result);
879 }
880 }
881 QCString encoding = getEncoding(FileInfo(fileName.str()));
882 if (encoding!="UTF-8")
883 {
884 std::string encBuf = result.str();
885 bool ok = transcodeCharacterStringToUTF8(encBuf,encoding.data());
886 if (ok)
887 {
888 result = QCString(encBuf);
889 }
890 else
891 {
892 err("failed to transcode characters in code fragment in file {} lines {} to {}, from input encoding {} to UTF-8\n",
893 fileName,startLine,endLine,encoding);
894
895 }
896 }
897 if (!result.isEmpty() && result.at(result.length()-1)!='\n') result += "\n";
898 //printf("readCodeFragment(%d-%d)=%s\n",startLine,endLine,qPrint(result));
899 return found;
900}

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)
inline static

Definition at line 1061 of file definition.cpp.

1061static inline MemberVector refMapToVector(const std::unordered_map<std::string,MemberDef *> &map)
1062{
1063 // convert map to a vector of values
1064 MemberVector result;
1065 std::transform(map.begin(),map.end(), // iterate over map
1066 std::back_inserter(result), // add results to vector
1067 [](const auto &item)
1068 { return item.second; } // extract value to add from map Key,Value pair
1069 );
1070 // and sort it
1071 std::stable_sort(result.begin(),result.end(),
1072 [](const auto &m1,const auto &m2) { return genericCompareMembers(m1,m2)<0; });
1073 return result;
1074}

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

227static void removeFromMap(const QCString &name,Definition *d)
228{
229 Doxygen::symbolMap->remove(name,d);
230}

References DefinitionImpl::name and Doxygen::symbolMap.

Referenced by DefinitionAliasImpl::deinit and DefinitionImpl::~DefinitionImpl.

stripWord()

bool stripWord (QCString & s, QCString w)
static

Definition at line 1534 of file definition.cpp.

1534static bool stripWord(QCString &s,QCString w)
1535{
1536 bool success=FALSE;
1537 if (s.left(w.length())==w)
1538 {
1539 success=TRUE;
1540 s=s.right(s.length()-w.length());
1541 }
1542 return success;
1543}

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

Referenced by abbreviate.

toDefinition()

toDefinitionMutable()

DefinitionMutable * toDefinitionMutable (Definition * d)

Variables

g_memberReferenceMutex

std::mutex g_memberReferenceMutex
static

Definition at line 1718 of file definition.cpp.

1718static std::mutex g_memberReferenceMutex;

Referenced by DefinitionImpl::getReferencedByMembers and DefinitionImpl::getReferencesMembers.

g_qualifiedNameMutex

std::recursive_mutex g_qualifiedNameMutex
static

Definition at line 1217 of file definition.cpp.

1217static std::recursive_mutex g_qualifiedNameMutex;

Referenced by DefinitionImpl::qualifiedName and DefinitionImpl::setOuterScope.


Generated via doxygen2docusaurus by Doxygen 1.14.0.