Doxygen
Loading...
Searching...
No Matches
definition.h File Reference
#include <vector>
#include "types.h"
#include "reflist.h"
#include "construct.h"
Include dependency graph for definition.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DocInfo
 Data associated with a detailed description. More...
struct  BriefInfo
 Data associated with a brief description. More...
struct  BodyInfo
 Data associated with description found in the body. More...
class  Definition
 The common base class of all entity definitions found in the sources. More...
class  DefinitionMutable

Functions

DefinitiontoDefinition (DefinitionMutable *dm)
DefinitionMutabletoDefinitionMutable (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.

Function Documentation

◆ 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.

The result is returned as a string via result. The function returns TRUE if successful and FALSE in case of an error.

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

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

References QCString::at(), Config_getBool, Config_getInt, QCString::data(), err, QCString::fill(), Debug::FilterOutput, QCString::findRev(), found, 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().

◆ toDefinition()

Definition * toDefinition ( DefinitionMutable * dm)

Definition at line 388 of file definition.cpp.

1871{
1872 if (dm==nullptr) return nullptr;
1873 return dm->toDefinition_();
1874}
virtual Definition * toDefinition_()=0

References DefinitionImpl::docLine(), stripLeadingAndTrailingEmptyLines(), and stripWhiteSpace().

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

◆ toDefinitionMutable()

DefinitionMutable * toDefinitionMutable ( Definition * d)

Definition at line 300 of file definition.cpp.

1877{
1878 if (d==nullptr) return nullptr;
1879 return d->toDefinitionMutable_();
1880}
virtual DefinitionMutable * toDefinitionMutable_()=0

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