Commit ac611be4 authored by albert-github's avatar albert-github

In case of sections with the same name they are not reported.

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.
parent 8eeaae0b
...@@ -553,7 +553,7 @@ static void addXRefItem(const char *listName,const char *itemTitle, ...@@ -553,7 +553,7 @@ static void addXRefItem(const char *listName,const char *itemTitle,
item->text += " <p>"; item->text += " <p>";
if (Doxygen::markdownSupport) if (Doxygen::markdownSupport)
{ {
item->text += processMarkdown(yyFileName,current,outputXRef); item->text += processMarkdown(yyFileName,yyLineNr,current,outputXRef);
} }
else else
{ {
...@@ -575,7 +575,7 @@ static void addXRefItem(const char *listName,const char *itemTitle, ...@@ -575,7 +575,7 @@ static void addXRefItem(const char *listName,const char *itemTitle,
ASSERT(item!=0); ASSERT(item!=0);
if (Doxygen::markdownSupport) if (Doxygen::markdownSupport)
{ {
item->text = processMarkdown(yyFileName,current,outputXRef); item->text = processMarkdown(yyFileName,yyLineNr,current,outputXRef);
} }
else else
{ {
...@@ -593,11 +593,26 @@ static void addXRefItem(const char *listName,const char *itemTitle, ...@@ -593,11 +593,26 @@ static void addXRefItem(const char *listName,const char *itemTitle,
{ {
docEntry->doc += cmdString; docEntry->doc += cmdString;
} }
SectionInfo *si=new SectionInfo(listName,anchorLabel, SectionInfo *si = Doxygen::sectionDict->find(anchorLabel);
g_sectionTitle,SectionInfo::Anchor, if (si)
g_sectionLevel); {
Doxygen::sectionDict->append(anchorLabel,si); if (si->lineNr != -1)
docEntry->anchors->append(si); {
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); outputXRef.resize(0);
} }
...@@ -643,18 +658,32 @@ static SectionInfo::SectionType sectionLevelToType(int level) ...@@ -643,18 +658,32 @@ static SectionInfo::SectionType sectionLevelToType(int level)
static void addSection() static void addSection()
{ {
// create a new section element SectionInfo *si = Doxygen::sectionDict->find(g_sectionLabel);
g_sectionTitle+=yytext; if (si)
g_sectionTitle=g_sectionTitle.stripWhiteSpace(); {
SectionInfo *si = new SectionInfo(yyFileName,g_sectionLabel, 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); g_sectionTitle,sectionLevelToType(g_sectionLevel),g_sectionLevel);
// add section to this entry // add section to this entry
current->anchors->append(si); current->anchors->append(si);
// add section to the global dictionary
Doxygen::sectionDict->append(g_sectionLabel,si);
// add section to the global dictionary
Doxygen::sectionDict->append(g_sectionLabel,si);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -1701,9 +1730,24 @@ RCSTAG "$"{ID}":"[^\n$]+"$" ...@@ -1701,9 +1730,24 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
/* ----- handle arguments of the anchor command ------- */ /* ----- handle arguments of the anchor command ------- */
<AnchorLabel>{LABELID} { // found argument <AnchorLabel>{LABELID} { // found argument
SectionInfo *si = new SectionInfo(yyFileName,yytext,0,SectionInfo::Anchor,0); SectionInfo *si = Doxygen::sectionDict->find(yytext);
Doxygen::sectionDict->append(yytext,si); if (si)
current->anchors->append(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); addOutput(yytext);
BEGIN( Comment ); BEGIN( Comment );
} }
...@@ -2876,9 +2920,9 @@ bool parseCommentBlock(/* in */ ParserInterface *parser, ...@@ -2876,9 +2920,9 @@ bool parseCommentBlock(/* in */ ParserInterface *parser,
if (Doxygen::markdownSupport) if (Doxygen::markdownSupport)
{ {
current->brief = processMarkdown(fileName,current,current->brief); current->brief = processMarkdown(fileName,lineNr,current,current->brief);
current->doc = processMarkdown(fileName,current,current->doc); current->doc = processMarkdown(fileName,lineNr,current,current->doc);
current->inbodyDocs = processMarkdown(fileName,current,current->inbodyDocs); current->inbodyDocs = processMarkdown(fileName,lineNr,current,current->inbodyDocs);
} }
Debug::print(Debug::CommentScan,0, Debug::print(Debug::CommentScan,0,
......
...@@ -8643,15 +8643,30 @@ static void findMainPage(EntryNav *rootNav) ...@@ -8643,15 +8643,30 @@ static void findMainPage(EntryNav *rootNav)
Doxygen::mainPage->setShowToc(root->stat); Doxygen::mainPage->setShowToc(root->stat);
addPageToContext(Doxygen::mainPage,rootNav); addPageToContext(Doxygen::mainPage,rootNav);
// a page name is a label as well! SectionInfo *si = Doxygen::sectionDict->find(Doxygen::mainPage->name());
SectionInfo *si=new SectionInfo( if (si)
indexName, {
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->name(),
Doxygen::mainPage->title(), Doxygen::mainPage->title(),
SectionInfo::Page, SectionInfo::Page,
0); // level 0 0); // level 0
Doxygen::sectionDict->append(indexName,si); Doxygen::sectionDict->append(indexName,si);
Doxygen::mainPage->addSectionsToDefinition(root->anchors); Doxygen::mainPage->addSectionsToDefinition(root->anchors);
}
} }
else else
{ {
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "commentcnv.h" #include "commentcnv.h"
#include "config.h" #include "config.h"
#include "section.h" #include "section.h"
#include "message.h"
//----------- //-----------
...@@ -90,6 +91,7 @@ static QDict<LinkRef> g_linkRefs(257); ...@@ -90,6 +91,7 @@ static QDict<LinkRef> g_linkRefs(257);
static action_t g_actions[256]; static action_t g_actions[256];
static Entry *g_current; static Entry *g_current;
static QCString g_fileName; static QCString g_fileName;
static int g_lineNr;
// In case a markdown page starts with a level1 header, that header is used // 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 // as a title of the page, in effect making it a level0 header, so the
...@@ -1690,12 +1692,27 @@ void writeOneLineHeaderOrRuler(GrowBuf &out,const char *data,int size) ...@@ -1690,12 +1692,27 @@ void writeOneLineHeaderOrRuler(GrowBuf &out,const char *data,int size)
out.addStr(" "); out.addStr(" ");
out.addStr(header); out.addStr(header);
out.addStr("\n"); out.addStr("\n");
SectionInfo *si = new SectionInfo(g_fileName,id,header,type,level); SectionInfo *si = Doxygen::sectionDict->find(header);
if (g_current) 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 else
{ {
...@@ -2020,13 +2037,28 @@ static QCString processBlocks(const QCString &s,int indent) ...@@ -2020,13 +2037,28 @@ static QCString processBlocks(const QCString &s,int indent)
out.addStr(" "); out.addStr(" ");
out.addStr(header); out.addStr(header);
out.addStr("\n\n"); out.addStr("\n\n");
SectionInfo *si = new SectionInfo(g_fileName,id,header, SectionInfo *si = Doxygen::sectionDict->find(header);
level==1 ? SectionInfo::Section : SectionInfo::Subsection,level); if (si)
if (g_current)
{ {
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 else
{ {
...@@ -2214,7 +2246,7 @@ static QCString detab(const QCString &s,int &refIndent) ...@@ -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; static bool init=FALSE;
if (!init) if (!init)
...@@ -2237,6 +2269,7 @@ QCString processMarkdown(const QCString &fileName,Entry *e,const QCString &input ...@@ -2237,6 +2269,7 @@ QCString processMarkdown(const QCString &fileName,Entry *e,const QCString &input
g_linkRefs.clear(); g_linkRefs.clear();
g_current = e; g_current = e;
g_fileName = fileName; g_fileName = fileName;
g_lineNr = lineNr;
static GrowBuf out; static GrowBuf out;
if (input.isEmpty()) return input; if (input.isEmpty()) return input;
out.clear(); out.clear();
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
class Entry; class Entry;
/** processes string \a s and converts markdown into doxygen/html commands. */ /** 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); QCString markdownFileNameToId(const QCString &fileName);
class MarkdownFileParser : public ParserInterface class MarkdownFileParser : public ParserInterface
......
...@@ -139,6 +139,7 @@ void marshalSectionInfoList(StorageIntf *s, QList<SectionInfo> *anchors) ...@@ -139,6 +139,7 @@ void marshalSectionInfoList(StorageIntf *s, QList<SectionInfo> *anchors)
marshalQCString(s,si->ref); marshalQCString(s,si->ref);
marshalInt(s,(int)si->type); marshalInt(s,(int)si->type);
marshalQCString(s,si->fileName); marshalQCString(s,si->fileName);
marshalInt(s,si->lineNr);
marshalInt(s,si->level); marshalInt(s,si->level);
} }
} }
...@@ -546,8 +547,9 @@ QList<SectionInfo> *unmarshalSectionInfoList(StorageIntf *s) ...@@ -546,8 +547,9 @@ QList<SectionInfo> *unmarshalSectionInfoList(StorageIntf *s)
QCString ref = unmarshalQCString(s); QCString ref = unmarshalQCString(s);
SectionInfo::SectionType type = (SectionInfo::SectionType)unmarshalInt(s); SectionInfo::SectionType type = (SectionInfo::SectionType)unmarshalInt(s);
QCString fileName = unmarshalQCString(s); QCString fileName = unmarshalQCString(s);
int lineNr = unmarshalInt(s);
int level = 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; return result;
} }
......
...@@ -33,17 +33,23 @@ struct SectionInfo ...@@ -33,17 +33,23 @@ struct SectionInfo
Paragraph = 4, Paragraph = 4,
Anchor = 5 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) : SectionType st,int lev,const char *r=0) :
label(l), title(t), type(st), ref(r), definition(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) SectionInfo(const SectionInfo &s)
{ {
label=s.label.copy(); title=s.title.copy(); ref=s.ref.copy(); label=s.label.copy();
type =s.type; definition=s.definition; title=s.title.copy();
fileName=s.fileName.copy(); generated=s.generated; type =s.type;
ref=s.ref.copy();
definition=s.definition;
fileName=s.fileName.copy();
lineNr=s.lineNr;
generated=s.generated;
level=s.level;
} }
~SectionInfo() {} ~SectionInfo() {}
QCString label; QCString label;
...@@ -52,6 +58,7 @@ struct SectionInfo ...@@ -52,6 +58,7 @@ struct SectionInfo
QCString ref; QCString ref;
Definition *definition; Definition *definition;
QCString fileName; QCString fileName;
int lineNr;
bool generated; bool generated;
int level; int level;
}; };
......
...@@ -1120,7 +1120,7 @@ void TagFileParser::addDocAnchors(Entry *e,const TagAnchorInfoList &l) ...@@ -1120,7 +1120,7 @@ void TagFileParser::addDocAnchors(Entry *e,const TagAnchorInfoList &l)
{ {
//printf("New sectionInfo file=%s anchor=%s\n", //printf("New sectionInfo file=%s anchor=%s\n",
// ta->fileName.data(),ta->label.data()); // 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); SectionInfo::Anchor,0,m_tagName);
Doxygen::sectionDict->append(ta->label,si); Doxygen::sectionDict->append(ta->label,si);
e->anchors->append(si); e->anchors->append(si);
......
...@@ -6280,14 +6280,29 @@ PageDef *addRelatedPage(const char *name,const QCString &ptitle, ...@@ -6280,14 +6280,29 @@ PageDef *addRelatedPage(const char *name,const QCString &ptitle,
{ {
file=pd->getOutputFileBase(); file=pd->getOutputFileBase();
} }
SectionInfo *si=new SectionInfo( SectionInfo *si = Doxygen::sectionDict->find(pd->name());
file,pd->name(),pd->title(),SectionInfo::Page,0,pd->getReference()); if (si)
//printf("si->label=`%s' si->definition=%s si->fileName=`%s'\n", {
// si->label.data(),si->definition?si->definition->name().data():"<none>", if (si->lineNr != -1)
// si->fileName.data()); {
//printf(" SectionInfo: sec=%p sec->fileName=%s\n",si,si->fileName.data()); warn(file,-1,"multiple use of section label '%s', (first occurrence: %s, line %d)",pd->name().data(),si->fileName.data(),si->lineNr);
//printf("Adding section key=%s si->fileName=%s\n",pageName.data(),si->fileName.data()); }
Doxygen::sectionDict->append(pd->name(),si); 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; return pd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment