summaryrefslogtreecommitdiffstats
path: root/src/qdoc/sections.h
diff options
context:
space:
mode:
authorMartin Smith <martin.smith@qt.io>2018-05-04 14:31:18 +0200
committerMartin Smith <martin.smith@qt.io>2018-06-01 12:14:36 +0000
commit26027a9b13491a4851c42e12d06af87f7e864a51 (patch)
tree399340d91e7aaea82b1c133c695a066586e1bc7a /src/qdoc/sections.h
parent1beb7d176492c284640082e6c8d7b9b37d5ce0f0 (diff)
qdoc: Refactor section construction and processing
This update adds two classes called Section and Sections. These classes replace the FastSection and Section structs that used to be in codemarker.h, and they also replace the section building functions that used to be in codemarker.cpp and cppcodemarker.cpp. Basically, the two structs FastSection and Section are combined into the single new class Section. FastSection was used to collect all the members for a section in a map with the node names as the keys and the nodes as the values. This allowed the names to be sorted as the map is built. When completed, themap was used to build the Section, where the map keys were copied to a list in the Section, and the map values were copied to another list. The values in these lists were already sorted. Then the Section structs were copied into a list of Sections and the list was returned. The code was becoming too messy to maintain and impossible to use for implementing custom sections for QTBUG-45725. Now the new class Section combines the deleted structs FastSection and Section. The procedure for building an instance of class Section is much the same as the old procedure for building a struct FastSection and then using the FastSection to build a struct Section. In the old procedure, 4 separate passes over all the child nodes of a class were required to build the FastSections and Sections for the Summay lists, the Details lists, the All Members list, and the Obsolete members lists. In the new procedure, only a single pass is required. This single pass is the purpose for the other new class Sections, which manages several static instances of QVector<Section>. All the required Section objects are built at the same time, and the never have to be copied. When the docs for a class, namespace, etc have been written, each Section is cleared but not deleted. The static instances of QVector<Section> are kept in their constructed state. I thought this would speed up qdoc some, because there is much less allocating and deallocating of objects, but it seems to have actually slowed down a bit, and I can't see why. But the code is a lot simpler and reusable for the custom sections proposal, so I will continue with it and hopefully find the cause of the slowdown. Change-Id: I49f592c631ccc6182d1dae742985c7b2bb15c81b Reviewed-by: Martin Smith <martin.smith@qt.io>
Diffstat (limited to 'src/qdoc/sections.h')
-rw-r--r--src/qdoc/sections.h245
1 files changed, 182 insertions, 63 deletions
diff --git a/src/qdoc/sections.h b/src/qdoc/sections.h
index e660f233a..5ff7ed4a3 100644
--- a/src/qdoc/sections.h
+++ b/src/qdoc/sections.h
@@ -38,94 +38,213 @@ typedef QMultiMap<QString, Node*> MemberMap; // the string is the member signatu
typedef QPair<const QmlTypeNode*, MemberMap> ClassMap; // the node is the QML type
typedef QList<ClassMap*> ClassMapList;
-typedef QPair<QStringList, NodeList> KeysAndNodes;
+typedef QPair<QStringList, NodeVector> KeysAndNodes;
typedef QPair<const QmlTypeNode*, KeysAndNodes> ClassKeysNodes;
typedef QList<ClassKeysNodes*> ClassKeysNodesList;
-struct Section
+class Section
{
- QString name_;
- QString divClass_;
- QString singular_;
- QString plural_;
- QStringList keys_;
- NodeList members_;
- NodeList reimpMembers_;
- QList<QPair<Aggregate *, int> > inherited_;
- ClassKeysNodesList classKeysNodesList_;
+ public:
+ enum Style { Summary, Details, AllMembers, Accessors };
+ enum Status { Obsolete, Active };
- Section() { }
- Section(const QString& name,
- const QString& divClass,
- const QString& singular,
- const QString& plural)
- : name_(name), divClass_(divClass), singular_(singular), plural_(plural) { }
+ public:
+ Section() : style_(Details), status_(Active), aggregate_(0) { }
+ Section(Style style, Status status);
~Section();
- void appendMember(Node* node) { members_.append(node); }
- void appendReimpMember(Node* node) { reimpMembers_.append(node); }
-};
-
-struct FastSection
-{
- QString name_;
- QString divClass_;
- QString singular_;
- QString plural_;
- QMultiMap<QString, Node *> memberMap_;
- QMultiMap<QString, Node *> reimpMemberMap_;
- ClassMapList classMapList_;
- QList<QPair<Aggregate *, int> > inherited_;
-
- FastSection(const QString& name, const QString& singular, const QString& plural)
- : name_(name), singular_(singular), plural_(plural) { }
+ void init(const QString& title) {
+ title_ = title;
+ }
+ void init(const QString& singular,
+ const QString& plural) {
+ singular_ = singular; plural_ = plural;
+ }
+ void init(const QString& title,
+ const QString& singular,
+ const QString& plural) {
+ title_ = title; divClass_.clear(); singular_= singular; plural_ = plural;
+ }
+ void init(const QString& title,
+ const QString& divClass,
+ const QString& singular,
+ const QString& plural) {
+ title_ = title; divClass_ = divClass; singular_= singular; plural_ = plural;
+ }
- FastSection(const QString& name,
- const QString& divClass,
- const QString& singular,
- const QString& plural)
- : name_(name), divClass_(divClass), singular_(singular), plural_(plural) { }
+ void insert(Node *node);
+ void insert(const QString& key, Node *node) { memberMap_.insertMulti(key, node); }
+ bool insertReimplementedMember(Node* node);
- ~FastSection();
+ ClassMap *newClassMap(const Aggregate *aggregate);
+ void add(ClassMap *classMap, Node *n);
+ void appendMember(Node* node) { members_.append(node); }
+ void appendReimplementedMember(Node* node) { reimplementedMembers_.append(node); }
void clear();
+ void reduce();
bool isEmpty() const {
return (memberMap_.isEmpty() &&
- inherited_.isEmpty() &&
- reimpMemberMap_.isEmpty() &&
+ inheritedMembers_.isEmpty() &&
+ reimplementedMemberMap_.isEmpty() &&
classMapList_.isEmpty());
}
+ Style style() const { return style_; }
+ Status status() const { return status_; }
+ const QString &title() const { return title_; }
+ const QString &divClass() const { return divClass_; }
+ const QString &singular() const { return singular_; }
+ const QString &plural() const { return plural_; }
+ const QStringList &keys() const { return keys_; }
+ const QStringList &keys(Status t) const { return (t == Obsolete ? obsoleteKeys_ : keys_); }
+ const NodeVector &members() const { return members_; }
+ const NodeVector &reimplementedMembers() const { return reimplementedMembers_; }
+ const QList<QPair<Aggregate*, int> > &inheritedMembers() const { return inheritedMembers_; }
+ ClassKeysNodesList &classKeysNodesList() { return classKeysNodesList_; }
+ const NodeVector &obsoleteMembers() const { return obsoleteMembers_; }
+ void appendMembers(const NodeVector &nv) { members_.append(nv); }
+ const Aggregate *aggregate() const { return aggregate_; }
+ void setAggregate(Aggregate *t) { aggregate_ = t; }
+
+ private:
+ QString sortName(const Node *node, const QString* name = 0);
+
+ private:
+ Style style_;
+ Status status_;
+ QString title_;
+ QString divClass_;
+ QString singular_;
+ QString plural_;
+
+ Aggregate *aggregate_;
+ QStringList keys_;
+ QStringList obsoleteKeys_;
+ NodeVector members_;
+ NodeVector obsoleteMembers_;
+ NodeVector reimplementedMembers_;
+ QList<QPair<Aggregate *, int> > inheritedMembers_;
+ ClassKeysNodesList classKeysNodesList_;
+
+ QMultiMap<QString, Node *> memberMap_;
+ QMultiMap<QString, Node *> obsoleteMemberMap_;
+ QMultiMap<QString, Node *> reimplementedMemberMap_;
+ ClassMapList classMapList_;
};
+typedef QVector<Section> SectionVector;
+typedef QVector<const Section*> SectionPtrVector;
+
class Sections
{
public:
- enum Style { Summary, Detailed, Subpage, Accessors };
- enum Status { Obsolete, Okay };
-
- Sections() { }
- ~Sections() { }
-
- static QList<Section> getStdCppSections(const Aggregate *aggregate, Style style, Status status);
- static QList<Section> getStdQmlSections(Aggregate* aggregate, Style style, Status status = Okay);
- static QString sortName(const Node *node, const QString* name = 0);
- static void insert(FastSection &fs, Node *node, Style style, Status status);
- static bool insertReimpFunc(FastSection& fs, Node* node, Status status);
- static void append(QList<Section>& sections, const FastSection& fs, bool includeKeys = false);
- static void setCurrentNode(const Aggregate *t) { aggregate_ = t; }
+ enum VectorIndex {
+ AllMembers = 0,
+ PublicTypes = 0,
+ DetailsMemberTypes = 0,
+ SinceNamespaces = 0,
+ StdNamespaces = 0,
+ QmlProperties = 0,
+ Properties = 1,
+ DetailsProperties = 1,
+ SinceClasses = 1,
+ StdClasses = 1,
+ QmlAttachedProperties = 1,
+ PublicFunctions = 2,
+ DetailsMemberFunctions = 2,
+ SinceMemberFunctions = 2,
+ StdTypes = 2,
+ QmlSignals = 2,
+ PublicSlots = 3,
+ DetailsMemberVariables = 3,
+ SinceNamespaceFunctions = 3,
+ StdVariables = 3,
+ QmlSignalHandlers = 3,
+ Signals = 4,
+ SinceGlobalFunctions = 4,
+ DetailsRelatedNonmembers = 4,
+ StdStaticVariables = 4,
+ QmlAttachedSignals = 4,
+ PublicVariables = 5,
+ SinceMacros = 5,
+ DetailsMacros = 5,
+ StdFunctions = 5,
+ QmlMethods = 5,
+ StaticPublicMembers = 6,
+ SinceEnumTypes = 6,
+ StdMacros = 6,
+ QmlAttachedMethods = 6,
+ ProtectedTypes = 7,
+ SinceTypedefs = 7,
+ ProtectedFunctions = 8,
+ SinceProperties = 8,
+ ProtectedSlots = 9,
+ SinceVariables = 9,
+ ProtectedVariables = 10,
+ SinceQmlTypes = 10,
+ StaticProtectedMembers = 11,
+ SinceQmlProperties = 11,
+ PrivateTypes = 12,
+ SinceQmlSignals = 12,
+ PrivateFunctions = 13,
+ SinceQmlSignalHandlers = 13,
+ PrivateSlots = 14,
+ SinceQmlMethods = 14,
+ StaticPrivateMembers = 15,
+ RelatedNonmembers = 16,
+ Macros = 17
+ };
+
+ Sections(Aggregate *aggregate);
+ Sections(const NodeMultiMap& nsmap);
+ ~Sections();
+
+ void initSections();
+ void clear(SectionVector &v);
+ void reduce(SectionVector &v);
+ void buildStdRefPageSections();
+ void buildStdCppClassRefPageSections();
+ void buildStdQmlTypeRefPageSections();
+
+ bool hasObsoleteMembers(SectionPtrVector *summary_spv, SectionPtrVector *details_spv) const;
+
+ static Section &allMembersSection() { return allMembers_[0]; }
+ SectionVector &sinceSections() { return sinceSections_; }
+ SectionVector &stdSummarySections() { return stdSummarySections_; }
+ SectionVector &stdDetailsSections() { return stdDetailsSections_; }
+ SectionVector &stdCppClassSummarySections() { return stdCppClassSummarySections_; }
+ SectionVector &stdCppClassDetailsSections() { return stdCppClassDetailsSections_; }
+ SectionVector &stdQmlTypeSummarySections() { return stdQmlTypeSummarySections_; }
+ SectionVector &stdQmlTypeDetailsSections() { return stdQmlTypeDetailsSections_; }
+
+ const SectionVector &stdSummarySections() const { return stdSummarySections_; }
+ const SectionVector &stdDetailsSections() const { return stdDetailsSections_; }
+ const SectionVector &stdCppClassSummarySections() const { return stdCppClassSummarySections_; }
+ const SectionVector &stdCppClassDetailsSections() const { return stdCppClassDetailsSections_; }
+ const SectionVector &stdQmlTypeSummarySections() const { return stdQmlTypeSummarySections_; }
+ const SectionVector &stdQmlTypeDetailsSections() const { return stdQmlTypeDetailsSections_; }
+
+ Aggregate *aggregate() const { return aggregate_; }
private:
- static void getAllCppClassMembers(QList<Section> &sections, Style style, Status status);
- static void getCppClassStdSummarySections(QList<Section> &sections, Style style, Status status);
- static void getCppClassStdDetailedSections(QList<Section> &sections, Style style, Status status);
- static void getAllStdCppSections(QList<Section> &sections, Style style, Status status);
- static void getAllQmlTypeMembers(QList<Section> &sections);
- static void getQmlTypeStdSummarySections(QList<Section> &sections, Style style, Status status);
- static void getQmlTypeStdDetailedSections(QList<Section> &sections, Style style, Status status);
+ void stdRefPageSwitch(SectionVector &v, Node *n);
+ void distributeNodeInSummaryVector(SectionVector &sv, Node *n);
+ void distributeNodeInDetailsVector(SectionVector &dv, Node *n);
+ void initAggregate(SectionVector &v, Aggregate *aggregate);
private:
- static const Aggregate *aggregate_;
+ Aggregate *aggregate_;
+
+ static SectionVector stdSummarySections_;
+ static SectionVector stdDetailsSections_;
+ static SectionVector stdCppClassSummarySections_;
+ static SectionVector stdCppClassDetailsSections_;
+ static SectionVector stdQmlTypeSummarySections_;
+ static SectionVector stdQmlTypeDetailsSections_;
+ static SectionVector sinceSections_;
+ static SectionVector allMembers_;
+
};
QT_END_NAMESPACE