source: trunk/tools/qdoc3/node.h@ 348

Last change on this file since 348 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 16.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*
43 node.h
44*/
45
46#ifndef NODE_H
47#define NODE_H
48
49#include <qdir.h>
50#include <qmap.h>
51#include <qpair.h>
52#include <qstringlist.h>
53
54#include "codechunk.h"
55#include "doc.h"
56#include "location.h"
57#include "text.h"
58
59QT_BEGIN_NAMESPACE
60
61class InnerNode;
62
63class Node
64{
65 public:
66 enum Type {
67 Namespace,
68 Class,
69 Fake,
70 Enum,
71 Typedef,
72 Function,
73 Property,
74 Variable,
75 Target
76 };
77
78 enum Access { Public, Protected, Private };
79
80 enum Status {
81 Compat,
82 Obsolete,
83 Deprecated,
84 Preliminary,
85 Commendable,
86 Main,
87 Internal
88 }; // don't reorder thisw enum
89
90 enum ThreadSafeness {
91 UnspecifiedSafeness,
92 NonReentrant,
93 Reentrant,
94 ThreadSafe
95 };
96
97 enum LinkType {
98 StartLink,
99 NextLink,
100 PreviousLink,
101 ContentsLink,
102 IndexLink /*,
103 GlossaryLink,
104 CopyrightLink,
105 ChapterLink,
106 SectionLink,
107 SubsectionLink,
108 AppendixLink */
109 };
110
111 virtual ~Node();
112
113 void setAccess(Access access) { acc = access; }
114 void setLocation(const Location& location) { loc = location; }
115 void setDoc(const Doc& doc, bool replace = false);
116 void setStatus(Status status) { sta = status; }
117 void setThreadSafeness(ThreadSafeness safeness) { saf = safeness; }
118 void setSince(const QString &since) { sinc = since; }
119 void setRelates(InnerNode *pseudoParent);
120 void setModuleName(const QString &module) { mod = module; }
121 void setLink(LinkType linkType, const QString &link, const QString &desc);
122 void setUrl(const QString &url);
123 void setTemplateStuff(const QString &templateStuff) { tpl = templateStuff; }
124
125 virtual bool isInnerNode() const = 0;
126 Type type() const { return typ; }
127 InnerNode *parent() const { return par; }
128 InnerNode *relates() const { return rel; }
129 const QString& name() const { return nam; }
130 QMap<LinkType, QPair<QString,QString> > links() const { return linkMap; }
131 QString moduleName() const;
132 QString url() const;
133
134 Access access() const { return acc; }
135 const Location& location() const { return loc; }
136 const Doc& doc() const { return d; }
137 Status status() const { return sta; }
138 Status inheritedStatus() const;
139 ThreadSafeness threadSafeness() const;
140 ThreadSafeness inheritedThreadSafeness() const;
141 QString since() const { return sinc; }
142 QString templateStuff() const { return tpl; }
143
144 void clearRelated() { rel = 0; }
145
146 QString fileBase() const;
147
148 protected:
149 Node(Type type, InnerNode *parent, const QString& name);
150
151 private:
152#ifdef Q_WS_WIN
153 Type typ;
154 Access acc;
155 Status sta;
156 ThreadSafeness saf;
157#else
158 Type typ : 4;
159 Access acc : 2;
160 Status sta : 3;
161 ThreadSafeness saf : 2;
162#endif
163 InnerNode *par;
164 InnerNode *rel;
165 QString nam;
166 Location loc;
167 Doc d;
168 QMap<LinkType, QPair<QString, QString> > linkMap;
169 QString mod;
170 QString u;
171 QString sinc;
172 QString tpl;
173};
174
175class FunctionNode;
176class EnumNode;
177
178typedef QList<Node *> NodeList;
179
180class InnerNode : public Node
181{
182 public:
183 ~InnerNode();
184
185 Node *findNode(const QString& name);
186 Node *findNode(const QString& name, Type type);
187 FunctionNode *findFunctionNode(const QString& name);
188 FunctionNode *findFunctionNode(const FunctionNode *clone);
189 void addInclude(const QString &include);
190 void setIncludes(const QStringList &includes);
191 void setOverload(const FunctionNode *func, bool overlode);
192 void normalizeOverloads();
193 void makeUndocumentedChildrenInternal();
194 void deleteChildren();
195 void removeFromRelated();
196
197 virtual bool isInnerNode() const;
198 const Node *findNode(const QString& name) const;
199 const Node *findNode(const QString& name, Type type) const;
200 const FunctionNode *findFunctionNode(const QString& name) const;
201 const FunctionNode *findFunctionNode(const FunctionNode *clone) const;
202 const EnumNode *findEnumNodeForValue(const QString &enumValue) const;
203 const NodeList & childNodes() const { return children; }
204 const NodeList & relatedNodes() const { return related; }
205 int overloadNumber(const FunctionNode *func) const;
206 int numOverloads(const QString& funcName) const;
207 NodeList overloads(const QString &funcName) const;
208 const QStringList& includes() const { return inc; }
209
210 protected:
211 InnerNode(Type type, InnerNode *parent, const QString& name);
212
213 private:
214 friend class Node;
215
216 static bool isSameSignature(const FunctionNode *f1, const FunctionNode *f2);
217 void addChild(Node *child);
218 void removeChild(Node *child);
219 void removeRelated(Node *pseudoChild);
220
221 QStringList inc;
222 NodeList children;
223 NodeList enumChildren;
224 NodeList related;
225 QMap<QString, Node *> childMap;
226 QMap<QString, Node *> primaryFunctionMap;
227 QMap<QString, NodeList> secondaryFunctionMap;
228};
229
230class LeafNode : public Node
231{
232 public:
233 LeafNode();
234
235 virtual bool isInnerNode() const;
236
237 protected:
238 LeafNode(Type type, InnerNode *parent, const QString& name);
239};
240
241class NamespaceNode : public InnerNode
242{
243 public:
244 NamespaceNode(InnerNode *parent, const QString& name);
245};
246
247class ClassNode;
248
249struct RelatedClass
250{
251 RelatedClass() { }
252 RelatedClass(Node::Access access0,
253 ClassNode* node0,
254 const QString& dataTypeWithTemplateArgs0 = "")
255 : access(access0),
256 node(node0),
257 dataTypeWithTemplateArgs(dataTypeWithTemplateArgs0) { }
258
259 Node::Access access;
260 ClassNode* node;
261 QString dataTypeWithTemplateArgs;
262};
263
264class ClassNode : public InnerNode
265{
266 public:
267 ClassNode(InnerNode *parent, const QString& name);
268
269 void addBaseClass(Access access,
270 ClassNode *node,
271 const QString &dataTypeWithTemplateArgs = "");
272 void fixBaseClasses();
273
274 const QList<RelatedClass> &baseClasses() const { return bas; }
275 const QList<RelatedClass> &derivedClasses() const { return der; }
276
277 bool hideFromMainList() const { return hidden; }
278 void setHideFromMainList(bool value) { hidden = value; }
279
280 QString serviceName() const { return sname; }
281 void setServiceName(const QString& value) { sname = value; }
282
283 private:
284 QList<RelatedClass> bas;
285 QList<RelatedClass> der;
286 bool hidden;
287 QString sname;
288};
289
290class FakeNode : public InnerNode
291{
292 public:
293 enum SubType {
294 Example,
295 HeaderFile,
296 File,
297 Group,
298 Module,
299 Page,
300 ExternalPage,
301 QmlClass
302 };
303
304 FakeNode(InnerNode *parent, const QString& name, SubType subType);
305
306 void setTitle(const QString &title) { tle = title; }
307 void setSubTitle(const QString &subTitle) { stle = subTitle; }
308 void addGroupMember(Node *node) { gr.append(node); }
309
310 SubType subType() const { return sub; }
311 QString title() const { return tle; }
312 QString fullTitle() const;
313 QString subTitle() const;
314 const NodeList &groupMembers() const { return gr; }
315
316 private:
317 SubType sub;
318 QString tle;
319 QString stle;
320 NodeList gr;
321};
322
323class QmlNode : public FakeNode
324{
325 public:
326 QmlNode(InnerNode *parent, const QString& name, const ClassNode* cn)
327 : FakeNode(parent, name, QmlClass), cnode(cn) { }
328
329 const ClassNode* classNode() const { return cnode; }
330
331 private:
332 const ClassNode* cnode;
333};
334
335class EnumItem
336{
337 public:
338 EnumItem() { }
339 EnumItem(const QString& name, const QString& value)
340 : nam(name), val(value) { }
341 EnumItem(const QString& name, const QString& value, const Text &txt)
342 : nam(name), val(value), txt(txt) { }
343
344 const QString& name() const { return nam; }
345 const QString& value() const { return val; }
346 const Text &text() const { return txt; }
347
348 private:
349 QString nam;
350 QString val;
351 Text txt;
352};
353
354class TypedefNode;
355
356class EnumNode : public LeafNode
357{
358 public:
359 EnumNode(InnerNode *parent, const QString& name);
360
361 void addItem(const EnumItem& item);
362 void setFlagsType(TypedefNode *typedeff);
363 bool hasItem(const QString &name) const { return names.contains(name); }
364
365 const QList<EnumItem>& items() const { return itms; }
366 Access itemAccess(const QString& name) const;
367 const TypedefNode *flagsType() const { return ft; }
368 QString itemValue(const QString &name) const;
369
370 private:
371 QList<EnumItem> itms;
372 QSet<QString> names;
373 const TypedefNode *ft;
374};
375
376class TypedefNode : public LeafNode
377{
378 public:
379 TypedefNode(InnerNode *parent, const QString& name);
380
381 const EnumNode *associatedEnum() const { return ae; }
382
383 private:
384 void setAssociatedEnum(const EnumNode *enume);
385
386 friend class EnumNode;
387
388 const EnumNode *ae;
389};
390
391inline void EnumNode::setFlagsType(TypedefNode *typedeff)
392{
393 ft = typedeff;
394 typedeff->setAssociatedEnum(this);
395}
396
397
398class Parameter
399{
400 public:
401 Parameter() {}
402 Parameter(const QString& leftType, const QString& rightType = "",
403 const QString& name = "", const QString& defaultValue = "");
404 Parameter(const Parameter& p);
405
406 Parameter& operator=(const Parameter& p);
407
408 void setName(const QString& name) { nam = name; }
409
410 bool hasType() const { return lef.length() + rig.length() > 0; }
411 const QString& leftType() const { return lef; }
412 const QString& rightType() const { return rig; }
413 const QString& name() const { return nam; }
414 const QString& defaultValue() const { return def; }
415
416 private:
417 QString lef;
418 QString rig;
419 QString nam;
420 QString def;
421};
422
423class PropertyNode;
424
425class FunctionNode : public LeafNode
426{
427 public:
428 enum Metaness {
429 Plain,
430 Signal,
431 Slot,
432 Ctor,
433 Dtor,
434 MacroWithParams,
435 MacroWithoutParams,
436 Native };
437 enum Virtualness { NonVirtual, ImpureVirtual, PureVirtual };
438
439 FunctionNode(InnerNode *parent, const QString &name);
440
441 void setReturnType(const QString& returnType) { rt = returnType; }
442 void setMetaness(Metaness metaness) { met = metaness; }
443 void setVirtualness(Virtualness virtualness) { vir = virtualness; }
444 void setConst(bool conste) { con = conste; }
445 void setStatic(bool statique) { sta = statique; }
446 void setOverload(bool overlode);
447 void addParameter(const Parameter& parameter);
448 inline void setParameters(const QList<Parameter>& parameters);
449 void borrowParameterNames(const FunctionNode *source);
450 void setReimplementedFrom(FunctionNode *from);
451
452 const QString& returnType() const { return rt; }
453 Metaness metaness() const { return met; }
454 bool isMacro() const {
455 return met == MacroWithParams || met == MacroWithoutParams;
456 }
457 Virtualness virtualness() const { return vir; }
458 bool isConst() const { return con; }
459 bool isStatic() const { return sta; }
460 bool isOverload() const { return ove; }
461 int overloadNumber() const;
462 int numOverloads() const;
463 const QList<Parameter>& parameters() const { return params; }
464 QStringList parameterNames() const;
465 const FunctionNode *reimplementedFrom() const { return rf; }
466 const QList<FunctionNode *> &reimplementedBy() const { return rb; }
467 const PropertyNode *associatedProperty() const { return ap; }
468
469 private:
470 void setAssociatedProperty(PropertyNode *property);
471
472 friend class InnerNode;
473 friend class PropertyNode;
474
475 QString rt;
476#ifdef Q_WS_WIN
477 Metaness met;
478 Virtualness vir;
479#else
480 Metaness met : 4;
481 Virtualness vir : 2;
482#endif
483 bool con : 1;
484 bool sta : 1;
485 bool ove : 1;
486 QList<Parameter> params;
487 const FunctionNode *rf;
488 const PropertyNode *ap;
489 QList<FunctionNode *> rb;
490};
491
492class PropertyNode : public LeafNode
493{
494 public:
495 enum FunctionRole { Getter, Setter, Resetter };
496 enum { NumFunctionRoles = Resetter + 1 };
497
498 PropertyNode(InnerNode *parent, const QString& name);
499
500 void setDataType(const QString& dataType) { dt = dataType; }
501 void addFunction(FunctionNode *function, FunctionRole role);
502 void setStored(bool stored) { sto = toTrool(stored); }
503 void setDesignable(bool designable) { des = toTrool(designable); }
504 void setOverriddenFrom(const PropertyNode *baseProperty);
505
506 const QString &dataType() const { return dt; }
507 QString qualifiedDataType() const;
508 NodeList functions() const;
509 NodeList functions(FunctionRole role) const { return funcs[(int)role]; }
510 NodeList getters() const { return functions(Getter); }
511 NodeList setters() const { return functions(Setter); }
512 NodeList resetters() const { return functions(Resetter); }
513 bool isStored() const { return fromTrool(sto, storedDefault()); }
514 bool isDesignable() const { return fromTrool(des, designableDefault()); }
515 const PropertyNode *overriddenFrom() const { return overrides; }
516
517 private:
518 enum Trool { Trool_True, Trool_False, Trool_Default };
519
520 static Trool toTrool(bool boolean);
521 static bool fromTrool(Trool troolean, bool defaultValue);
522
523 bool storedDefault() const { return true; }
524 bool designableDefault() const { return !setters().isEmpty(); }
525
526 QString dt;
527 NodeList funcs[NumFunctionRoles];
528 Trool sto;
529 Trool des;
530 const PropertyNode *overrides;
531};
532
533inline void FunctionNode::setParameters(const QList<Parameter> &parameters)
534{
535 params = parameters;
536}
537
538inline void PropertyNode::addFunction(FunctionNode *function, FunctionRole role)
539{
540 funcs[(int)role].append(function);
541 function->setAssociatedProperty(this);
542}
543
544inline NodeList PropertyNode::functions() const
545{
546 NodeList list;
547 for (int i = 0; i < NumFunctionRoles; ++i)
548 list += funcs[i];
549 return list;
550}
551
552class VariableNode : public LeafNode
553{
554 public:
555 VariableNode(InnerNode *parent, const QString &name);
556
557 void setLeftType(const QString &leftType) { lt = leftType; }
558 void setRightType(const QString &rightType) { rt = rightType; }
559 void setStatic(bool statique) { sta = statique; }
560
561 const QString &leftType() const { return lt; }
562 const QString &rightType() const { return rt; }
563 QString dataType() const { return lt + rt; }
564 bool isStatic() const { return sta; }
565
566 private:
567 QString lt;
568 QString rt;
569 bool sta;
570};
571
572inline VariableNode::VariableNode(InnerNode *parent, const QString &name)
573 : LeafNode(Variable, parent, name), sta(false)
574{
575}
576
577class TargetNode : public LeafNode
578{
579 public:
580 TargetNode(InnerNode *parent, const QString& name);
581
582 virtual bool isInnerNode() const;
583};
584
585QT_END_NAMESPACE
586
587#endif
Note: See TracBrowser for help on using the repository browser.