Skip to content

Commit 46cd570

Browse files
committed
Include class moved to its own .h/.cpp file.
1 parent 97bff10 commit 46cd570

File tree

5 files changed

+137
-63
lines changed

5 files changed

+137
-63
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ graph.cpp
4444
reporthandler.cpp
4545
typeparser.cpp
4646
typesystem.cpp
47+
include.cpp
4748
parser/ast.cpp
4849
parser/binder.cpp
4950
parser/class_compiler.cpp
@@ -114,6 +115,7 @@ typesystem.h
114115
fileout.h
115116
docparser.h
116117
qtdocparser.h
118+
include.h
117119
)
118120

119121
if (BUILD_TESTS)

include.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of the API Extractor project.
3+
*
4+
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5+
*
6+
* Contact: PySide team <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* version 2 as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful, but
13+
* WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA
21+
*
22+
*/
23+
24+
#include "include.h"
25+
#include <QTextStream>
26+
#include <QHash>
27+
28+
QString Include::toString() const
29+
{
30+
if (m_type == IncludePath)
31+
return "#include <" + m_name + '>';
32+
else if (m_type == LocalPath)
33+
return "#include \"" + m_name + "\"";
34+
else
35+
return "import " + m_name + ";";
36+
}
37+
38+
uint qHash(const Include& inc)
39+
{
40+
return qHash(inc.m_name);
41+
}
42+
43+
QTextStream& operator<<(QTextStream& out, const Include& include)
44+
{
45+
if (include.isValid())
46+
out << include.toString() << endl;
47+
return out;
48+
}
49+

include.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* This file is part of the API Extractor project.
3+
*
4+
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5+
*
6+
* Contact: PySide team <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* version 2 as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful, but
13+
* WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA
21+
*
22+
*/
23+
24+
#ifndef INCLUDE_H
25+
#define INCLUDE_H
26+
27+
#include "apiextractormacros.h"
28+
#include <QString>
29+
#include <QList>
30+
31+
class QTextStream;
32+
33+
class APIEXTRACTOR_API Include
34+
{
35+
public:
36+
enum IncludeType {
37+
IncludePath,
38+
LocalPath,
39+
TargetLangImport
40+
};
41+
42+
Include() : m_type(IncludePath) {}
43+
Include(IncludeType t, const QString &nam) : m_type(t), m_name(nam) {};
44+
45+
bool isValid() const
46+
{
47+
return !m_name.isEmpty();
48+
}
49+
50+
IncludeType type() const
51+
{
52+
return m_type;
53+
}
54+
55+
QString name() const
56+
{
57+
return m_name;
58+
}
59+
60+
QString toString() const;
61+
62+
bool operator<(const Include& other) const
63+
{
64+
return m_name < other.m_name;
65+
}
66+
67+
bool operator==(const Include& other) const
68+
{
69+
return m_type == other.m_type && m_name == other.m_name;
70+
}
71+
72+
friend uint qHash(const Include&);
73+
private:
74+
IncludeType m_type;
75+
QString m_name;
76+
};
77+
78+
APIEXTRACTOR_API uint qHash(const Include& inc);
79+
APIEXTRACTOR_API QTextStream& operator<<(QTextStream& out, const Include& include);
80+
81+
typedef QList<Include> IncludeList;
82+
83+
#endif

typesystem.cpp

-24
Original file line numberDiff line numberDiff line change
@@ -1792,18 +1792,6 @@ IncludeList TypeDatabase::extraIncludes(const QString &className)
17921792
return IncludeList();
17931793
}
17941794

1795-
1796-
1797-
QString Include::toString() const
1798-
{
1799-
if (type == IncludePath)
1800-
return "#include <" + name + '>';
1801-
else if (type == LocalPath)
1802-
return "#include \"" + name + "\"";
1803-
else
1804-
return "import " + name + ";";
1805-
}
1806-
18071795
QString Modification::accessModifierString() const
18081796
{
18091797
if (isPrivate()) return "private";
@@ -2239,18 +2227,6 @@ QString ContainerTypeEntry::typeName() const
22392227
}
22402228
}
22412229

2242-
uint qHash(const Include& inc)
2243-
{
2244-
return qHash(inc.name);
2245-
}
2246-
2247-
QTextStream& operator<<(QTextStream& out, const Include& include)
2248-
{
2249-
if (include.isValid())
2250-
out << include.toString() << endl;
2251-
return out;
2252-
}
2253-
22542230
/*
22552231
static void injectCode(ComplexTypeEntry *e,
22562232
const char *signature,

typesystem.h

+3-39
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QtCore/QMap>
3131
#include <QtCore/QDebug>
3232
#include "apiextractormacros.h"
33+
#include "include.h"
3334

3435
class Indentor;
3536

@@ -39,43 +40,6 @@ class QTextStream;
3940
class EnumTypeEntry;
4041
class FlagsTypeEntry;
4142

42-
struct APIEXTRACTOR_API Include
43-
{
44-
enum IncludeType {
45-
IncludePath,
46-
LocalPath,
47-
TargetLangImport
48-
};
49-
50-
Include() : type(IncludePath) {}
51-
Include(IncludeType t, const QString &nam) : type(t), name(nam) {};
52-
53-
bool isValid() const
54-
{
55-
return !name.isEmpty();
56-
}
57-
58-
IncludeType type;
59-
QString name;
60-
61-
QString toString() const;
62-
63-
bool operator<(const Include& other) const
64-
{
65-
return name < other.name;
66-
}
67-
68-
bool operator==(const Include& other) const
69-
{
70-
return type == other.type && name == other.name;
71-
}
72-
};
73-
74-
APIEXTRACTOR_API uint qHash(const Include& inc);
75-
APIEXTRACTOR_API QTextStream& operator<<(QTextStream& out, const Include& include);
76-
77-
typedef QList<Include> IncludeList;
78-
7943
typedef QMap<int, QString> ArgumentMap;
8044

8145
class TemplateInstance;
@@ -883,9 +847,9 @@ class APIEXTRACTOR_API TypeEntry
883847
}
884848
void addExtraInclude(const Include &include)
885849
{
886-
if (!m_includesUsed.value(include.name, false)) {
850+
if (!m_includesUsed.value(include.name(), false)) {
887851
m_extraIncludes << include;
888-
m_includesUsed[include.name] = true;
852+
m_includesUsed[include.name()] = true;
889853
}
890854
}
891855

0 commit comments

Comments
 (0)