| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 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 qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | /* | 
|---|
| 43 | generator.h | 
|---|
| 44 | */ | 
|---|
| 45 |  | 
|---|
| 46 | #ifndef GENERATOR_H | 
|---|
| 47 | #define GENERATOR_H | 
|---|
| 48 |  | 
|---|
| 49 | #include <qlist.h> | 
|---|
| 50 | #include <qmap.h> | 
|---|
| 51 | #include <qregexp.h> | 
|---|
| 52 | #include <qstring.h> | 
|---|
| 53 | #include <qstringlist.h> | 
|---|
| 54 |  | 
|---|
| 55 | #include "node.h" | 
|---|
| 56 | #include "text.h" | 
|---|
| 57 |  | 
|---|
| 58 | QT_BEGIN_NAMESPACE | 
|---|
| 59 |  | 
|---|
| 60 | class ClassNode; | 
|---|
| 61 | class Config; | 
|---|
| 62 | class CodeMarker; | 
|---|
| 63 | class FakeNode; | 
|---|
| 64 | class FunctionNode; | 
|---|
| 65 | class InnerNode; | 
|---|
| 66 | class Location; | 
|---|
| 67 | class NamespaceNode; | 
|---|
| 68 | class Node; | 
|---|
| 69 | class Tree; | 
|---|
| 70 |  | 
|---|
| 71 | class Generator | 
|---|
| 72 | { | 
|---|
| 73 | public: | 
|---|
| 74 | Generator(); | 
|---|
| 75 | virtual ~Generator(); | 
|---|
| 76 |  | 
|---|
| 77 | virtual void initializeGenerator(const Config &config); | 
|---|
| 78 | virtual void terminateGenerator(); | 
|---|
| 79 | virtual QString format() = 0; | 
|---|
| 80 | virtual bool canHandleFormat(const QString &format) { return format == this->format(); } | 
|---|
| 81 | virtual void generateTree(const Tree *tree, CodeMarker *marker) = 0; | 
|---|
| 82 |  | 
|---|
| 83 | static void initialize(const Config& config); | 
|---|
| 84 | static void terminate(); | 
|---|
| 85 | static Generator *generatorForFormat(const QString& format); | 
|---|
| 86 |  | 
|---|
| 87 | protected: | 
|---|
| 88 | virtual void startText(const Node *relative, CodeMarker *marker); | 
|---|
| 89 | virtual void endText(const Node *relative, CodeMarker *marker); | 
|---|
| 90 | virtual int generateAtom(const Atom *atom, | 
|---|
| 91 | const Node *relative, | 
|---|
| 92 | CodeMarker *marker); | 
|---|
| 93 | virtual void generateClassLikeNode(const InnerNode *inner, CodeMarker *marker); | 
|---|
| 94 | virtual void generateFakeNode(const FakeNode *fake, CodeMarker *marker); | 
|---|
| 95 |  | 
|---|
| 96 | virtual void generateText(const Text& text, | 
|---|
| 97 | const Node *relative, | 
|---|
| 98 | CodeMarker *marker); | 
|---|
| 99 | #ifdef QDOC_QML | 
|---|
| 100 | virtual void generateQmlText(const Text& text, | 
|---|
| 101 | const Node *relative, | 
|---|
| 102 | CodeMarker *marker); | 
|---|
| 103 | #endif | 
|---|
| 104 | virtual void generateBody(const Node *node, CodeMarker *marker); | 
|---|
| 105 | virtual void generateAlsoList(const Node *node, CodeMarker *marker); | 
|---|
| 106 | virtual void generateInherits(const ClassNode *classe, | 
|---|
| 107 | CodeMarker *marker); | 
|---|
| 108 | virtual void generateInheritedBy(const ClassNode *classe, | 
|---|
| 109 | CodeMarker *marker); | 
|---|
| 110 |  | 
|---|
| 111 | void generateThreadSafeness(const Node *node, CodeMarker *marker); | 
|---|
| 112 | void generateSince(const Node *node, CodeMarker *marker); | 
|---|
| 113 | void generateStatus(const Node *node, CodeMarker *marker); | 
|---|
| 114 | const Atom *generateAtomList(const Atom *atom, | 
|---|
| 115 | const Node *relative, | 
|---|
| 116 | CodeMarker *marker, | 
|---|
| 117 | bool generate, | 
|---|
| 118 | int& numGeneratedAtoms); | 
|---|
| 119 | void generateExampleFiles(const FakeNode *fake, CodeMarker *marker); | 
|---|
| 120 | void generateModuleWarning(const ClassNode *classe, CodeMarker *marker); | 
|---|
| 121 |  | 
|---|
| 122 | virtual int skipAtoms(const Atom *atom, Atom::Type type) const; | 
|---|
| 123 | virtual QString fullName(const Node *node, | 
|---|
| 124 | const Node *relative, | 
|---|
| 125 | CodeMarker *marker) const; | 
|---|
| 126 |  | 
|---|
| 127 | const QString& outputDir() { return outDir; } | 
|---|
| 128 | QString indent(int level, const QString& markedCode); | 
|---|
| 129 | QString plainCode(const QString& markedCode); | 
|---|
| 130 | virtual QString typeString(const Node *node); | 
|---|
| 131 | virtual QString imageFileName(const Node *relative, const QString& fileBase); | 
|---|
| 132 | void setImageFileExtensions(const QStringList& extensions); | 
|---|
| 133 | void unknownAtom(const Atom *atom); | 
|---|
| 134 | QMap<QString, QString> &formattingLeftMap(); | 
|---|
| 135 | QMap<QString, QString> &formattingRightMap(); | 
|---|
| 136 |  | 
|---|
| 137 | QMap<QString, QStringList> editionModuleMap; | 
|---|
| 138 | QMap<QString, QStringList> editionGroupMap; | 
|---|
| 139 |  | 
|---|
| 140 | static QString trimmedTrailing(const QString &string); | 
|---|
| 141 | static bool matchAhead(const Atom *atom, Atom::Type expectedAtomType); | 
|---|
| 142 | static void supplementAlsoList(const Node *node, QList<Text> &alsoList); | 
|---|
| 143 |  | 
|---|
| 144 | private: | 
|---|
| 145 | void generateOverload(const Node *node, CodeMarker *marker); | 
|---|
| 146 | void generateReimplementedFrom(const FunctionNode *func, | 
|---|
| 147 | CodeMarker *marker); | 
|---|
| 148 | void appendFullName(Text& text, | 
|---|
| 149 | const Node *apparentNode, | 
|---|
| 150 | const Node *relative, | 
|---|
| 151 | CodeMarker *marker, | 
|---|
| 152 | const Node *actualNode = 0); | 
|---|
| 153 | void appendSortedNames(Text& text, | 
|---|
| 154 | const ClassNode *classe, | 
|---|
| 155 | const QList<RelatedClass> &classes, | 
|---|
| 156 | CodeMarker *marker); | 
|---|
| 157 |  | 
|---|
| 158 | QString amp; | 
|---|
| 159 | QString lt; | 
|---|
| 160 | QString gt; | 
|---|
| 161 | QString quot; | 
|---|
| 162 | QRegExp tag; | 
|---|
| 163 |  | 
|---|
| 164 | static QList<Generator *> generators; | 
|---|
| 165 | static QMap<QString, QMap<QString, QString> > fmtLeftMaps; | 
|---|
| 166 | static QMap<QString, QMap<QString, QString> > fmtRightMaps; | 
|---|
| 167 | static QMap<QString, QStringList> imgFileExts; | 
|---|
| 168 | static QSet<QString> outputFormats; | 
|---|
| 169 | static QStringList imageFiles; | 
|---|
| 170 | static QStringList imageDirs; | 
|---|
| 171 | static QString outDir; | 
|---|
| 172 | static QString project; | 
|---|
| 173 | }; | 
|---|
| 174 |  | 
|---|
| 175 | QT_END_NAMESPACE | 
|---|
| 176 |  | 
|---|
| 177 | #endif | 
|---|