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 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.
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:567
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:526
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:84
const char * qPrint(const char *s)
Definition qcstring.h:661
#define TRUE
Definition qcstring.h:37
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().

◆ toDefinition()

Definition * toDefinition ( DefinitionMutable * dm)

Definition at line 388 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 300 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().