Commit c5ec90d1 authored by Dimitri van Heesch's avatar Dimitri van Heesch

Template and context enhancements

parent e47f3d06
...@@ -337,7 +337,14 @@ QCString ClassDef::displayName(bool includeScope) const ...@@ -337,7 +337,14 @@ QCString ClassDef::displayName(bool includeScope) const
// n = n.left(n.length()-2); // n = n.left(n.length()-2);
//} //}
//printf("ClassDef::displayName()=%s\n",n.data()); //printf("ClassDef::displayName()=%s\n",n.data());
return n; if (n.find('@')!=-1)
{
return removeAnonymousScopes(n);
}
else
{
return n;
}
} }
// inserts a base/super class in the inheritance list // inserts a base/super class in the inheritance list
...@@ -1542,7 +1549,7 @@ void ClassDef::writeSummaryLinks(OutputList &ol) ...@@ -1542,7 +1549,7 @@ void ClassDef::writeSummaryLinks(OutputList &ol)
MemberList * ml = getMemberList(lmd->type); MemberList * ml = getMemberList(lmd->type);
if (ml && ml->declVisible()) if (ml && ml->declVisible())
{ {
ol.writeSummaryLink(0,ml->listTypeAsString(ml->listType()),lmd->title(lang),first); ol.writeSummaryLink(0,MemberList::listTypeAsString(ml->listType()),lmd->title(lang),first);
first=FALSE; first=FALSE;
} }
} }
...@@ -2526,23 +2533,14 @@ bool ClassDef::hasNonReferenceSuperClass() ...@@ -2526,23 +2533,14 @@ bool ClassDef::hasNonReferenceSuperClass()
void ClassDef::writeDeclaration(OutputList &ol,MemberDef *md,bool inGroup, void ClassDef::writeDeclaration(OutputList &ol,MemberDef *md,bool inGroup,
ClassDef *inheritedFrom,const char *inheritId) ClassDef *inheritedFrom,const char *inheritId)
{ {
//ol.insertMemberAlign();
//printf("ClassName=`%s' inGroup=%d\n",name().data(),inGroup); //printf("ClassName=`%s' inGroup=%d\n",name().data(),inGroup);
//if (inGroup && md && md->getClassDef()==this) return;
ol.docify(compoundTypeString()); ol.docify(compoundTypeString());
int ri=name().findRev("::"); QCString cn = displayName(FALSE);
if (ri==-1) ri=name().length(); if (!cn.isEmpty())
QCString cn=name().right(name().length()-ri-2);
if (!cn.isEmpty() && cn.at(0)!='@' && md)
{ {
if (cn.right(2)=="-p" /*|| cn.right(2)=="-g"*/)
{
cn = cn.left(cn.length()-2);
}
ol.docify(" "); ol.docify(" ");
if (isLinkable()) if (md && isLinkable())
{ {
ol.writeObjectLink(0,0,md->anchor(),cn); ol.writeObjectLink(0,0,md->anchor(),cn);
} }
...@@ -3929,196 +3927,6 @@ void ClassDef::sortMemberLists() ...@@ -3929,196 +3927,6 @@ void ClassDef::sortMemberLists()
} }
} }
/** Computes for a given list type \a inListType, which are the
* the corresponding list type(s) in the base class that are to be
* added to this list.
*
* So for public inheritance, the mapping is 1-1, so outListType1=inListType
* Private members are to be hidden completely.
*
* For protected inheritance, both protected and public members of the
* base class should be joined in the protected member section.
*
* For private inheritance, both protected and public members of the
* base class should be joined in the private member section.
*/
static void convertProtectionLevel(
MemberListType inListType,
Protection inProt,
int *outListType1,
int *outListType2
)
{
static bool extractPrivate = Config_getBool("EXTRACT_PRIVATE");
// default representing 1-1 mapping
*outListType1=inListType;
*outListType2=-1;
if (inProt==Public)
{
switch (inListType) // in the private section of the derived class,
// the private section of the base class should not
// be visible
{
case MemberListType_priMethods:
case MemberListType_priStaticMethods:
case MemberListType_priSlots:
case MemberListType_priAttribs:
case MemberListType_priStaticAttribs:
case MemberListType_priTypes:
*outListType1=-1;
*outListType2=-1;
break;
default:
break;
}
}
else if (inProt==Protected) // Protected inheritance
{
switch (inListType) // in the protected section of the derived class,
// both the public and protected members are shown
// as protected
{
case MemberListType_pubMethods:
case MemberListType_pubStaticMethods:
case MemberListType_pubSlots:
case MemberListType_pubAttribs:
case MemberListType_pubStaticAttribs:
case MemberListType_pubTypes:
case MemberListType_priMethods:
case MemberListType_priStaticMethods:
case MemberListType_priSlots:
case MemberListType_priAttribs:
case MemberListType_priStaticAttribs:
case MemberListType_priTypes:
*outListType1=-1;
*outListType2=-1;
break;
case MemberListType_proMethods:
*outListType2=MemberListType_pubMethods;
break;
case MemberListType_proStaticMethods:
*outListType2=MemberListType_pubStaticMethods;
break;
case MemberListType_proSlots:
*outListType2=MemberListType_pubSlots;
break;
case MemberListType_proAttribs:
*outListType2=MemberListType_pubAttribs;
break;
case MemberListType_proStaticAttribs:
*outListType2=MemberListType_pubStaticAttribs;
break;
case MemberListType_proTypes:
*outListType2=MemberListType_pubTypes;
break;
default:
break;
}
}
else if (inProt==Private)
{
switch (inListType) // in the private section of the derived class,
// both the public and protected members are shown
// as private
{
case MemberListType_pubMethods:
case MemberListType_pubStaticMethods:
case MemberListType_pubSlots:
case MemberListType_pubAttribs:
case MemberListType_pubStaticAttribs:
case MemberListType_pubTypes:
case MemberListType_proMethods:
case MemberListType_proStaticMethods:
case MemberListType_proSlots:
case MemberListType_proAttribs:
case MemberListType_proStaticAttribs:
case MemberListType_proTypes:
*outListType1=-1;
*outListType2=-1;
break;
case MemberListType_priMethods:
if (extractPrivate)
{
*outListType1=MemberListType_pubMethods;
*outListType2=MemberListType_proMethods;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priStaticMethods:
if (extractPrivate)
{
*outListType1=MemberListType_pubStaticMethods;
*outListType2=MemberListType_proStaticMethods;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priSlots:
if (extractPrivate)
{
*outListType1=MemberListType_pubSlots;
*outListType1=MemberListType_proSlots;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priAttribs:
if (extractPrivate)
{
*outListType1=MemberListType_pubAttribs;
*outListType2=MemberListType_proAttribs;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priStaticAttribs:
if (extractPrivate)
{
*outListType1=MemberListType_pubStaticAttribs;
*outListType2=MemberListType_proStaticAttribs;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priTypes:
if (extractPrivate)
{
*outListType1=MemberListType_pubTypes;
*outListType2=MemberListType_proTypes;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
default:
break;
}
}
//printf("convertProtectionLevel(type=%d prot=%d): %d,%d\n",
// inListType,inProt,*outListType1,*outListType2);
}
int ClassDef::countMemberDeclarations(MemberListType lt,ClassDef *inheritedFrom, int ClassDef::countMemberDeclarations(MemberListType lt,ClassDef *inheritedFrom,
int lt2,bool invert,bool showAlways,QPtrDict<void> *visitedClasses) int lt2,bool invert,bool showAlways,QPtrDict<void> *visitedClasses)
{ {
...@@ -4157,7 +3965,7 @@ int ClassDef::countInheritedDecMembers(MemberListType lt, ...@@ -4157,7 +3965,7 @@ int ClassDef::countInheritedDecMembers(MemberListType lt,
QPtrDict<void> *visitedClasses) QPtrDict<void> *visitedClasses)
{ {
int inhCount = 0; int inhCount = 0;
int count = countMembersIncludingGrouped(lt,inheritedFrom,FALSE)>0; int count = countMembersIncludingGrouped(lt,inheritedFrom,FALSE);
bool process = count>0; bool process = count>0;
//printf("%s: countInheritedDecMembers: lt=%d process=%d count=%d invert=%d\n", //printf("%s: countInheritedDecMembers: lt=%d process=%d count=%d invert=%d\n",
// name().data(),lt,process,count,invert); // name().data(),lt,process,count,invert);
...@@ -4297,7 +4105,7 @@ void ClassDef::writeInheritedMemberDeclarations(OutputList &ol, ...@@ -4297,7 +4105,7 @@ void ClassDef::writeInheritedMemberDeclarations(OutputList &ol,
{ {
ol.pushGeneratorState(); ol.pushGeneratorState();
ol.disableAllBut(OutputGenerator::Html); ol.disableAllBut(OutputGenerator::Html);
int count = countMembersIncludingGrouped(lt,inheritedFrom,FALSE)>0; int count = countMembersIncludingGrouped(lt,inheritedFrom,FALSE);
bool process = count>0; bool process = count>0;
//printf("%s: writeInheritedMemberDec: lt=%d process=%d invert=%d always=%d\n", //printf("%s: writeInheritedMemberDec: lt=%d process=%d invert=%d always=%d\n",
// name().data(),lt,process,invert,showAlways); // name().data(),lt,process,invert,showAlways);
......
This diff is collapsed.
...@@ -614,6 +614,23 @@ class ExampleListContext : public TemplateStructIntf ...@@ -614,6 +614,23 @@ class ExampleListContext : public TemplateStructIntf
Private *p; Private *p;
}; };
//----------------------------------------------------
class NavPathElemContext : public TemplateStructIntf
{
public:
NavPathElemContext(Definition *def);
~NavPathElemContext();
// TemplateStructIntf methods
virtual TemplateVariant get(const char *name) const;
private:
class Private;
Private *p;
};
//---------------------------------------------------- //----------------------------------------------------
class InheritanceNodeContext : public TemplateStructIntf class InheritanceNodeContext : public TemplateStructIntf
...@@ -741,6 +758,41 @@ class MemberInfoContext : public TemplateStructIntf ...@@ -741,6 +758,41 @@ class MemberInfoContext : public TemplateStructIntf
//---------------------------------------------------- //----------------------------------------------------
class InheritedMemberInfoContext : public TemplateStructIntf
{
public:
InheritedMemberInfoContext(ClassDef *cd,MemberList *ml,const QCString &title);
~InheritedMemberInfoContext();
// TemplateStructIntf methods
virtual TemplateVariant get(const char *name) const;
private:
class Private;
Private *p;
};
//----------------------------------------------------
class InheritedMemberInfoListContext : public TemplateListIntf
{
public:
InheritedMemberInfoListContext();
void addMemberList(ClassDef *cd,MemberListType lt,const QCString &title,bool additionalList=TRUE);
~InheritedMemberInfoListContext();
// TemplateListIntf
virtual int count() const;
virtual TemplateVariant at(int index) const;
virtual TemplateListIntf::ConstIterator *createIterator() const;
private:
class Private;
Private *p;
};
//----------------------------------------------------
class AllMembersListContext : public TemplateListIntf class AllMembersListContext : public TemplateListIntf
{ {
public: public:
......
...@@ -11427,6 +11427,8 @@ void generateOutput() ...@@ -11427,6 +11427,8 @@ void generateOutput()
g_s.end(); g_s.end();
} }
if (g_useOutputTemplate) generateOutputViaTemplate();
if (generateRtf) if (generateRtf)
{ {
g_s.begin("Combining RTF output...\n"); g_s.begin("Combining RTF output...\n");
...@@ -11506,7 +11508,6 @@ void generateOutput() ...@@ -11506,7 +11508,6 @@ void generateOutput()
msg("finished...\n"); msg("finished...\n");
} }
if (g_useOutputTemplate) generateOutputViaTemplate();
/************************************************************************** /**************************************************************************
* Start cleaning up * * Start cleaning up *
......
...@@ -514,7 +514,7 @@ void FileDef::writeSummaryLinks(OutputList &ol) ...@@ -514,7 +514,7 @@ void FileDef::writeSummaryLinks(OutputList &ol)
MemberList * ml = getMemberList(lmd->type); MemberList * ml = getMemberList(lmd->type);
if (ml && ml->declVisible()) if (ml && ml->declVisible())
{ {
ol.writeSummaryLink(0,ml->listTypeAsString(ml->listType()),lmd->title(lang),first); ol.writeSummaryLink(0,MemberList::listTypeAsString(ml->listType()),lmd->title(lang),first);
first=FALSE; first=FALSE;
} }
} }
......
...@@ -913,7 +913,7 @@ void GroupDef::writeSummaryLinks(OutputList &ol) ...@@ -913,7 +913,7 @@ void GroupDef::writeSummaryLinks(OutputList &ol)
MemberList * ml = getMemberList(lmd->type); MemberList * ml = getMemberList(lmd->type);
if (ml && ml->declVisible()) if (ml && ml->declVisible())
{ {
ol.writeSummaryLink(0,ml->listTypeAsString(ml->listType()),lmd->title(lang),first); ol.writeSummaryLink(0,MemberList::listTypeAsString(ml->listType()),lmd->title(lang),first);
first=FALSE; first=FALSE;
} }
} }
......
...@@ -1409,9 +1409,6 @@ void MemberDef::writeDeclaration(OutputList &ol, ...@@ -1409,9 +1409,6 @@ void MemberDef::writeDeclaration(OutputList &ol,
// are explicitly grouped. // are explicitly grouped.
if (!inGroup && m_impl->mtype==MemberType_EnumValue) return; if (!inGroup && m_impl->mtype==MemberType_EnumValue) return;
// hide members whose brief section should not be visible
//if (!isBriefSectionVisible()) return;
Definition *d=0; Definition *d=0;
ASSERT (cd!=0 || nd!=0 || fd!=0 || gd!=0); // member should belong to something ASSERT (cd!=0 || nd!=0 || fd!=0 || gd!=0); // member should belong to something
if (cd) d=cd; else if (nd) d=nd; else if (fd) d=fd; else d=gd; if (cd) d=cd; else if (nd) d=nd; else if (fd) d=fd; else d=gd;
...@@ -1421,14 +1418,6 @@ void MemberDef::writeDeclaration(OutputList &ol, ...@@ -1421,14 +1418,6 @@ void MemberDef::writeDeclaration(OutputList &ol,
QCString cname = d->name(); QCString cname = d->name();
QCString cdname = d->displayName(); QCString cdname = d->displayName();
QCString cfname = getOutputFileBase(); QCString cfname = getOutputFileBase();
//QCString osname = cname;
// in case of class members that are put in a group the name of the outerscope
// differs from the cname.
//if (getOuterScope()) osname=getOuterScope()->name();
//HtmlHelp *htmlHelp=0;
//bool hasHtmlHelp = Config_getBool("GENERATE_HTML") && Config_getBool("GENERATE_HTMLHELP");
//if (hasHtmlHelp) htmlHelp = HtmlHelp::getInstance();
// search for the last anonymous scope in the member type // search for the last anonymous scope in the member type
ClassDef *annoClassDef=getClassDefOfAnonymousType(); ClassDef *annoClassDef=getClassDefOfAnonymousType();
...@@ -1445,15 +1434,27 @@ void MemberDef::writeDeclaration(OutputList &ol, ...@@ -1445,15 +1434,27 @@ void MemberDef::writeDeclaration(OutputList &ol,
// If there is no detailed description we need to write the anchor here. // If there is no detailed description we need to write the anchor here.
bool detailsVisible = isDetailedSectionLinkable(); bool detailsVisible = isDetailedSectionLinkable();
if (!detailsVisible && !m_impl->annMemb) if (!detailsVisible)
{ {
QCString doxyName=name().copy(); QCString doxyArgs=argsString();
if (!cname.isEmpty()) if (m_impl->annMemb)
{ {
doxyName.prepend(cdname+getLanguageSpecificSeparator(getLanguage())); QCString doxyName=m_impl->annMemb->name();
if (!cname.isEmpty())
{
doxyName.prepend(cdname+getLanguageSpecificSeparator(getLanguage()));
}
ol.startDoxyAnchor(cfname,cname,m_impl->annMemb->anchor(),doxyName,doxyArgs);
}
else
{
QCString doxyName=name();
if (!cname.isEmpty())
{
doxyName.prepend(cdname+getLanguageSpecificSeparator(getLanguage()));
}
ol.startDoxyAnchor(cfname,cname,anchor(),doxyName,doxyArgs);
} }
QCString doxyArgs=argsString();
ol.startDoxyAnchor(cfname,cname,anchor(),doxyName,doxyArgs);
ol.pushGeneratorState(); ol.pushGeneratorState();
ol.disable(OutputGenerator::Man); ol.disable(OutputGenerator::Man);
...@@ -2388,6 +2389,21 @@ QCString MemberDef::displayDefinition() const ...@@ -2388,6 +2389,21 @@ QCString MemberDef::displayDefinition() const
ldef=ldef.mid(2); ldef=ldef.mid(2);
} }
} }
static QRegExp r("@[0-9]+");
int l,i=r.match(ldef,0,&l);
if (i!=-1) // replace anonymous parts with { ... }
{
int si=ldef.find(' '),pi,ei=i+l;
if (si==-1) si=0;
while ((pi=r.match(ldef,i+l,&l))!=-1)
{
i=pi;
ei=i+l;
}
int ni=ldef.find("::",si);
if (ni>=ei) ei=ni+2;
ldef = ldef.left(si) + " { ... } " + ldef.right(ldef.length()-ei);
}
ClassDef *cd=getClassDef(); ClassDef *cd=getClassDef();
if (cd && cd->isObjectiveC()) if (cd && cd->isObjectiveC())
{ {
...@@ -2407,9 +2423,9 @@ QCString MemberDef::displayDefinition() const ...@@ -2407,9 +2423,9 @@ QCString MemberDef::displayDefinition() const
{ {
ldef=ldef.left(dp+1); ldef=ldef.left(dp+1);
} }
int l=ldef.length(); l=ldef.length();
//printf("start >%s<\n",ldef.data()); //printf("start >%s<\n",ldef.data());
int i=l-1; i=l-1;
while (i>=0 && (isId(ldef.at(i)) || ldef.at(i)==':')) i--; while (i>=0 && (isId(ldef.at(i)) || ldef.at(i)==':')) i--;
while (i>=0 && isspace((uchar)ldef.at(i))) i--; while (i>=0 && isspace((uchar)ldef.at(i))) i--;
if (i>0) if (i>0)
...@@ -2483,8 +2499,8 @@ void MemberDef::writeDocumentation(MemberList *ml,OutputList &ol, ...@@ -2483,8 +2499,8 @@ void MemberDef::writeDocumentation(MemberList *ml,OutputList &ol,
bool inFile = container->definitionType()==Definition::TypeFile; bool inFile = container->definitionType()==Definition::TypeFile;
bool hasDocs = isDetailedSectionVisible(inGroup,inFile); bool hasDocs = isDetailedSectionVisible(inGroup,inFile);
//printf("MemberDef::writeDocumentation(): name=`%s' hasDocs=`%d' containerType=%d inGroup=%d\n", //printf("MemberDef::writeDocumentation(): name=`%s' hasDocs=`%d' containerType=%d inGroup=%d sectionLinkable=%d\n",
// name().data(),hasDocs,container->definitionType(),inGroup); // name().data(),hasDocs,container->definitionType(),inGroup,isDetailedSectionLinkable());
if ( !hasDocs ) return; if ( !hasDocs ) return;
if (isEnumValue() && !showEnumValues) return; if (isEnumValue() && !showEnumValues) return;
...@@ -4656,6 +4672,11 @@ void MemberDef::setFromAnonymousMember(MemberDef *m) ...@@ -4656,6 +4672,11 @@ void MemberDef::setFromAnonymousMember(MemberDef *m)
m_impl->annMemb=m; m_impl->annMemb=m;
} }
MemberDef *MemberDef::fromAnonymousMember() const
{
return m_impl->annMemb;
}
void MemberDef::setTemplateMaster(MemberDef *mt) void MemberDef::setTemplateMaster(MemberDef *mt)
{ {
m_impl->templateMaster=mt; m_impl->templateMaster=mt;
......
...@@ -217,6 +217,7 @@ class MemberDef : public Definition ...@@ -217,6 +217,7 @@ class MemberDef : public Definition
bool fromAnonymousScope() const; bool fromAnonymousScope() const;
bool anonymousDeclShown() const; bool anonymousDeclShown() const;
MemberDef *fromAnonymousMember() const;
// callgraph related members // callgraph related members
bool hasCallGraph() const; bool hasCallGraph() const;
......
...@@ -878,7 +878,7 @@ void MemberList::setNeedsSorting(bool b) ...@@ -878,7 +878,7 @@ void MemberList::setNeedsSorting(bool b)
m_needsSorting = b; m_needsSorting = b;
} }
QCString MemberList::listTypeAsString(MemberListType type) const QCString MemberList::listTypeAsString(MemberListType type)
{ {
switch(type) switch(type)
{ {
......
...@@ -36,7 +36,7 @@ class MemberList : public QList<MemberDef> ...@@ -36,7 +36,7 @@ class MemberList : public QList<MemberDef>
MemberList(MemberListType lt); MemberList(MemberListType lt);
~MemberList(); ~MemberList();
MemberListType listType() const { return m_listType; } MemberListType listType() const { return m_listType; }
QCString listTypeAsString(MemberListType type) const; static QCString listTypeAsString(MemberListType type);
bool insert(uint index,const MemberDef *md); bool insert(uint index,const MemberDef *md);
void inSort(const MemberDef *md); void inSort(const MemberDef *md);
void append(const MemberDef *md); void append(const MemberDef *md);
......
...@@ -430,7 +430,7 @@ void NamespaceDef::writeSummaryLinks(OutputList &ol) ...@@ -430,7 +430,7 @@ void NamespaceDef::writeSummaryLinks(OutputList &ol)
MemberList * ml = getMemberList(lmd->type); MemberList * ml = getMemberList(lmd->type);
if (ml && ml->declVisible()) if (ml && ml->declVisible())
{ {
ol.writeSummaryLink(0,ml->listTypeAsString(ml->listType()),lmd->title(lang),first); ol.writeSummaryLink(0,MemberList::listTypeAsString(ml->listType()),lmd->title(lang),first);
first=FALSE; first=FALSE;
} }
} }
......
...@@ -1558,6 +1558,7 @@ class TemplateImpl : public TemplateNode, public Template ...@@ -1558,6 +1558,7 @@ class TemplateImpl : public TemplateNode, public Template
{ {
public: public:
TemplateImpl(TemplateEngine *e,const QCString &name,const QCString &data); TemplateImpl(TemplateEngine *e,const QCString &name,const QCString &data);
~TemplateImpl() {}
void render(FTextStream &ts, TemplateContext *c); void render(FTextStream &ts, TemplateContext *c);
TemplateEngine *engine() const { return m_engine; } TemplateEngine *engine() const { return m_engine; }
...@@ -1867,6 +1868,58 @@ class TemplateNodeIf : public TemplateNodeCreator<TemplateNodeIf> ...@@ -1867,6 +1868,58 @@ class TemplateNodeIf : public TemplateNodeCreator<TemplateNodeIf>
TemplateNodeList m_falseNodes; TemplateNodeList m_falseNodes;
}; };
//----------------------------------------------------------
/** @brief Class representing a 'for' tag in a template */
class TemplateNodeRepeat : public TemplateNodeCreator<TemplateNodeRepeat>
{
public:
TemplateNodeRepeat(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeRepeat>(parser,parent,line)
{
TRACE(("{TemplateNodeRepeat(%s)\n",data.data()));
ExpressionParser expParser(parser->templateName(),line);
m_expr = expParser.parseVariable(data);
QStrList stopAt;
stopAt.append("endrepeat");
parser->parse(this,line,stopAt,m_repeatNodes);
parser->removeNextToken(); // skip over endrepeat
TRACE(("}TemplateNodeRepeat(%s)\n",data.data()));
}
~TemplateNodeRepeat()
{
delete m_expr;
}
void render(FTextStream &ts, TemplateContext *c)
{
dynamic_cast<TemplateContextImpl*>(c)->setLocation(m_templateName,m_line);
TemplateVariant v;
if (m_expr && (v=m_expr->resolve(c)).type()==TemplateVariant::Integer)
{
int i, n = v.toInt();
for (i=0;i<n;i++)
{
TemplateStruct s;
s.set("counter0", (int)i);
s.set("counter", (int)(i+1));
s.set("revcounter", (int)(n-i));
s.set("revcounter0", (int)(n-i-1));
s.set("first",i==0);
s.set("last", i==n-1);
c->set("repeatloop",&s);
// render all items for this iteration of the loop
m_repeatNodes.render(ts,c);
}
}
else // simple type...
{
warn(m_templateName,m_line,"for requires a variable of list type!");
}
}
private:
TemplateNodeList m_repeatNodes;
ExprAst *m_expr;
};
//---------------------------------------------------------- //----------------------------------------------------------
/** @brief Class representing a 'for' tag in a template */ /** @brief Class representing a 'for' tag in a template */
...@@ -2165,7 +2218,8 @@ class TemplateNodeExtend : public TemplateNodeCreator<TemplateNodeExtend> ...@@ -2165,7 +2218,8 @@ class TemplateNodeExtend : public TemplateNodeCreator<TemplateNodeExtend>
TemplateImpl *t = getTemplate(); TemplateImpl *t = getTemplate();
if (t) if (t)
{ {
TemplateImpl *baseTemplate = dynamic_cast<TemplateImpl*>(t->engine()->loadByName(extendFile)); Template *bt = t->engine()->loadByName(extendFile);
TemplateImpl *baseTemplate = bt ? dynamic_cast<TemplateImpl*>(bt) : 0;
if (baseTemplate) if (baseTemplate)
{ {
// fill block context // fill block context
...@@ -2194,7 +2248,7 @@ class TemplateNodeExtend : public TemplateNodeCreator<TemplateNodeExtend> ...@@ -2194,7 +2248,7 @@ class TemplateNodeExtend : public TemplateNodeCreator<TemplateNodeExtend>
// clean up // clean up
bc->clear(); bc->clear();
delete baseTemplate; //delete baseTemplate;
} }
else else
{ {
...@@ -2242,7 +2296,8 @@ class TemplateNodeInclude : public TemplateNodeCreator<TemplateNodeInclude> ...@@ -2242,7 +2296,8 @@ class TemplateNodeInclude : public TemplateNodeCreator<TemplateNodeInclude>
TemplateImpl *t = getTemplate(); TemplateImpl *t = getTemplate();
if (t) if (t)
{ {
TemplateImpl *incTemplate = dynamic_cast<TemplateImpl*>(t->engine()->loadByName(includeFile)); Template *it = t->engine()->loadByName(includeFile);
TemplateImpl *incTemplate = it ? dynamic_cast<TemplateImpl*>(it) : 0;
if (incTemplate) if (incTemplate)
{ {
incTemplate->render(ts,c); incTemplate->render(ts,c);
...@@ -2324,7 +2379,8 @@ class TemplateNodeCreate : public TemplateNodeCreator<TemplateNodeCreate> ...@@ -2324,7 +2379,8 @@ class TemplateNodeCreate : public TemplateNodeCreator<TemplateNodeCreate>
TemplateImpl *t = getTemplate(); TemplateImpl *t = getTemplate();
if (t) if (t)
{ {
TemplateImpl *createTemplate = dynamic_cast<TemplateImpl*>(t->engine()->loadByName(templateFile)); Template *ct = t->engine()->loadByName(templateFile);
TemplateImpl *createTemplate = ct ? dynamic_cast<TemplateImpl*>(ct) : 0;
if (createTemplate) if (createTemplate)
{ {
if (!ci->outputDirectory().isEmpty()) if (!ci->outputDirectory().isEmpty())
...@@ -2336,7 +2392,7 @@ class TemplateNodeCreate : public TemplateNodeCreator<TemplateNodeCreate> ...@@ -2336,7 +2392,7 @@ class TemplateNodeCreate : public TemplateNodeCreator<TemplateNodeCreate>
{ {
FTextStream ts(&f); FTextStream ts(&f);
createTemplate->render(ts,c); createTemplate->render(ts,c);
delete createTemplate; //delete createTemplate;
} }
else else
{ {
...@@ -2729,6 +2785,9 @@ class TemplateNodeMarkers : public TemplateNodeCreator<TemplateNodeMarkers> ...@@ -2729,6 +2785,9 @@ class TemplateNodeMarkers : public TemplateNodeCreator<TemplateNodeMarkers>
for (it->toFirst(); (it->current(var)) && i<entryIndex; it->toNext(),i++) {} for (it->toFirst(); (it->current(var)) && i<entryIndex; it->toNext(),i++) {}
if (ok && i==entryIndex) // found element if (ok && i==entryIndex) // found element
{ {
TemplateStruct s;
s.set("id",(int)i);
c->set("markers",&s);
c->set(m_var,var); // define local variable to hold element of list type c->set(m_var,var); // define local variable to hold element of list type
bool wasSpaceless = ci->spacelessEnabled(); bool wasSpaceless = ci->spacelessEnabled();
ci->enableSpaceless(TRUE); ci->enableSpaceless(TRUE);
...@@ -2824,6 +2883,7 @@ static TemplateNodeFactory::AutoRegister<TemplateNodeBlock> autoRefBlock("bl ...@@ -2824,6 +2883,7 @@ static TemplateNodeFactory::AutoRegister<TemplateNodeBlock> autoRefBlock("bl
static TemplateNodeFactory::AutoRegister<TemplateNodeCycle> autoRefCycle("cycle"); static TemplateNodeFactory::AutoRegister<TemplateNodeCycle> autoRefCycle("cycle");
static TemplateNodeFactory::AutoRegister<TemplateNodeExtend> autoRefExtend("extend"); static TemplateNodeFactory::AutoRegister<TemplateNodeExtend> autoRefExtend("extend");
static TemplateNodeFactory::AutoRegister<TemplateNodeCreate> autoRefCreate("create"); static TemplateNodeFactory::AutoRegister<TemplateNodeCreate> autoRefCreate("create");
static TemplateNodeFactory::AutoRegister<TemplateNodeRepeat> autoRefRepeat("repeat");
static TemplateNodeFactory::AutoRegister<TemplateNodeInclude> autoRefInclude("include"); static TemplateNodeFactory::AutoRegister<TemplateNodeInclude> autoRefInclude("include");
static TemplateNodeFactory::AutoRegister<TemplateNodeMarkers> autoRefMarkers("markers"); static TemplateNodeFactory::AutoRegister<TemplateNodeMarkers> autoRefMarkers("markers");
static TemplateNodeFactory::AutoRegister<TemplateNodeSpaceless> autoRefSpaceless("spaceless"); static TemplateNodeFactory::AutoRegister<TemplateNodeSpaceless> autoRefSpaceless("spaceless");
...@@ -3186,7 +3246,8 @@ void TemplateParser::parse( ...@@ -3186,7 +3246,8 @@ void TemplateParser::parse(
command=="endif" || command=="endfor" || command=="endif" || command=="endfor" ||
command=="endblock" || command=="endwith" || command=="endblock" || command=="endwith" ||
command=="endrecursetree" || command=="endspaceless" || command=="endrecursetree" || command=="endspaceless" ||
command=="endmarkers" || command=="endmsg") command=="endmarkers" || command=="endmsg" ||
command=="endrepeat")
{ {
warn(m_templateName,tok->line,"Found tag '%s' without matching start tag",command.data()); warn(m_templateName,tok->line,"Found tag '%s' without matching start tag",command.data());
} }
...@@ -3288,13 +3349,45 @@ void TemplateImpl::render(FTextStream &ts, TemplateContext *c) ...@@ -3288,13 +3349,45 @@ void TemplateImpl::render(FTextStream &ts, TemplateContext *c)
class TemplateEngine::Private class TemplateEngine::Private
{ {
public: public:
Private() { templates.setAutoDelete(TRUE); } Private(TemplateEngine *engine) : m_templateCache(17), m_engine(engine)
QList<Template> templates; { m_templateCache.setAutoDelete(TRUE); }
Template *loadByName(const QCString &fileName) const
{
Template *templ = m_templateCache.find(fileName);
if (templ==0)
{
QFile f(fileName);
if (f.open(IO_ReadOnly))
{
uint size=f.size();
char *data = new char[size+1];
if (data)
{
data[size]=0;
if (f.readBlock(data,f.size()))
{
templ = new TemplateImpl(m_engine,fileName,data);
m_templateCache.insert(fileName,templ);
}
delete[] data;
}
}
else
{
err("Cound not open template file %s\n",fileName.data());
}
}
return templ;
}
private:
mutable QDict<Template> m_templateCache;
TemplateEngine *m_engine;
}; };
TemplateEngine::TemplateEngine() TemplateEngine::TemplateEngine()
{ {
p = new Private; p = new Private(this);
} }
TemplateEngine::~TemplateEngine() TemplateEngine::~TemplateEngine()
...@@ -3307,32 +3400,8 @@ TemplateContext *TemplateEngine::createContext() const ...@@ -3307,32 +3400,8 @@ TemplateContext *TemplateEngine::createContext() const
return new TemplateContextImpl; return new TemplateContextImpl;
} }
Template *TemplateEngine::newTemplate(const QCString &name,const QCString &data)
{
Template *t = new TemplateImpl(this,name,data);
p->templates.append(t);
return t;
}
Template *TemplateEngine::loadByName(const QCString &fileName) Template *TemplateEngine::loadByName(const QCString &fileName)
{ {
Template *t=0; return p->loadByName(fileName);
QFile f(fileName);
if (f.open(IO_ReadOnly))
{
uint size=f.size();
char *data = new char[size+1];
if (data)
{
data[size]=0;
if (f.readBlock(data,f.size()))
{
t = new TemplateImpl(this,fileName,data);
}
delete[] data;
}
}
return t;
} }
...@@ -443,13 +443,6 @@ class TemplateEngine ...@@ -443,13 +443,6 @@ class TemplateEngine
*/ */
TemplateContext *createContext() const; TemplateContext *createContext() const;
/** Creates a new template whose contents are given by a string.
* @param[in] name The name of the template.
* @param[in] data The contents of the template.
* @return the new template, the caller will be the owner.
*/
Template *newTemplate(const QCString &name,const QCString &data);
/** Creates a new template whole contents are in a file. /** Creates a new template whole contents are in a file.
* @param[in] fileName The name of the file containing the * @param[in] fileName The name of the file containing the
* template data * template data
......
...@@ -8080,3 +8080,193 @@ QCString extractDirection(QCString &docs) ...@@ -8080,3 +8080,193 @@ QCString extractDirection(QCString &docs)
return QCString(); return QCString();
} }
//-----------------------------------------------------------
/** Computes for a given list type \a inListType, which are the
* the corresponding list type(s) in the base class that are to be
* added to this list.
*
* So for public inheritance, the mapping is 1-1, so outListType1=inListType
* Private members are to be hidden completely.
*
* For protected inheritance, both protected and public members of the
* base class should be joined in the protected member section.
*
* For private inheritance, both protected and public members of the
* base class should be joined in the private member section.
*/
void convertProtectionLevel(
MemberListType inListType,
Protection inProt,
int *outListType1,
int *outListType2
)
{
static bool extractPrivate = Config_getBool("EXTRACT_PRIVATE");
// default representing 1-1 mapping
*outListType1=inListType;
*outListType2=-1;
if (inProt==Public)
{
switch (inListType) // in the private section of the derived class,
// the private section of the base class should not
// be visible
{
case MemberListType_priMethods:
case MemberListType_priStaticMethods:
case MemberListType_priSlots:
case MemberListType_priAttribs:
case MemberListType_priStaticAttribs:
case MemberListType_priTypes:
*outListType1=-1;
*outListType2=-1;
break;
default:
break;
}
}
else if (inProt==Protected) // Protected inheritance
{
switch (inListType) // in the protected section of the derived class,
// both the public and protected members are shown
// as protected
{
case MemberListType_pubMethods:
case MemberListType_pubStaticMethods:
case MemberListType_pubSlots:
case MemberListType_pubAttribs:
case MemberListType_pubStaticAttribs:
case MemberListType_pubTypes:
case MemberListType_priMethods:
case MemberListType_priStaticMethods:
case MemberListType_priSlots:
case MemberListType_priAttribs:
case MemberListType_priStaticAttribs:
case MemberListType_priTypes:
*outListType1=-1;
*outListType2=-1;
break;
case MemberListType_proMethods:
*outListType2=MemberListType_pubMethods;
break;
case MemberListType_proStaticMethods:
*outListType2=MemberListType_pubStaticMethods;
break;
case MemberListType_proSlots:
*outListType2=MemberListType_pubSlots;
break;
case MemberListType_proAttribs:
*outListType2=MemberListType_pubAttribs;
break;
case MemberListType_proStaticAttribs:
*outListType2=MemberListType_pubStaticAttribs;
break;
case MemberListType_proTypes:
*outListType2=MemberListType_pubTypes;
break;
default:
break;
}
}
else if (inProt==Private)
{
switch (inListType) // in the private section of the derived class,
// both the public and protected members are shown
// as private
{
case MemberListType_pubMethods:
case MemberListType_pubStaticMethods:
case MemberListType_pubSlots:
case MemberListType_pubAttribs:
case MemberListType_pubStaticAttribs:
case MemberListType_pubTypes:
case MemberListType_proMethods:
case MemberListType_proStaticMethods:
case MemberListType_proSlots:
case MemberListType_proAttribs:
case MemberListType_proStaticAttribs:
case MemberListType_proTypes:
*outListType1=-1;
*outListType2=-1;
break;
case MemberListType_priMethods:
if (extractPrivate)
{
*outListType1=MemberListType_pubMethods;
*outListType2=MemberListType_proMethods;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priStaticMethods:
if (extractPrivate)
{
*outListType1=MemberListType_pubStaticMethods;
*outListType2=MemberListType_proStaticMethods;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priSlots:
if (extractPrivate)
{
*outListType1=MemberListType_pubSlots;
*outListType1=MemberListType_proSlots;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priAttribs:
if (extractPrivate)
{
*outListType1=MemberListType_pubAttribs;
*outListType2=MemberListType_proAttribs;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priStaticAttribs:
if (extractPrivate)
{
*outListType1=MemberListType_pubStaticAttribs;
*outListType2=MemberListType_proStaticAttribs;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
case MemberListType_priTypes:
if (extractPrivate)
{
*outListType1=MemberListType_pubTypes;
*outListType2=MemberListType_proTypes;
}
else
{
*outListType1=-1;
*outListType2=-1;
}
break;
default:
break;
}
}
//printf("convertProtectionLevel(type=%d prot=%d): %d,%d\n",
// inListType,inProt,*outListType1,*outListType2);
}
...@@ -448,5 +448,12 @@ uint getUtf8CodeToUpper( const QCString& s, int idx ); ...@@ -448,5 +448,12 @@ uint getUtf8CodeToUpper( const QCString& s, int idx );
QCString extractDirection(QCString &docs); QCString extractDirection(QCString &docs);
void convertProtectionLevel(
MemberListType inListType,
Protection inProt,
int *outListType1,
int *outListType2
);
#endif #endif
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