Commit 00b7d393 authored by Dimitri van Heesch's avatar Dimitri van Heesch

More context and template additions

parent 727e5e1c
......@@ -2446,12 +2446,12 @@ bool ClassDef::addExample(const char *anchor,const char *nameStr,
}
// returns TRUE if this class is used in an example
bool ClassDef::hasExamples()
bool ClassDef::hasExamples() const
{
if (m_impl->exampleSDict==0)
return FALSE;
else
return m_impl->exampleSDict->count()>0;
bool result=FALSE;
if (m_impl->exampleSDict)
result = m_impl->exampleSDict->count()>0;
return result;
}
......@@ -4758,3 +4758,12 @@ const FileList &ClassDef::usedFiles() const
return m_impl->files;
}
const ArgumentList *ClassDef::typeConstraints() const
{
return m_impl->typeConstraints;
}
const ExampleSDict *ClassDef::exampleList() const
{
return m_impl->exampleSDict;
}
......@@ -313,6 +313,11 @@ class ClassDef : public Definition
QCString includeStatement() const;
const ArgumentList *typeConstraints() const;
const ExampleSDict *exampleList() const;
bool hasExamples() const;
QCString getMemberListFileName() const;
//-----------------------------------------------------------------------------------
// --- setters ----
//-----------------------------------------------------------------------------------
......@@ -384,7 +389,6 @@ class ClassDef : public Definition
protected:
void addUsedInterfaceClasses(MemberDef *md,const char *typeStr);
bool hasExamples();
bool hasNonReferenceSuperClass();
void showUsedFiles(OutputList &ol);
......@@ -392,7 +396,6 @@ class ClassDef : public Definition
void writeTagFileMarker();
void writeDocumentationContents(OutputList &ol,const QCString &pageTitle);
void internalInsertMember(MemberDef *md,Protection prot,bool addToAllList);
QCString getMemberListFileName() const;
void addMemberToList(MemberListType lt,MemberDef *md,bool isBrief);
MemberList *createMemberList(MemberListType lt);
void writeInheritedMemberDeclarations(OutputList &ol,MemberListType lt,int lt2,const QCString &title,ClassDef *inheritedFrom,bool invert,bool showAlways,QPtrDict<void> *visitedClasses);
......
This diff is collapsed.
......@@ -28,6 +28,8 @@ class MemberList;
class MemberDef;
struct Argument;
class ArgumentList;
class MemberNameInfoSDict;
struct MemberInfo;
//----------------------------------------------------
......@@ -679,10 +681,44 @@ class MemberListInfoContext : public TemplateStructIntf
//----------------------------------------------------
class MemberInfoContext : public TemplateStructIntf
{
public:
MemberInfoContext(const MemberInfo *mi);
~MemberInfoContext();
// TemplateStructIntf methods
virtual TemplateVariant get(const char *name) const;
private:
class Private;
Private *p;
};
//----------------------------------------------------
class AllMembersListContext : public TemplateListIntf
{
public:
AllMembersListContext(const MemberNameInfoSDict *ml);
~AllMembersListContext();
// TemplateListIntf
virtual int count() const;
virtual TemplateVariant at(int index) const;
virtual TemplateListIntf::ConstIterator *createIterator() const;
private:
class Private;
Private *p;
};
//----------------------------------------------------
class ArgumentContext : public TemplateStructIntf
{
public:
ArgumentContext(const Argument *arg);
ArgumentContext(const Argument *arg,Definition *def,const QCString &relPath);
~ArgumentContext();
// TemplateStructIntf methods
......@@ -698,7 +734,7 @@ class ArgumentContext : public TemplateStructIntf
class ArgumentListContext : public TemplateListIntf
{
public:
ArgumentListContext(const ArgumentList *al);
ArgumentListContext(const ArgumentList *al,Definition *def,const QCString &relPath);
~ArgumentListContext();
// TemplateListIntf
......
......@@ -959,7 +959,7 @@ void Definition::writeSourceDef(OutputList &ol,const char *)
{
ol.disable(OutputGenerator::Latex);
}
// write line link (HTML, LaTeX optionally)
// write file link (HTML, LaTeX optionally)
ol.writeObjectLink(0,fn,0,m_impl->body->fileDef->name());
ol.enableAll();
ol.disable(OutputGenerator::Html);
......
......@@ -3279,7 +3279,7 @@ void HtmlGenerator::writeExternalSearchPage()
void HtmlGenerator::startConstraintList(const char *header)
{
t << "<div class=\"typeconstraint\">" << endl;
t << "<dl><dt><b>" << header << "</b><dt><dd>" << endl;
t << "<dl><dt><b>" << header << "</b></dt><dd>" << endl;
t << "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\">" << endl;
}
......
......@@ -128,7 +128,6 @@ static bool writeDefArgumentList(OutputList &ol,ClassDef *cd,
{
return FALSE; // member has no function like argument list
}
if (!md->isDefine()) ol.docify(" ");
// simple argument list for tcl
if (md->getLanguage()==SrcLangExt_Tcl)
......@@ -156,6 +155,8 @@ static bool writeDefArgumentList(OutputList &ol,ClassDef *cd,
return TRUE;
}
if (!md->isDefine()) ol.docify(" ");
//printf("writeDefArgList(%d)\n",defArgList->count());
ol.pushGeneratorState();
//ol.disableAllBut(OutputGenerator::Html);
......@@ -262,7 +263,7 @@ static bool writeDefArgumentList(OutputList &ol,ClassDef *cd,
{
ol.docify(a->type.mid(wp,vp-wp));
}
if (!a->name.isEmpty() || (a->name.isEmpty() && a->type=="...")) // argument has a name
if (!a->name.isEmpty() || a->type=="...") // argument has a name
{
//if (!hasFuncPtrType)
//{
......@@ -1925,7 +1926,7 @@ bool MemberDef::isDetailedSectionVisible(bool inGroup,bool inFile) const
return result;
}
void MemberDef::_getLabels(QStrList &sl,Definition *container) const
void MemberDef::getLabels(QStrList &sl,Definition *container) const
{
static bool inlineInfo = Config_getBool("INLINE_INFO");
......@@ -2382,6 +2383,69 @@ void MemberDef::_writeEnumValues(OutputList &ol,Definition *container,
}
}
QCString MemberDef::displayDefinition() const
{
QCString ldef = definition();
QCString title = name();
if (isEnumerate())
{
if (title.at(0)=='@')
{
ldef = title = "anonymous enum";
if (!m_impl->enumBaseType.isEmpty())
{
ldef+=" : "+m_impl->enumBaseType;
}
}
else
{
ldef.prepend("enum ");
}
}
else if (isEnumValue())
{
if (ldef.at(0)=='@')
{
ldef=ldef.mid(2);
}
}
ClassDef *cd=getClassDef();
if (cd && cd->isObjectiveC())
{
// strip scope name
int ep = ldef.find("::");
if (ep!=-1)
{
int sp=ldef.findRev(' ',ep);
if (sp!=-1)
{
ldef=ldef.left(sp+1)+ldef.mid(ep+2);
}
}
// strip keywords
int dp = ldef.find(':');
if (dp!=-1)
{
ldef=ldef.left(dp+1);
}
int l=ldef.length();
//printf("start >%s<\n",ldef.data());
int i=l-1;
while (i>=0 && (isId(ldef.at(i)) || ldef.at(i)==':')) i--;
while (i>=0 && isspace((uchar)ldef.at(i))) i--;
if (i>0)
{
// insert braches around the type
QCString tmp("("+ldef.left(i+1)+")"+ldef.mid(i+1));
ldef=tmp;
}
//printf("end >%s< i=%d\n",ldef.data(),i);
if (isStatic()) ldef.prepend("+ "); else ldef.prepend("- ");
}
SrcLangExt lang = getLanguage();
QCString sep = getLanguageSpecificSeparator(lang,TRUE);
return substitute(ldef,"::",sep);
}
/*! Writes the "detailed documentation" section of this member to
* all active output formats.
......@@ -2473,7 +2537,7 @@ void MemberDef::writeDocumentation(MemberList *ml,OutputList &ol,
bool htmlEndLabelTable=FALSE;
QStrList sl;
_getLabels(sl,container);
getLabels(sl,container);
if ((isVariable() || isTypedef()) && (i=r.match(ldef,0,&l))!=-1)
{
......
......@@ -75,6 +75,7 @@ class MemberDef : public Definition
int initializerLines() const;
uint64 getMemberSpecifiers() const;
MemberList *getSectionList(Definition *d) const;
QCString displayDefinition() const;
// scope query members
ClassDef *getClassDef() const;
......@@ -242,6 +243,7 @@ class MemberDef : public Definition
QCString displayName(bool=TRUE) const;
QCString getDeclType() const;
void getLabels(QStrList &sl,Definition *container) const;
//-----------------------------------------------------------------------------------
// ---- setters -----
......@@ -384,7 +386,6 @@ class MemberDef : public Definition
void _computeLinkableInProject();
void _computeIsConstructor();
void _computeIsDestructor();
void _getLabels(QStrList &sl,Definition *container) const;
void _writeCallGraph(OutputList &ol);
void _writeCallerGraph(OutputList &ol);
void _writeReimplements(OutputList &ol);
......
......@@ -250,7 +250,7 @@ bool TemplateVariant::toBool() const
result = p->intVal!=0;
break;
case String:
result = !p->strVal.isEmpty() && p->strVal!="false" && p->strVal!="0";
result = !p->strVal.isEmpty(); // && p->strVal!="false" && p->strVal!="0";
break;
case Struct:
result = TRUE;
......@@ -758,6 +758,31 @@ class FilterNoWrap
}
};
//--------------------------------------------------------------------
/** @brief The implementation of the "divisibleby" filter */
class FilterDivisibleBy
{
public:
static TemplateVariant apply(const TemplateVariant &v,const TemplateVariant &n)
{
printf("FilterDivisibleBy::apply()\n");
if (!v.isValid() || !n.isValid())
{
return TemplateVariant();
}
if (v.type()==TemplateVariant::Integer && n.type()==TemplateVariant::Integer)
{
printf("FilterDivisibleBy(%d,%d)=%d",v.toInt(),n.toInt(),(v.toInt()%n.toInt())==0);
return TemplateVariant((v.toInt()%n.toInt())==0);
}
else
{
return TemplateVariant();
}
}
};
//--------------------------------------------------------------------
......@@ -809,12 +834,14 @@ class TemplateFilterFactory
};
// register a handlers for each filter we support
static TemplateFilterFactory::AutoRegister<FilterAdd> fAdd("add");
static TemplateFilterFactory::AutoRegister<FilterPrepend> fPrepend("prepend");
static TemplateFilterFactory::AutoRegister<FilterLength> fLength("length");
static TemplateFilterFactory::AutoRegister<FilterDefault> fDefault("default");
static TemplateFilterFactory::AutoRegister<FilterStripPath> fStripPath("stripPath");
static TemplateFilterFactory::AutoRegister<FilterNoWrap> fNoWrap("nowrap");
static TemplateFilterFactory::AutoRegister<FilterAdd> fAdd("add");
static TemplateFilterFactory::AutoRegister<FilterAdd> fAppend("append");
static TemplateFilterFactory::AutoRegister<FilterLength> fLength("length");
static TemplateFilterFactory::AutoRegister<FilterNoWrap> fNoWrap("nowrap");
static TemplateFilterFactory::AutoRegister<FilterDefault> fDefault("default");
static TemplateFilterFactory::AutoRegister<FilterPrepend> fPrepend("prepend");
static TemplateFilterFactory::AutoRegister<FilterStripPath> fStripPath("stripPath");
static TemplateFilterFactory::AutoRegister<FilterDivisibleBy> fDivisibleBy("divisibleby");
//--------------------------------------------------------------------
......@@ -1404,6 +1431,16 @@ class ExpressionParser
m_curToken.id+=s;
p++;
}
if (m_curToken.id=="True") // treat true literal as numerical 1
{
m_curToken.type = ExprToken::Number;
m_curToken.num = 1;
}
else if (m_curToken.id=="False") // treat false literal as numerical 0
{
m_curToken.type = ExprToken::Number;
m_curToken.num = 0;
}
}
else if (c=='"' || c=='\'')
{
......@@ -2066,7 +2103,7 @@ class TemplateNodeBlock : public TemplateNodeCreator<TemplateNodeBlock>
}
// add 'block.super' variable to allow access to parent block content
TemplateStruct superBlock;
superBlock.set("super",super.data());
superBlock.set("super",TemplateVariant(super.data(),TRUE));
ci->set("block",&superBlock);
// render the overruled block contents
nb->m_nodes.render(ts,c);
......@@ -2495,6 +2532,121 @@ class TemplateNodeWith : public TemplateNodeCreator<TemplateNodeWith>
//----------------------------------------------------------
/** @brief Class representing an 'set' tag in a template */
class TemplateNodeCycle : public TemplateNodeCreator<TemplateNodeCycle>
{
public:
TemplateNodeCycle(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeCycle>(parser,parent,line)
{
TRACE(("{TemplateNodeCycle(%s)\n",data.data()));
m_args.setAutoDelete(TRUE);
m_index=0;
ExpressionParser expParser(parser->templateName(),line);
QValueList<QCString> args = split(data," ");
QValueListIterator<QCString> it = args.begin();
while (it!=args.end())
{
ExprAst *expr = expParser.parsePrimary(*it);
if (expr)
{
m_args.append(expr);
}
++it;
}
if (m_args.count()<2)
{
warn(parser->templateName(),line,"expected at least two arguments for cycle command, got %d",m_args.count());
}
TRACE(("}TemplateNodeCycle(%s)\n",data.data()));
}
void render(FTextStream &ts, TemplateContext *c)
{
TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
if (m_index<m_args.count())
{
TemplateVariant v = m_args.at(m_index)->resolve(c);
if (v.type()==TemplateVariant::Function)
{
v = v.call(QValueList<TemplateVariant>());
}
if (ci->escapeIntf() && !v.raw())
{
ts << ci->escapeIntf()->escape(v.toString());
}
else
{
ts << v.toString();
}
}
if (++m_index==m_args.count()) // wrap around
{
m_index=0;
}
}
private:
uint m_index;
QList<ExprAst> m_args;
};
//----------------------------------------------------------
/** @brief Class representing an 'set' tag in a template */
class TemplateNodeSet : public TemplateNodeCreator<TemplateNodeSet>
{
struct Mapping
{
Mapping(const QCString &n,ExprAst *e) : name(n), value(e) {}
~Mapping() { delete value; }
QCString name;
ExprAst *value;
};
public:
TemplateNodeSet(TemplateParser *parser,TemplateNode *parent,int line,const QCString &data)
: TemplateNodeCreator<TemplateNodeSet>(parser,parent,line)
{
TRACE(("{TemplateNodeSet(%s)\n",data.data()));
m_args.setAutoDelete(TRUE);
ExpressionParser expParser(parser->templateName(),line);
QValueList<QCString> args = split(data," ");
QValueListIterator<QCString> it = args.begin();
while (it!=args.end())
{
QCString arg = *it;
int j=arg.find('=');
if (j>0)
{
ExprAst *expr = expParser.parsePrimary(arg.mid(j+1));
if (expr)
{
m_args.append(new Mapping(arg.left(j),expr));
}
}
else
{
warn(parser->templateName(),line,"invalid argument '%s' for with tag",arg.data());
}
++it;
}
TRACE(("}TemplateNodeSet(%s)\n",data.data()));
}
void render(FTextStream &, TemplateContext *c)
{
TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
QListIterator<Mapping> it(m_args);
Mapping *mapping;
for (it.toFirst();(mapping=it.current());++it)
{
TemplateVariant value = mapping->value->resolve(c);
ci->set(mapping->name,value);
}
}
private:
QList<Mapping> m_args;
};
//----------------------------------------------------------
/** @brief Class representing an 'spaceless' tag in a template */
class TemplateNodeSpaceless : public TemplateNodeCreator<TemplateNodeSpaceless>
{
......@@ -2667,9 +2819,11 @@ class TemplateNodeFactory
static TemplateNodeFactory::AutoRegister<TemplateNodeIf> autoRefIf("if");
static TemplateNodeFactory::AutoRegister<TemplateNodeFor> autoRefFor("for");
static TemplateNodeFactory::AutoRegister<TemplateNodeMsg> autoRefMsg("msg");
static TemplateNodeFactory::AutoRegister<TemplateNodeSet> autoRefSet("set");
static TemplateNodeFactory::AutoRegister<TemplateNodeTree> autoRefTree("recursetree");
static TemplateNodeFactory::AutoRegister<TemplateNodeWith> autoRefWith("with");
static TemplateNodeFactory::AutoRegister<TemplateNodeBlock> autoRefBlock("block");
static TemplateNodeFactory::AutoRegister<TemplateNodeCycle> autoRefCycle("cycle");
static TemplateNodeFactory::AutoRegister<TemplateNodeExtend> autoRefExtend("extend");
static TemplateNodeFactory::AutoRegister<TemplateNodeCreate> autoRefCreate("create");
static TemplateNodeFactory::AutoRegister<TemplateNodeInclude> autoRefInclude("include");
......
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