Skip to content

Commit

Permalink
In case of sections with the same name they are not reported.
Browse files Browse the repository at this point in the history
In this patch it is checked if a section label has been used before and if so a warning is given with file name and line number (when possible) where the section label was used the first time.
Note in section.h the item level was not initialized in the past in case of a copy constructor.
  • Loading branch information
albert-github committed Mar 2, 2014
1 parent 8eeaae0 commit ac611be
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 53 deletions.
88 changes: 66 additions & 22 deletions src/commentscan.l
Expand Up @@ -553,7 +553,7 @@ static void addXRefItem(const char *listName,const char *itemTitle,
item->text += " <p>";
if (Doxygen::markdownSupport)
{
item->text += processMarkdown(yyFileName,current,outputXRef);
item->text += processMarkdown(yyFileName,yyLineNr,current,outputXRef);
}
else
{
Expand All @@ -575,7 +575,7 @@ static void addXRefItem(const char *listName,const char *itemTitle,
ASSERT(item!=0);
if (Doxygen::markdownSupport)
{
item->text = processMarkdown(yyFileName,current,outputXRef);
item->text = processMarkdown(yyFileName,yyLineNr,current,outputXRef);
}
else
{
Expand All @@ -593,11 +593,26 @@ static void addXRefItem(const char *listName,const char *itemTitle,
{
docEntry->doc += cmdString;
}
SectionInfo *si=new SectionInfo(listName,anchorLabel,
g_sectionTitle,SectionInfo::Anchor,
g_sectionLevel);
Doxygen::sectionDict->append(anchorLabel,si);
docEntry->anchors->append(si);
SectionInfo *si = Doxygen::sectionDict->find(anchorLabel);
if (si)
{
if (si->lineNr != -1)
{
warn(listName,yyLineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",anchorLabel,si->fileName.data(),si->lineNr);
}
else
{
warn(listName,yyLineNr,"multiple use of section label '%s', (first occurrence: %s)",anchorLabel,si->fileName.data());
}
}
else
{
si=new SectionInfo(listName,yyLineNr,anchorLabel,
g_sectionTitle,SectionInfo::Anchor,
g_sectionLevel);
Doxygen::sectionDict->append(anchorLabel,si);
docEntry->anchors->append(si);
}
}
outputXRef.resize(0);
}
Expand Down Expand Up @@ -643,18 +658,32 @@ static SectionInfo::SectionType sectionLevelToType(int level)

static void addSection()
{
// create a new section element
g_sectionTitle+=yytext;
g_sectionTitle=g_sectionTitle.stripWhiteSpace();
SectionInfo *si = new SectionInfo(yyFileName,g_sectionLabel,
SectionInfo *si = Doxygen::sectionDict->find(g_sectionLabel);
if (si)
{
if (si->lineNr != -1)
{
warn(yyFileName,yyLineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",g_sectionLabel.data(),si->fileName.data(),si->lineNr);
}
else
{
warn(yyFileName,yyLineNr,"multiple use of section label '%s', (first occurrence: %s)",g_sectionLabel.data(),si->fileName.data());
}
}
else
{
// create a new section element
g_sectionTitle+=yytext;
g_sectionTitle=g_sectionTitle.stripWhiteSpace();
si = new SectionInfo(yyFileName,yyLineNr,g_sectionLabel,
g_sectionTitle,sectionLevelToType(g_sectionLevel),g_sectionLevel);

// add section to this entry
current->anchors->append(si);

// add section to the global dictionary
Doxygen::sectionDict->append(g_sectionLabel,si);
// add section to this entry
current->anchors->append(si);

// add section to the global dictionary
Doxygen::sectionDict->append(g_sectionLabel,si);
}
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1701,9 +1730,24 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
/* ----- handle arguments of the anchor command ------- */

<AnchorLabel>{LABELID} { // found argument
SectionInfo *si = new SectionInfo(yyFileName,yytext,0,SectionInfo::Anchor,0);
Doxygen::sectionDict->append(yytext,si);
current->anchors->append(si);
SectionInfo *si = Doxygen::sectionDict->find(yytext);
if (si)
{
if (si->lineNr != -1)
{
warn(yyFileName,yyLineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",yytext,si->fileName.data(),si->lineNr);
}
else
{
warn(yyFileName,yyLineNr,"multiple use of section label '%s', (first occurrence: %s)",yytext,si->fileName.data());
}
}
else
{
si = new SectionInfo(yyFileName,yyLineNr,yytext,0,SectionInfo::Anchor,0);
Doxygen::sectionDict->append(yytext,si);
current->anchors->append(si);
}
addOutput(yytext);
BEGIN( Comment );
}
Expand Down Expand Up @@ -2876,9 +2920,9 @@ bool parseCommentBlock(/* in */ ParserInterface *parser,

if (Doxygen::markdownSupport)
{
current->brief = processMarkdown(fileName,current,current->brief);
current->doc = processMarkdown(fileName,current,current->doc);
current->inbodyDocs = processMarkdown(fileName,current,current->inbodyDocs);
current->brief = processMarkdown(fileName,lineNr,current,current->brief);
current->doc = processMarkdown(fileName,lineNr,current,current->doc);
current->inbodyDocs = processMarkdown(fileName,lineNr,current,current->inbodyDocs);
}

Debug::print(Debug::CommentScan,0,
Expand Down
25 changes: 20 additions & 5 deletions src/doxygen.cpp
Expand Up @@ -8643,15 +8643,30 @@ static void findMainPage(EntryNav *rootNav)
Doxygen::mainPage->setShowToc(root->stat);
addPageToContext(Doxygen::mainPage,rootNav);

// a page name is a label as well!
SectionInfo *si=new SectionInfo(
indexName,
SectionInfo *si = Doxygen::sectionDict->find(Doxygen::mainPage->name());
if (si)
{
if (si->lineNr != -1)
{
warn(root->fileName,root->startLine,"multiple use of section label '%s', (first occurrence: %s, line %d)",Doxygen::mainPage->name().data(),si->fileName.data(),si->lineNr);
}
else
{
warn(root->fileName,root->startLine,"multiple use of section label '%s', (first occurrence: %s)",Doxygen::mainPage->name().data(),si->fileName.data());
}
}
else
{
// a page name is a label as well! but should no be double either
si=new SectionInfo(
indexName, root->startLine,
Doxygen::mainPage->name(),
Doxygen::mainPage->title(),
SectionInfo::Page,
0); // level 0
Doxygen::sectionDict->append(indexName,si);
Doxygen::mainPage->addSectionsToDefinition(root->anchors);
Doxygen::sectionDict->append(indexName,si);
Doxygen::mainPage->addSectionsToDefinition(root->anchors);
}
}
else
{
Expand Down
53 changes: 43 additions & 10 deletions src/markdown.cpp
Expand Up @@ -48,6 +48,7 @@
#include "commentcnv.h"
#include "config.h"
#include "section.h"
#include "message.h"

//-----------

Expand Down Expand Up @@ -90,6 +91,7 @@ static QDict<LinkRef> g_linkRefs(257);
static action_t g_actions[256];
static Entry *g_current;
static QCString g_fileName;
static int g_lineNr;

// In case a markdown page starts with a level1 header, that header is used
// as a title of the page, in effect making it a level0 header, so the
Expand Down Expand Up @@ -1690,12 +1692,27 @@ void writeOneLineHeaderOrRuler(GrowBuf &out,const char *data,int size)
out.addStr(" ");
out.addStr(header);
out.addStr("\n");
SectionInfo *si = new SectionInfo(g_fileName,id,header,type,level);
if (g_current)
SectionInfo *si = Doxygen::sectionDict->find(header);
if (si)
{
g_current->anchors->append(si);
if (si->lineNr != -1)
{
warn(g_fileName,g_lineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",header.data(),si->fileName.data(),si->lineNr);
}
else
{
warn(g_fileName,g_lineNr,"multiple use of section label '%s', (first occurrence: %s)",header.data(),si->fileName.data());
}
}
else
{
si = new SectionInfo(g_fileName,g_lineNr,id,header,type,level);
if (g_current)
{
g_current->anchors->append(si);
}
Doxygen::sectionDict->append(header,si);
}
Doxygen::sectionDict->append(header,si);
}
else
{
Expand Down Expand Up @@ -2020,13 +2037,28 @@ static QCString processBlocks(const QCString &s,int indent)
out.addStr(" ");
out.addStr(header);
out.addStr("\n\n");
SectionInfo *si = new SectionInfo(g_fileName,id,header,
level==1 ? SectionInfo::Section : SectionInfo::Subsection,level);
if (g_current)
SectionInfo *si = Doxygen::sectionDict->find(header);
if (si)
{
g_current->anchors->append(si);
if (si->lineNr != -1)
{
warn(g_fileName,g_lineNr,"multiple use of section label '%s', (first occurrence: %s, line %d)",header.data(),si->fileName.data(),si->lineNr);
}
else
{
warn(g_fileName,g_lineNr,"multiple use of section label '%s', (first occurrence: %s)",header.data(),si->fileName.data());
}
}
else
{
si = new SectionInfo(g_fileName,g_lineNr,id,header,
level==1 ? SectionInfo::Section : SectionInfo::Subsection,level);
if (g_current)
{
g_current->anchors->append(si);
}
Doxygen::sectionDict->append(header,si);
}
Doxygen::sectionDict->append(header,si);
}
else
{
Expand Down Expand Up @@ -2214,7 +2246,7 @@ static QCString detab(const QCString &s,int &refIndent)

//---------------------------------------------------------------------------

QCString processMarkdown(const QCString &fileName,Entry *e,const QCString &input)
QCString processMarkdown(const QCString &fileName,const int lineNr,Entry *e,const QCString &input)
{
static bool init=FALSE;
if (!init)
Expand All @@ -2237,6 +2269,7 @@ QCString processMarkdown(const QCString &fileName,Entry *e,const QCString &input
g_linkRefs.clear();
g_current = e;
g_fileName = fileName;
g_lineNr = lineNr;
static GrowBuf out;
if (input.isEmpty()) return input;
out.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.h
Expand Up @@ -22,7 +22,7 @@
class Entry;

/** processes string \a s and converts markdown into doxygen/html commands. */
QCString processMarkdown(const QCString &fileName,Entry *e,const QCString &s);
QCString processMarkdown(const QCString &fileName,const int lineNr,Entry *e,const QCString &s);
QCString markdownFileNameToId(const QCString &fileName);

class MarkdownFileParser : public ParserInterface
Expand Down
4 changes: 3 additions & 1 deletion src/marshal.cpp
Expand Up @@ -139,6 +139,7 @@ void marshalSectionInfoList(StorageIntf *s, QList<SectionInfo> *anchors)
marshalQCString(s,si->ref);
marshalInt(s,(int)si->type);
marshalQCString(s,si->fileName);
marshalInt(s,si->lineNr);
marshalInt(s,si->level);
}
}
Expand Down Expand Up @@ -546,8 +547,9 @@ QList<SectionInfo> *unmarshalSectionInfoList(StorageIntf *s)
QCString ref = unmarshalQCString(s);
SectionInfo::SectionType type = (SectionInfo::SectionType)unmarshalInt(s);
QCString fileName = unmarshalQCString(s);
int lineNr = unmarshalInt(s);
int level = unmarshalInt(s);
result->append(new SectionInfo(fileName,label,title,type,level,ref));
result->append(new SectionInfo(fileName,lineNr,label,title,type,level,ref));
}
return result;
}
Expand Down
17 changes: 12 additions & 5 deletions src/section.h
Expand Up @@ -33,17 +33,23 @@ struct SectionInfo
Paragraph = 4,
Anchor = 5
};
SectionInfo(const char *f,const char *l,const char *t,
SectionInfo(const char *f,const int lin,const char *l,const char *t,
SectionType st,int lev,const char *r=0) :
label(l), title(t), type(st), ref(r), definition(0),
fileName(f), generated(FALSE), level(lev)
fileName(f), generated(FALSE), level(lev), lineNr(lin)
{
}
SectionInfo(const SectionInfo &s)
{
label=s.label.copy(); title=s.title.copy(); ref=s.ref.copy();
type =s.type; definition=s.definition;
fileName=s.fileName.copy(); generated=s.generated;
label=s.label.copy();
title=s.title.copy();
type =s.type;
ref=s.ref.copy();
definition=s.definition;
fileName=s.fileName.copy();
lineNr=s.lineNr;
generated=s.generated;
level=s.level;
}
~SectionInfo() {}
QCString label;
Expand All @@ -52,6 +58,7 @@ struct SectionInfo
QCString ref;
Definition *definition;
QCString fileName;
int lineNr;
bool generated;
int level;
};
Expand Down
2 changes: 1 addition & 1 deletion src/tagreader.cpp
Expand Up @@ -1120,7 +1120,7 @@ void TagFileParser::addDocAnchors(Entry *e,const TagAnchorInfoList &l)
{
//printf("New sectionInfo file=%s anchor=%s\n",
// ta->fileName.data(),ta->label.data());
SectionInfo *si=new SectionInfo(ta->fileName,ta->label,ta->title,
SectionInfo *si=new SectionInfo(ta->fileName,-1,ta->label,ta->title,
SectionInfo::Anchor,0,m_tagName);
Doxygen::sectionDict->append(ta->label,si);
e->anchors->append(si);
Expand Down
31 changes: 23 additions & 8 deletions src/util.cpp
Expand Up @@ -6280,14 +6280,29 @@ PageDef *addRelatedPage(const char *name,const QCString &ptitle,
{
file=pd->getOutputFileBase();
}
SectionInfo *si=new SectionInfo(
file,pd->name(),pd->title(),SectionInfo::Page,0,pd->getReference());
//printf("si->label=`%s' si->definition=%s si->fileName=`%s'\n",
// si->label.data(),si->definition?si->definition->name().data():"<none>",
// si->fileName.data());
//printf(" SectionInfo: sec=%p sec->fileName=%s\n",si,si->fileName.data());
//printf("Adding section key=%s si->fileName=%s\n",pageName.data(),si->fileName.data());
Doxygen::sectionDict->append(pd->name(),si);
SectionInfo *si = Doxygen::sectionDict->find(pd->name());
if (si)
{
if (si->lineNr != -1)
{
warn(file,-1,"multiple use of section label '%s', (first occurrence: %s, line %d)",pd->name().data(),si->fileName.data(),si->lineNr);
}
else
{
warn(file,-1,"multiple use of section label '%s', (first occurrence: %s)",pd->name().data(),si->fileName.data());
}
}
else
{
si=new SectionInfo(
file,-1,pd->name(),pd->title(),SectionInfo::Page,0,pd->getReference());
//printf("si->label=`%s' si->definition=%s si->fileName=`%s'\n",
// si->label.data(),si->definition?si->definition->name().data():"<none>",
// si->fileName.data());
//printf(" SectionInfo: sec=%p sec->fileName=%s\n",si,si->fileName.data());
//printf("Adding section key=%s si->fileName=%s\n",pageName.data(),si->fileName.data());
Doxygen::sectionDict->append(pd->name(),si);
}
}
}
return pd;
Expand Down

0 comments on commit ac611be

Please sign in to comment.