Classes | Macros | Functions
definition.cpp File Reference
#include <ctype.h>
#include <qregexp.h>
#include "md5.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "config.h"
#include "definition.h"
#include "doxygen.h"
#include "language.h"
#include "message.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 "marshal.h"
#include "debug.h"
#include "vhdldocgen.h"
#include "memberlist.h"
#include "namespacedef.h"
#include "filedef.h"
#include "dirdef.h"

Go to the source code of this file.

Classes

class  DefinitionImpl
 

Macros

#define START_MARKER   0x4445465B
 
#define END_MARKER   0x4445465D
 
#define uni_isupper(c)   (QChar(c).category()==QChar::Letter_Uppercase)
 

Functions

static bool matchExcludedSymbols (const char *name)
 
static bool lastCharIsMultibyte (const QCString &s)
 
bool readCodeFragment (const char *fileName, int &startLine, int &endLine, QCString &result)
 
static bool stripWord (QCString &s, QCString w)
 
QCString abbreviate (const char *s, const char *name)
 

Macro Definition Documentation

#define END_MARKER   0x4445465D

Definition at line 46 of file definition.cpp.

#define START_MARKER   0x4445465B

Definition at line 45 of file definition.cpp.

#define uni_isupper (   c)    (QChar(c).category()==QChar::Letter_Uppercase)

Definition at line 618 of file definition.cpp.

Function Documentation

QCString abbreviate ( const char *  s,
const char *  name 
)

Definition at line 1732 of file definition.cpp.

1733 {
1734  QCString scopelessName=name;
1735  int i=scopelessName.findRev("::");
1736  if (i!=-1) scopelessName=scopelessName.mid(i+2);
1737  QCString result=s;
1738  result=result.stripWhiteSpace();
1739  // strip trailing .
1740  if (!result.isEmpty() && result.at(result.length()-1)=='.')
1741  result=result.left(result.length()-1);
1742 
1743  // strip any predefined prefix
1744  QStrList &briefDescAbbrev = Config_getList("ABBREVIATE_BRIEF");
1745  const char *p = briefDescAbbrev.first();
1746  while (p)
1747  {
1748  QCString s = p;
1749  s.replace(QRegExp("\\$name"), scopelessName); // replace $name with entity name
1750  s += " ";
1751  stripWord(result,s);
1752  p = briefDescAbbrev.next();
1753  }
1754 
1755  // capitalize first word
1756  if (!result.isEmpty())
1757  {
1758  int c=result[0];
1759  if (c>='a' && c<='z') c+='A'-'a';
1760  result[0]=c;
1761  }
1762  return result;
1763 }
static QCString name
Definition: declinfo.cpp:673
QCString stripWhiteSpace() const
Definition: qcstring.cpp:295
static QCString result
bool isEmpty() const
Definition: qcstring.h:189
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
uint length() const
Definition: qcstring.h:195
type * first()
Definition: qinternallist.h:87
char & at(uint i) const
Definition: qcstring.h:326
#define Config_getList(val)
Definition: config.cpp:662
QCString left(uint len) const
Definition: qcstring.cpp:213
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition: qcstring.cpp:95
p
Definition: test.py:223
type * next()
Definition: qinternallist.h:89
static bool stripWord(QCString &s, QCString w)
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
QCString & replace(uint index, uint len, const char *s)
Definition: qcstring.cpp:411
static QCString * s
Definition: config.cpp:1042
static bool lastCharIsMultibyte ( const QCString s)
static

Definition at line 622 of file definition.cpp.

623 {
624  int l = s.length();
625  int p = 0;
626  int pp = -1;
627  while ((p=nextUtf8CharPosition(s,l,p))<l) pp=p;
628  if (pp==-1 || ((uchar)s[pp])<0x80) return FALSE;
629  return TRUE;
630 }
uint length() const
Definition: qcstring.h:195
const bool FALSE
Definition: qglobal.h:370
static QStrList * l
Definition: config.cpp:1044
unsigned char uchar
Definition: nybbler.cc:11
p
Definition: test.py:223
int nextUtf8CharPosition(const QCString &utf8Str, int len, int startPos)
Definition: util.cpp:7195
const bool TRUE
Definition: qglobal.h:371
static bool matchExcludedSymbols ( const char *  name)
static

Definition at line 150 of file definition.cpp.

