1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the tools applications of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
52 #include <qstringlist.h>
54 #include "codechunk.h"
105 enum Access
{ Public
, Protected
, Private
};
115 }; // don't reorder thisw enum
117 enum ThreadSafeness
{
141 void setAccess(Access access
) { acc
= access
; }
142 void setLocation(const Location
& location
) { loc
= location
; }
143 void setDoc(const Doc
& doc
, bool replace
= false);
144 void setStatus(Status status
) { sta
= status
; }
145 void setThreadSafeness(ThreadSafeness safeness
) { saf
= safeness
; }
146 void setSince(const QString
&since
) { sinc
= since
; }
147 void setRelates(InnerNode
*pseudoParent
);
148 void setModuleName(const QString
&module
) { mod
= module
; }
149 void setLink(LinkType linkType
, const QString
&link
, const QString
&desc
);
150 void setUrl(const QString
&url
);
151 void setTemplateStuff(const QString
&templateStuff
) { tpl
= templateStuff
; }
153 virtual bool isInnerNode() const = 0;
154 virtual bool isReimp() const { return false; }
155 virtual bool isFunction() const { return false; }
156 Type
type() const { return typ
; }
157 virtual SubType
subType() const { return NoSubType
; }
158 InnerNode
*parent() const { return par
; }
159 InnerNode
*relates() const { return rel
; }
160 const QString
& name() const { return nam
; }
161 QMap
<LinkType
, QPair
<QString
,QString
> > links() const { return linkMap
; }
162 QString
moduleName() const;
164 virtual QString
nameForLists() const { return nam
; }
166 Access
access() const { return acc
; }
167 const Location
& location() const { return loc
; }
168 const Doc
& doc() const { return d
; }
169 Status
status() const { return sta
; }
170 Status
inheritedStatus() const;
171 ThreadSafeness
threadSafeness() const;
172 ThreadSafeness
inheritedThreadSafeness() const;
173 QString
since() const { return sinc
; }
174 QString
templateStuff() const { return tpl
; }
176 void clearRelated() { rel
= 0; }
178 virtual QString
fileBase() const;
181 Node(Type type
, InnerNode
*parent
, const QString
& name
);
194 ThreadSafeness saf
: 2;
201 QMap
<LinkType
, QPair
<QString
, QString
> > linkMap
;
211 typedef QList
<Node
*> NodeList
;
213 class InnerNode
: public Node
216 virtual ~InnerNode();
218 Node
*findNode(const QString
& name
);
219 Node
*findNode(const QString
& name
, Type type
);
220 FunctionNode
*findFunctionNode(const QString
& name
);
221 FunctionNode
*findFunctionNode(const FunctionNode
*clone
);
222 void addInclude(const QString
&include
);
223 void setIncludes(const QStringList
&includes
);
224 void setOverload(const FunctionNode
*func
, bool overlode
);
225 void normalizeOverloads();
226 void makeUndocumentedChildrenInternal();
227 void deleteChildren();
228 void removeFromRelated();
230 virtual bool isInnerNode() const;
231 const Node
*findNode(const QString
& name
) const;
232 const Node
*findNode(const QString
& name
, Type type
) const;
233 const FunctionNode
*findFunctionNode(const QString
& name
) const;
234 const FunctionNode
*findFunctionNode(const FunctionNode
*clone
) const;
235 const EnumNode
*findEnumNodeForValue(const QString
&enumValue
) const;
236 const NodeList
& childNodes() const { return children
; }
237 const NodeList
& relatedNodes() const { return related
; }
238 int count() const { return children
.size(); }
239 int overloadNumber(const FunctionNode
*func
) const;
240 int numOverloads(const QString
& funcName
) const;
241 NodeList
overloads(const QString
&funcName
) const;
242 const QStringList
& includes() const { return inc
; }
244 QStringList
primaryKeys();
245 QStringList
secondaryKeys();
248 InnerNode(Type type
, InnerNode
*parent
, const QString
& name
);
253 static bool isSameSignature(const FunctionNode
*f1
, const FunctionNode
*f2
);
254 void addChild(Node
*child
);
255 void removeChild(Node
*child
);
256 void removeRelated(Node
*pseudoChild
);
260 NodeList enumChildren
;
262 QMap
<QString
, Node
*> childMap
;
263 QMap
<QString
, Node
*> primaryFunctionMap
;
264 QMap
<QString
, NodeList
> secondaryFunctionMap
;
267 class LeafNode
: public Node
271 virtual ~LeafNode() { }
273 virtual bool isInnerNode() const;
276 LeafNode(Type type
, InnerNode
* parent
, const QString
& name
);
279 class NamespaceNode
: public InnerNode
282 NamespaceNode(InnerNode
*parent
, const QString
& name
);
283 virtual ~NamespaceNode() { }
291 RelatedClass(Node::Access access0
,
293 const QString
& dataTypeWithTemplateArgs0
= "")
296 dataTypeWithTemplateArgs(dataTypeWithTemplateArgs0
) { }
300 QString dataTypeWithTemplateArgs
;
303 class ClassNode
: public InnerNode
306 ClassNode(InnerNode
*parent
, const QString
& name
);
307 virtual ~ClassNode() { }
309 void addBaseClass(Access access
,
311 const QString
&dataTypeWithTemplateArgs
= "");
312 void fixBaseClasses();
314 const QList
<RelatedClass
> &baseClasses() const { return bas
; }
315 const QList
<RelatedClass
> &derivedClasses() const { return der
; }
317 bool hideFromMainList() const { return hidden
; }
318 void setHideFromMainList(bool value
) { hidden
= value
; }
320 QString
serviceName() const { return sname
; }
321 void setServiceName(const QString
& value
) { sname
= value
; }
322 QString
qmlElement() const { return qmlelement
; }
323 void setQmlElement(const QString
& value
) { qmlelement
= value
; }
326 QList
<RelatedClass
> bas
;
327 QList
<RelatedClass
> der
;
333 class FakeNode
: public InnerNode
337 FakeNode(InnerNode
*parent
, const QString
& name
, SubType subType
);
338 virtual ~FakeNode() { }
340 void setTitle(const QString
&title
) { tle
= title
; }
341 void setSubTitle(const QString
&subTitle
) { stle
= subTitle
; }
342 void addGroupMember(Node
*node
) { gr
.append(node
); }
344 SubType
subType() const { return sub
; }
345 QString
title() const { return tle
; }
346 QString
fullTitle() const;
347 QString
subTitle() const;
348 const NodeList
&groupMembers() const { return gr
; }
349 virtual QString
nameForLists() const { return title(); }
359 class QmlClassNode
: public FakeNode
362 QmlClassNode(InnerNode
*parent
,
364 const ClassNode
* cn
);
365 virtual ~QmlClassNode() { }
367 const ClassNode
* classNode() const { return cnode
; }
368 virtual QString
fileBase() const;
373 const ClassNode
* cnode
;
376 class QmlPropGroupNode
: public FakeNode
379 QmlPropGroupNode(QmlClassNode
* parent
,
382 virtual ~QmlPropGroupNode() { }
384 const QString
& element() const { return parent()->name(); }
385 void setDefault() { isdefault
= true; }
386 bool isDefault() const { return isdefault
; }
387 bool isAttached() const { return att
; }
394 class QmlPropertyNode
: public LeafNode
397 QmlPropertyNode(QmlPropGroupNode
* parent
,
401 virtual ~QmlPropertyNode() { }
403 void setDataType(const QString
& dataType
) { dt
= dataType
; }
404 void setStored(bool stored
) { sto
= toTrool(stored
); }
405 void setDesignable(bool designable
) { des
= toTrool(designable
); }
406 void setWritable(bool writable
) { wri
= toTrool(writable
); }
408 const QString
&dataType() const { return dt
; }
409 QString
qualifiedDataType() const { return dt
; }
410 bool isStored() const { return fromTrool(sto
,true); }
411 bool isDesignable() const { return fromTrool(des
,false); }
412 bool isWritable() const { return fromTrool(wri
,true); }
413 bool isAttached() const { return att
; }
415 const QString
& element() const { return static_cast<QmlPropGroupNode
*>(parent())->element(); }
418 enum Trool
{ Trool_True
, Trool_False
, Trool_Default
};
420 static Trool
toTrool(bool boolean
);
421 static bool fromTrool(Trool troolean
, bool defaultValue
);
435 EnumItem(const QString
& name
, const QString
& value
)
436 : nam(name
), val(value
) { }
437 EnumItem(const QString
& name
, const QString
& value
, const Text
&txt
)
438 : nam(name
), val(value
), txt(txt
) { }
440 const QString
& name() const { return nam
; }
441 const QString
& value() const { return val
; }
442 const Text
&text() const { return txt
; }
452 class EnumNode
: public LeafNode
455 EnumNode(InnerNode
*parent
, const QString
& name
);
456 virtual ~EnumNode() { }
458 void addItem(const EnumItem
& item
);
459 void setFlagsType(TypedefNode
*typedeff
);
460 bool hasItem(const QString
&name
) const { return names
.contains(name
); }
462 const QList
<EnumItem
>& items() const { return itms
; }
463 Access
itemAccess(const QString
& name
) const;
464 const TypedefNode
*flagsType() const { return ft
; }
465 QString
itemValue(const QString
&name
) const;
468 QList
<EnumItem
> itms
;
470 const TypedefNode
*ft
;
473 class TypedefNode
: public LeafNode
476 TypedefNode(InnerNode
*parent
, const QString
& name
);
477 virtual ~TypedefNode() { }
479 const EnumNode
*associatedEnum() const { return ae
; }
482 void setAssociatedEnum(const EnumNode
*enume
);
484 friend class EnumNode
;
489 inline void EnumNode::setFlagsType(TypedefNode
*typedeff
)
492 typedeff
->setAssociatedEnum(this);
500 Parameter(const QString
& leftType
,
501 const QString
& rightType
= "",
502 const QString
& name
= "",
503 const QString
& defaultValue
= "");
504 Parameter(const Parameter
& p
);
506 Parameter
& operator=(const Parameter
& p
);
508 void setName(const QString
& name
) { nam
= name
; }
510 bool hasType() const { return lef
.length() + rig
.length() > 0; }
511 const QString
& leftType() const { return lef
; }
512 const QString
& rightType() const { return rig
; }
513 const QString
& name() const { return nam
; }
514 const QString
& defaultValue() const { return def
; }
516 QString
reconstruct(bool value
= false) const;
527 class FunctionNode
: public LeafNode
539 enum Virtualness
{ NonVirtual
, ImpureVirtual
, PureVirtual
};
541 FunctionNode(InnerNode
*parent
, const QString
&name
);
542 FunctionNode(Type type
, InnerNode
*parent
, const QString
&name
, bool attached
);
543 virtual ~FunctionNode() { }
545 void setReturnType(const QString
& returnType
) { rt
= returnType
; }
546 void setParentPath(const QStringList
& parentPath
) { pp
= parentPath
; }
547 void setMetaness(Metaness metaness
) { met
= metaness
; }
548 void setVirtualness(Virtualness virtualness
) { vir
= virtualness
; }
549 void setConst(bool conste
) { con
= conste
; }
550 void setStatic(bool statique
) { sta
= statique
; }
551 void setOverload(bool overlode
);
552 void setReimp(bool r
);
553 void addParameter(const Parameter
& parameter
);
554 inline void setParameters(const QList
<Parameter
>& parameters
);
555 void borrowParameterNames(const FunctionNode
*source
);
556 void setReimplementedFrom(FunctionNode
*from
);
558 const QString
& returnType() const { return rt
; }
559 Metaness
metaness() const { return met
; }
560 bool isMacro() const {
561 return met
== MacroWithParams
|| met
== MacroWithoutParams
;
563 Virtualness
virtualness() const { return vir
; }
564 bool isConst() const { return con
; }
565 bool isStatic() const { return sta
; }
566 bool isOverload() const { return ove
; }
567 bool isReimp() const { return reimp
; }
568 bool isFunction() const { return true; }
569 int overloadNumber() const;
570 int numOverloads() const;
571 const QList
<Parameter
>& parameters() const { return params
; }
572 QStringList
parameterNames() const;
573 const FunctionNode
*reimplementedFrom() const { return rf
; }
574 const QList
<FunctionNode
*> &reimplementedBy() const { return rb
; }
575 const PropertyNode
*associatedProperty() const { return ap
; }
576 const QStringList
& parentPath() const { return pp
; }
578 QStringList
reconstructParams(bool values
= false) const;
579 QString
signature(bool values
= false) const;
580 const QString
& element() const { return parent()->name(); }
581 bool isAttached() const { return att
; }
586 void setAssociatedProperty(PropertyNode
*property
);
588 friend class InnerNode
;
589 friend class PropertyNode
;
605 QList
<Parameter
> params
;
606 const FunctionNode
*rf
;
607 const PropertyNode
*ap
;
608 QList
<FunctionNode
*> rb
;
611 class PropertyNode
: public LeafNode
614 enum FunctionRole
{ Getter
, Setter
, Resetter
, Notifier
};
615 enum { NumFunctionRoles
= Notifier
+ 1 };
617 PropertyNode(InnerNode
*parent
, const QString
& name
);
618 virtual ~PropertyNode() { }
620 void setDataType(const QString
& dataType
) { dt
= dataType
; }
621 void addFunction(FunctionNode
*function
, FunctionRole role
);
622 void addSignal(FunctionNode
*function
, FunctionRole role
);
623 void setStored(bool stored
) { sto
= toTrool(stored
); }
624 void setDesignable(bool designable
) { des
= toTrool(designable
); }
625 void setWritable(bool writable
) { wri
= toTrool(writable
); }
626 void setOverriddenFrom(const PropertyNode
*baseProperty
);
628 const QString
&dataType() const { return dt
; }
629 QString
qualifiedDataType() const;
630 NodeList
functions() const;
631 NodeList
functions(FunctionRole role
) const { return funcs
[(int)role
]; }
632 NodeList
getters() const { return functions(Getter
); }
633 NodeList
setters() const { return functions(Setter
); }
634 NodeList
resetters() const { return functions(Resetter
); }
635 NodeList
notifiers() const { return functions(Notifier
); }
636 bool isStored() const { return fromTrool(sto
, storedDefault()); }
637 bool isDesignable() const { return fromTrool(des
, designableDefault()); }
638 bool isWritable() const { return fromTrool(wri
, writableDefault()); }
639 const PropertyNode
*overriddenFrom() const { return overrides
; }
642 enum Trool
{ Trool_True
, Trool_False
, Trool_Default
};
644 static Trool
toTrool(bool boolean
);
645 static bool fromTrool(Trool troolean
, bool defaultValue
);
647 bool storedDefault() const { return true; }
648 bool designableDefault() const { return !setters().isEmpty(); }
649 bool writableDefault() const { return !setters().isEmpty(); }
652 NodeList funcs
[NumFunctionRoles
];
656 const PropertyNode
*overrides
;
659 inline void FunctionNode::setParameters(const QList
<Parameter
> ¶meters
)
664 inline void PropertyNode::addFunction(FunctionNode
*function
, FunctionRole role
)
666 funcs
[(int)role
].append(function
);
667 function
->setAssociatedProperty(this);
670 inline void PropertyNode::addSignal(FunctionNode
*function
, FunctionRole role
)
672 funcs
[(int)role
].append(function
);
675 inline NodeList
PropertyNode::functions() const
678 for (int i
= 0; i
< NumFunctionRoles
; ++i
)
683 class VariableNode
: public LeafNode
686 VariableNode(InnerNode
*parent
, const QString
&name
);
687 virtual ~VariableNode() { }
689 void setLeftType(const QString
&leftType
) { lt
= leftType
; }
690 void setRightType(const QString
&rightType
) { rt
= rightType
; }
691 void setStatic(bool statique
) { sta
= statique
; }
693 const QString
&leftType() const { return lt
; }
694 const QString
&rightType() const { return rt
; }
695 QString
dataType() const { return lt
+ rt
; }
696 bool isStatic() const { return sta
; }
704 inline VariableNode::VariableNode(InnerNode
*parent
, const QString
&name
)
705 : LeafNode(Variable
, parent
, name
), sta(false)
709 class TargetNode
: public LeafNode
712 TargetNode(InnerNode
*parent
, const QString
& name
);
713 virtual ~TargetNode() { }
715 virtual bool isInnerNode() const;