2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-20 22:24:33 +08:00
|
|
|
#ifndef COMPILER_H
|
|
|
|
#define COMPILER_H
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include "settings.h"
|
2021-04-24 15:57:45 +08:00
|
|
|
#include "../common.h"
|
2021-09-04 11:37:04 +08:00
|
|
|
#include "../parser/cppparser.h"
|
2021-04-20 22:24:33 +08:00
|
|
|
|
2021-09-12 22:45:00 +08:00
|
|
|
class Project;
|
2021-04-20 22:24:33 +08:00
|
|
|
class Compiler : public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum class TargetType {
|
|
|
|
Invalid,
|
|
|
|
cttNone,
|
|
|
|
File,
|
|
|
|
Project,
|
|
|
|
StdIn
|
|
|
|
};
|
2023-08-15 10:57:03 +08:00
|
|
|
Compiler(const QString& filename, bool onlyCheckSyntax);
|
2023-01-12 12:07:22 +08:00
|
|
|
Compiler(const Compiler&)=delete;
|
|
|
|
Compiler& operator=(const Compiler&)=delete;
|
2021-04-20 22:24:33 +08:00
|
|
|
|
2021-06-25 12:40:11 +08:00
|
|
|
bool isRebuild() const;
|
|
|
|
void setRebuild(bool isRebuild);
|
|
|
|
|
2021-09-12 22:45:00 +08:00
|
|
|
const std::shared_ptr<Project> &project() const;
|
|
|
|
void setProject(const std::shared_ptr<Project> &newProject);
|
|
|
|
|
2023-08-13 14:46:53 +08:00
|
|
|
PCppParser parser() const;
|
|
|
|
|
2021-04-20 22:24:33 +08:00
|
|
|
signals:
|
|
|
|
void compileStarted();
|
2022-12-25 12:00:09 +08:00
|
|
|
void compileFinished(QString filename);
|
2021-04-20 22:24:33 +08:00
|
|
|
void compileOutput(const QString& msg);
|
2021-04-24 15:57:45 +08:00
|
|
|
void compileIssue(PCompileIssue issue);
|
2021-06-21 11:21:26 +08:00
|
|
|
void compileErrorOccured(const QString& reason);
|
2021-04-20 22:24:33 +08:00
|
|
|
public slots:
|
|
|
|
void stopCompile();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void run() override;
|
2021-04-24 15:57:45 +08:00
|
|
|
void processOutput(QString& line);
|
2023-08-13 14:46:53 +08:00
|
|
|
void getParserForFile(const QString& filename);
|
2021-04-24 15:57:45 +08:00
|
|
|
virtual QString getFileNameFromOutputLine(QString &line);
|
|
|
|
virtual int getLineNumberFromOutputLine(QString &line);
|
|
|
|
virtual int getColunmnFromOutputLine(QString &line);
|
|
|
|
virtual CompileIssueType getIssueTypeFromOutputLine(QString &line);
|
2021-04-20 22:24:33 +08:00
|
|
|
|
|
|
|
protected:
|
2021-09-13 07:49:36 +08:00
|
|
|
virtual Settings::PCompilerSet compilerSet();
|
2021-04-20 22:24:33 +08:00
|
|
|
virtual bool prepareForCompile() = 0;
|
2022-03-31 09:56:49 +08:00
|
|
|
virtual QByteArray pipedText();
|
2021-06-25 12:40:11 +08:00
|
|
|
virtual bool prepareForRebuild() = 0;
|
2023-08-14 12:22:24 +08:00
|
|
|
virtual bool beforeRunExtraCommand(int idx);
|
2024-02-28 19:41:05 +08:00
|
|
|
virtual QStringList getCharsetArgument(const QByteArray& encoding, FileType fileType, bool onlyCheckSyntax);
|
|
|
|
virtual QStringList getCCompileArguments(bool checkSyntax);
|
|
|
|
virtual QStringList getCppCompileArguments(bool checkSyntax);
|
|
|
|
virtual QStringList getCIncludeArguments();
|
|
|
|
virtual QStringList getProjectIncludeArguments();
|
|
|
|
virtual QStringList getCppIncludeArguments();
|
|
|
|
virtual QStringList getLibraryArguments(FileType fileType);
|
|
|
|
virtual QStringList parseFileIncludesForAutolink(
|
2021-09-04 11:37:04 +08:00
|
|
|
const QString& filename,
|
2023-08-13 14:46:53 +08:00
|
|
|
QSet<QString>& parsedFiles);
|
2022-06-23 19:07:48 +08:00
|
|
|
virtual bool parseForceUTF8ForAutolink(
|
|
|
|
const QString& filename,
|
2023-08-13 14:46:53 +08:00
|
|
|
QSet<QString>& parsedFiles);
|
2021-04-20 22:24:33 +08:00
|
|
|
void log(const QString& msg);
|
|
|
|
void error(const QString& msg);
|
2024-02-28 19:41:05 +08:00
|
|
|
void runCommand(const QString& cmd, const QStringList& arguments, const QString& workingDir, const QByteArray& inputText=QByteArray(), const QString& outputFile=QString());
|
|
|
|
QString escapeCommandForLog(const QString &cmd, const QStringList &arguments);
|
2021-04-20 22:24:33 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool mOnlyCheckSyntax;
|
|
|
|
QString mCompiler;
|
2024-02-28 19:41:05 +08:00
|
|
|
QStringList mArguments;
|
|
|
|
QList<QString> mExtraCompilersList;
|
|
|
|
QList<QStringList> mExtraArgumentsList;
|
|
|
|
QList<QString> mExtraOutputFilesList;
|
2021-04-21 23:06:55 +08:00
|
|
|
QString mOutputFile;
|
2021-04-24 15:57:45 +08:00
|
|
|
int mErrorCount;
|
|
|
|
int mWarningCount;
|
2021-06-24 16:05:19 +08:00
|
|
|
PCompileIssue mLastIssue;
|
2021-06-24 20:43:09 +08:00
|
|
|
QString mFilename;
|
2021-09-13 22:45:50 +08:00
|
|
|
QString mDirectory;
|
2021-06-25 12:40:11 +08:00
|
|
|
bool mRebuild;
|
2021-09-12 22:45:00 +08:00
|
|
|
std::shared_ptr<Project> mProject;
|
2023-02-13 21:49:19 +08:00
|
|
|
bool mSetLANG;
|
2023-08-14 12:22:24 +08:00
|
|
|
PCppParser mParserForFile;
|
2024-02-20 21:47:12 +08:00
|
|
|
bool mForceEnglishOutput;
|
2021-04-20 22:24:33 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool mStop;
|
|
|
|
};
|
|
|
|
|
2021-06-21 11:21:26 +08:00
|
|
|
|
2021-04-20 22:24:33 +08:00
|
|
|
#endif // COMPILER_H
|