151 {
152  static QStrList &exclSyms = Config_getList("EXCLUDE_SYMBOLS");
153  if (exclSyms.count()==0) return FALSE; // nothing specified
154  const char *pat = exclSyms.first();
155  QCString symName = name;
156  while (pat)
157  {
158  QCString pattern = pat;
159  bool forceStart=FALSE;
160  bool forceEnd=FALSE;
161  if (pattern.at(0)=='^')
162  pattern=pattern.mid(1),forceStart=TRUE;
163  if (pattern.at(pattern.length()-1)=='$')
164  pattern=pattern.left(pattern.length()-1),forceEnd=TRUE;
165  if (pattern.find('*')!=-1) // wildcard mode
166  {
167  QRegExp re(substitute(pattern,"*",".*"),TRUE);
168  int i,pl;
169  i = re.match(symName,0,&pl);
170  //printf(" %d = re.match(%s) pattern=%s\n",i,symName.data(),pattern.data());
171  if (i!=-1) // wildcard match
172  {
173  int sl=symName.length();
174  // check if it is a whole word match
175  if ((i==0 || pattern.at(0)=='*' || (!isId(symName.at(i-1)) && !forceStart)) &&
176  (i+pl==sl || pattern.at(i+pl)=='*' || (!isId(symName.at(i+pl)) && !forceEnd))
177  )
178  {
179  //printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i);
180  return TRUE;
181  }
182  }
183  }
184  else if (!pattern.isEmpty()) // match words
185  {
186  int i = symName.find(pattern);
187  if (i!=-1) // we have a match!
188  {
189  int pl=pattern.length();
190  int sl=symName.length();
191  // check if it is a whole word match
192  if ((i==0 || (!isId(symName.at(i-1)) && !forceStart)) &&
193  (i+pl==sl || (!isId(symName.at(i+pl)) && !forceEnd))
194  )
195  {
196  //printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i);
197  return TRUE;
198  }
199  }
200  }
201  pat = exclSyms.next();
202  }
203  //printf("--> name=%s: no match\n",name);
204  return FALSE;
205 }
static QCString name
Definition: declinfo.cpp:673
bool isEmpty() const
Definition: qcstring.h:189
The QRegExp class provides pattern matching using regular expressions or wildcards.
Definition: qregexp.h:46
uint length() const
Definition: qcstring.h:195
type * first()
Definition: qinternallist.h:87
char & at(uint i) const
Definition: qcstring.h:326
const bool FALSE
Definition: qglobal.h:370
#define Config_getList(val)
Definition: config.cpp:662
QCString left(uint len) const
Definition: qcstring.cpp:213
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
type * next()
Definition: qinternallist.h:89
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
std::string pattern
Definition: regex_t.cc:35
bool isId(int c)
Definition: util.h:224
uint count() const
Definition: qinternallist.h:56
const bool TRUE
Definition: qglobal.h:371
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: util.cpp:5088
bool readCodeFragment ( const char *  fileName,
int &  startLine,
int &  endLine,
QCString result 
)

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

