1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
3 | * |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef COMPILER_H |
18 | #define COMPILER_H |
19 | |
20 | #include <QThread> |
21 | #include "settings.h" |
22 | #include "../common.h" |
23 | #include "../parser/cppparser.h" |
24 | |
25 | class Project; |
26 | class Compiler : public QThread |
27 | { |
28 | Q_OBJECT |
29 | public: |
30 | enum class TargetType { |
31 | Invalid, |
32 | cttNone, |
33 | File, |
34 | Project, |
35 | StdIn |
36 | }; |
37 | Compiler(const QString& filename, bool silent,bool onlyCheckSyntax); |
38 | |
39 | bool isRebuild() const; |
40 | void setRebuild(bool isRebuild); |
41 | |
42 | const std::shared_ptr<Project> &project() const; |
43 | void setProject(const std::shared_ptr<Project> &newProject); |
44 | |
45 | signals: |
46 | void compileStarted(); |
47 | void compileFinished(); |
48 | void compileOutput(const QString& msg); |
49 | void compileIssue(PCompileIssue issue); |
50 | void compileErrorOccured(const QString& reason); |
51 | public slots: |
52 | void stopCompile(); |
53 | |
54 | protected: |
55 | void run() override; |
56 | void processOutput(QString& line); |
57 | virtual QString getFileNameFromOutputLine(QString &line); |
58 | virtual int getLineNumberFromOutputLine(QString &line); |
59 | virtual int getColunmnFromOutputLine(QString &line); |
60 | virtual CompileIssueType getIssueTypeFromOutputLine(QString &line); |
61 | |
62 | protected: |
63 | virtual Settings::PCompilerSet compilerSet(); |
64 | virtual bool prepareForCompile() = 0; |
65 | virtual QByteArray pipedText(); |
66 | virtual bool prepareForRebuild() = 0; |
67 | virtual QString getCharsetArgument(const QByteArray& encoding, FileType fileType, bool onlyCheckSyntax); |
68 | virtual QString getCCompileArguments(bool checkSyntax); |
69 | virtual QString getCppCompileArguments(bool checkSyntax); |
70 | virtual QString getCIncludeArguments(); |
71 | virtual QString getProjectIncludeArguments(); |
72 | virtual QString getCppIncludeArguments(); |
73 | virtual QString getLibraryArguments(FileType fileType); |
74 | virtual QString parseFileIncludesForAutolink( |
75 | const QString& filename, |
76 | QSet<QString>& parsedFiles, |
77 | PCppParser& parser); |
78 | virtual bool parseForceUTF8ForAutolink( |
79 | const QString& filename, |
80 | QSet<QString>& parsedFiles, |
81 | PCppParser& parser); |
82 | void log(const QString& msg); |
83 | void error(const QString& msg); |
84 | void runCommand(const QString& cmd, const QString& arguments, const QString& workingDir, const QByteArray& inputText=QByteArray()); |
85 | |
86 | protected: |
87 | bool mSilent; |
88 | bool mOnlyCheckSyntax; |
89 | QString mCompiler; |
90 | QString mArguments; |
91 | QString mOutputFile; |
92 | int mErrorCount; |
93 | int mWarningCount; |
94 | PCompileIssue mLastIssue; |
95 | QString mFilename; |
96 | QString mDirectory; |
97 | bool mRebuild; |
98 | std::shared_ptr<Project> mProject; |
99 | |
100 | private: |
101 | bool mStop; |
102 | }; |
103 | |
104 | |
105 | #endif // COMPILER_H |
106 | |