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

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%s\n-------------\n",qPrint(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 %s lines %d to %d, from input encoding %s to UTF-8\n",
893 qPrint(fileName),startLine,endLine,qPrint(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}
@ 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: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:84
const char * qPrint(const char *s)
Definition qcstring.h:672
#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:6008
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(), DefinitionMutable::toDefinition_(), and DefinitionImpl::writeInlineCode().

◆ toDefinition()

◆ toDefinitionMutable()

DefinitionMutable * toDefinitionMutable ( Definition * d)

Definition at line 300 of file definition.cpp.

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

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