730 {
731  static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES");
732  static int tabSize = Config_getInt("TAB_SIZE");
733  //printf("readCodeFragment(%s,%d,%d)\n",fileName,startLine,endLine);
734  if (fileName==0 || fileName[0]==0) return FALSE; // not a valid file name
736  FILE *f=0;
737  bool usePipe = !filter.isEmpty() && filterSourceFiles;
739  if (!usePipe) // no filter given or wanted
740  {
741  f = portable_fopen(fileName,"r");
742  }
743  else // use filter
744  {
745  QCString cmd=filter+" \""+fileName+"\"";
746  Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",qPrint(cmd));
747  f = portable_popen(cmd,"r");
748  }
749  bool found = lang==SrcLangExt_VHDL ||
750  lang==SrcLangExt_Tcl ||
751  lang==SrcLangExt_Python ||
752  lang==SrcLangExt_Fortran;
753  // for VHDL, TCL, Python, and Fortran no bracket search is possible
754  if (f)
755  {
756  int c=0;
757  int col=0;
758  int lineNr=1;
759  // skip until the startLine has reached
760  while (lineNr<startLine && !feof(f))
761  {
762  while ((c=fgetc(f))!='\n' && c!=EOF) /* skip */;
763  lineNr++;
764  if (found && c == '\n') c = '\0';
765  }
766  if (!feof(f))
767  {
768  // skip until the opening bracket or lonely : is found
769  char cn=0;
770  while (lineNr<=endLine && !feof(f) && !found)
771  {
772  int pc=0;
773  while ((c=fgetc(f))!='{' && c!=':' && c!=EOF) // } so vi matching brackets has no problem
774  {
775  //printf("parsing char `%c'\n",c);
776  if (c=='\n')
777  {
778  lineNr++,col=0;
779  }
780  else if (c=='\t')
781  {
782  col+=tabSize - (col%tabSize);
783  }
784  else if (pc=='/' && c=='/') // skip single line comment
785  {
786  while ((c=fgetc(f))!='\n' && c!=EOF) pc=c;
787  if (c=='\n') lineNr++,col=0;
788  }
789  else if (pc=='/' && c=='*') // skip C style comment
790  {
791  while (((c=fgetc(f))!='/' || pc!='*') && c!=EOF)
792  {
793  if (c=='\n') lineNr++,col=0;
794  pc=c;
795  }
796  }
797  else
798  {
799  col++;
800  }
801  pc = c;
802  }
803  if (c==':')
804  {
805  cn=fgetc(f);
806  if (cn!=':') found=TRUE;
807  }
808  else if (c=='{') // } so vi matching brackets has no problem
809  {
810  found=TRUE;
811  }
812  }
813  //printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr);
814  if (found)
815  {
816  // For code with more than one line,
817  // fill the line with spaces until we are at the right column
818  // so that the opening brace lines up with the closing brace
819  if (endLine!=startLine)
820  {
821  QCString spaces;
822  spaces.fill(' ',col);
823  result+=spaces;
824  }
825  // copy until end of line
826  if (c) result+=c;
827  startLine=lineNr;
828  if (c==':')
829  {
830  result+=cn;
831  if (cn=='\n') lineNr++;
832  }
833  const int maxLineLength=4096;
834  char lineStr[maxLineLength];
835  do
836  {
837  //printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine);
838  int size_read;
839  do
840  {
841  // read up to maxLineLength-1 bytes, the last byte being zero
842  char *p = fgets(lineStr, maxLineLength,f);
843  //printf(" read %s",p);
844  if (p)
845  {
846  size_read=qstrlen(p);
847  }
848  else // nothing read
849  {
850  size_read=-1;
851  lineStr[0]='\0';
852  }
853  result+=lineStr;
854  } while (size_read == (maxLineLength-1));
855 
856  lineNr++;
857  } while (lineNr<=endLine && !feof(f));
858 
859  // strip stuff after closing bracket
860  int newLineIndex = result.findRev('\n');
861  int braceIndex = result.findRev('}');
862  if (braceIndex > newLineIndex)
863  {
864  result.truncate(braceIndex+1);
865  }
866  endLine=lineNr-1;
867  }
868  }
869  if (usePipe)
870  {
871  portable_pclose(f);
872  Debug::print(Debug::FilterOutput, 0, "Filter output\n");
873  Debug::print(Debug::FilterOutput,0,"-------------\n%s\n-------------\n",qPrint(result));
874  }
875  else
876  {
877  fclose(f);
878  }
879  }
880  result = transcodeCharacterStringToUTF8(result);
881  //fprintf(stderr,"readCodeFragement(%d-%d)=%s\n",startLine,endLine,result.data());
882  return found;
883 }
bool isEmpty() const
Definition: qcstring.h:189
FILE * portable_popen(const char *name, const char *type)
Definition: portable.cpp:400
const bool FALSE
Definition: qglobal.h:370
SrcLangExt
Definition: types.h:41
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition: qcstring.cpp:95
QCString getFileFilter(const char *name, bool isSourceCode)
Definition: util.cpp:2345
QCString transcodeCharacterStringToUTF8(const QCString &input)
Definition: util.cpp:2374
#define Config_getInt(val)
Definition: config.cpp:661
Q_EXPORT uint qstrlen(const char *str)
Definition: qcstring.h:81
fileName
Definition: dumpTree.py:9
static void print(DebugMask mask, int prio, const char *fmt,...)
Definition: debug.cpp:84
p
Definition: test.py:223
#define Config_getBool(val)
Definition: config.cpp:664
SrcLangExt getLanguageFromFileName(const QCString fileName)
Definition: util.cpp:7061
int portable_pclose(FILE *stream)
Definition: portable.cpp:405
bool fill(char c, int len=-1)
Definition: qcstring.h:243
bool truncate(uint pos)
Definition: qcstring.h:232
list cmd
Definition: getreco.py:22
FILE * portable_fopen(const char *fileName, const char *mode)
Definition: portable.cpp:344
const char * qPrint(const char *s)
Definition: qcstring.h:797
const bool TRUE
Definition: qglobal.h:371
static bool stripWord ( QCString s,
QCString  w 
)
static

Definition at line 1719 of file definition.cpp.

1720 {
1721  bool success=FALSE;
1722  if (s.left(w.length())==w)
1723  {
1724  success=TRUE;
1725  s=s.right(s.length()-w.length());
1726  }
1727  return success;
1728 }
uint length() const
Definition: qcstring.h:195
const bool FALSE
Definition: qglobal.h:370
QCString left(uint len) const
Definition: qcstring.cpp:213
QCString right(uint len) const
Definition: qcstring.cpp:231
const bool TRUE
Definition: qglobal.h:371