Changeset View
Changeset View
Standalone View
Standalone View
src/qmljsc/ir/file.h
Show All 16 Lines | |||||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | * | 18 | * | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef FILE_H | 21 | #ifndef FILE_H | ||
22 | #define FILE_H | 22 | #define FILE_H | ||
23 | 23 | | |||
24 | #include "objecttree.h" | 24 | #include "objecttree.h" | ||
25 | #include "importdefinition.h" | | |||
26 | #include "../utils/shortsymbolname.h" | 25 | #include "../utils/shortsymbolname.h" | ||
27 | 26 | | |||
28 | #include <QtCore/QObject> | 27 | #include <QtCore/QObject> | ||
29 | #include <QtCore/QHash> | 28 | #include <QtCore/QHash> | ||
30 | #include <QtCore/QMutex> | 29 | #include <QtCore/QMutex> | ||
31 | #include <QtCore/QWaitCondition> | 30 | #include <QtCore/QWaitCondition> | ||
32 | #include <QtCore/QStringList> | 31 | #include <QtCore/QStringList> | ||
32 | #include <QtCore/QUrl> | ||||
33 | 33 | | |||
34 | namespace QmlJSc { | 34 | namespace QmlJSc { | ||
35 | namespace IR { | 35 | namespace IR { | ||
36 | 36 | | |||
37 | class Module; | 37 | class Module; | ||
38 | class Type; | 38 | class Type; | ||
39 | 39 | | |||
40 | class File : public Node | 40 | class Import : public Node | ||
41 | { | 41 | { | ||
42 | public: | 42 | public: | ||
43 | struct ModuleData { | 43 | enum ImportType { | ||
44 | Module *module; | 44 | Invalid, | ||
45 | QString localPrefix; | 45 | ModuleImport, | ||
46 | FileImport, | ||||
47 | DirectoryImport | ||||
48 | }; | ||||
49 | | ||||
50 | Import(); | ||||
51 | Import(const Import &other); | ||||
52 | Import(Module *module, const QString &localPrefix = QString()); | ||||
53 | Import(const QUrl &url, const QString &localPrefix= QString()); | ||||
54 | | ||||
55 | bool operator==(const Import &other) const; | ||||
56 | | ||||
57 | ImportType importType() const; | ||||
58 | Module *module() const; | ||||
59 | QUrl filePath() const; | ||||
60 | const QString &localPrefix() const; | ||||
61 | | ||||
62 | virtual Kind kind() const override; | ||||
63 | virtual void accept(Visitor * visitor) override; | ||||
46 | 64 | | |||
47 | bool operator==(const ModuleData &other) const; | 65 | private: | ||
66 | ImportType m_importType; | ||||
67 | Module *m_module; | ||||
68 | QUrl m_filePath; // for file and directory imports | ||||
69 | QString m_localPrefix; // import [...] as <localPrefix> | ||||
48 | }; | 70 | }; | ||
49 | 71 | | |||
50 | explicit File(); | 72 | class File : public Node | ||
73 | { | ||||
74 | public: | ||||
75 | | ||||
76 | File(); | ||||
77 | File(std::initializer_list<Import> imports, ObjectSpec *rootObject); | ||||
51 | virtual ~File(); | 78 | virtual ~File(); | ||
52 | 79 | | |||
53 | virtual Node::Kind kind() const override; | 80 | virtual Node::Kind kind() const override; | ||
54 | 81 | | |||
55 | void addModule(Module *module, const QString &prefix = QString()); | 82 | void addModule(Module *module, const QString &prefix = QString()); | ||
56 | 83 | | |||
57 | Type* type(const QString &typeName) const; | 84 | Type* type(const QString &typeName) const; | ||
58 | QString fullyQualifiedName(const QString &typeName); | 85 | QString fullyQualifiedName(const QString &typeName); | ||
59 | 86 | | |||
60 | ObjectSpec *rootObject() const; | 87 | ObjectSpec *rootObject() const; | ||
61 | void setRootObject(ObjectSpec *root); | 88 | void setRootObject(ObjectSpec *root); | ||
62 | 89 | | |||
63 | virtual void accept(Visitor * visitor) override; | 90 | virtual void accept(Visitor * visitor) override; | ||
64 | 91 | | |||
65 | const QVector<ModuleData> &importedModules() const; | 92 | const QVector<Import> &importedModules() const; | ||
66 | 93 | | |||
67 | private: | 94 | private: | ||
68 | const ModuleData *moduleForType(const QString &typeName) const; | 95 | const Import *moduleForType(const QString &typeName) const; | ||
69 | 96 | | |||
70 | QVector<ModuleData> m_importedModules; | 97 | QVector<Import> m_importedModules; | ||
71 | ShortSymbolName m_prefix; | 98 | ShortSymbolName m_prefix; | ||
72 | ObjectSpec *m_rootObject; | 99 | ObjectSpec *m_rootObject; | ||
73 | }; | 100 | }; | ||
74 | 101 | | |||
75 | } // namespace IR | 102 | } // namespace IR | ||
76 | } // namespace QMLJSc | 103 | } // namespace QMLJSc | ||
77 | 104 | | |||
78 | #endif // FILE_H | 105 | #endif // FILE_H |