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 COMPILERMANAGER_H
|
|
|
|
#define COMPILERMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QMutex>
|
2021-06-21 11:21:26 +08:00
|
|
|
#include "../utils.h"
|
2021-06-24 16:05:19 +08:00
|
|
|
#include "../common.h"
|
2021-04-20 22:24:33 +08:00
|
|
|
|
2021-11-01 09:18:23 +08:00
|
|
|
class Runner;
|
2021-09-12 22:45:00 +08:00
|
|
|
class Project;
|
2022-12-01 22:10:44 +08:00
|
|
|
class Compiler;
|
2022-12-13 08:49:20 +08:00
|
|
|
struct OJProblem;
|
|
|
|
using POJProblem = std::shared_ptr<OJProblem>;
|
2022-03-29 09:43:24 +08:00
|
|
|
struct OJProblemCase;
|
2021-11-01 09:18:23 +08:00
|
|
|
using POJProblemCase = std::shared_ptr<OJProblemCase>;
|
2021-04-20 22:24:33 +08:00
|
|
|
class CompilerManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit CompilerManager(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
bool compiling();
|
|
|
|
bool backgroundSyntaxChecking();
|
2021-06-25 12:40:11 +08:00
|
|
|
bool running();
|
2021-04-20 22:24:33 +08:00
|
|
|
|
2022-12-01 22:10:44 +08:00
|
|
|
void compile(const QString& filename, const QByteArray& encoding, bool rebuild, CppCompileType compileType);
|
|
|
|
void compileProject(std::shared_ptr<Project> project, bool rebuild);
|
2021-09-17 21:33:19 +08:00
|
|
|
void cleanProject(std::shared_ptr<Project> project);
|
2021-09-17 19:58:37 +08:00
|
|
|
void buildProjectMakefile(std::shared_ptr<Project> project);
|
2022-03-27 11:44:52 +08:00
|
|
|
void checkSyntax(const QString&filename, const QByteArray& encoding, const QString& content, std::shared_ptr<Project> project);
|
2022-06-16 21:34:31 +08:00
|
|
|
void run(
|
|
|
|
const QString& filename,
|
|
|
|
const QString& arguments,
|
|
|
|
const QString& workDir,
|
|
|
|
const QStringList& extraBinDir);
|
2022-12-13 08:49:20 +08:00
|
|
|
void runProblem(
|
|
|
|
const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase,
|
|
|
|
const POJProblem& problem
|
|
|
|
);
|
|
|
|
void runProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector<POJProblemCase> &problemCases,
|
|
|
|
const POJProblem& problem
|
|
|
|
);
|
2021-06-25 12:40:11 +08:00
|
|
|
void stopRun();
|
2021-12-29 22:03:18 +08:00
|
|
|
void stopAllRunners();
|
2021-12-23 17:07:27 +08:00
|
|
|
void stopPausing();
|
2021-06-25 12:40:11 +08:00
|
|
|
void stopCompile();
|
2021-09-26 19:40:52 +08:00
|
|
|
void stopCheckSyntax();
|
2021-04-21 18:58:35 +08:00
|
|
|
bool canCompile(const QString& filename);
|
2021-06-23 22:38:02 +08:00
|
|
|
int compileErrorCount() const;
|
|
|
|
|
|
|
|
int syntaxCheckErrorCount() const;
|
|
|
|
|
2021-09-26 22:52:19 +08:00
|
|
|
int compileIssueCount() const;
|
|
|
|
|
|
|
|
int syntaxCheckIssueCount() const;
|
|
|
|
|
2021-12-29 22:03:18 +08:00
|
|
|
signals:
|
|
|
|
void signalStopAllRunners();
|
|
|
|
|
2021-04-20 22:24:33 +08:00
|
|
|
private slots:
|
2022-12-13 08:49:20 +08:00
|
|
|
void doRunProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector<POJProblemCase> &problemCases,
|
|
|
|
const POJProblem& problem
|
|
|
|
);
|
2021-04-21 18:58:35 +08:00
|
|
|
void onRunnerTerminated();
|
2021-12-29 22:03:18 +08:00
|
|
|
void onRunnerPausing();
|
2021-06-24 20:43:09 +08:00
|
|
|
void onCompileFinished();
|
2021-06-24 16:05:19 +08:00
|
|
|
void onCompileIssue(PCompileIssue issue);
|
2021-06-24 20:43:09 +08:00
|
|
|
void onSyntaxCheckFinished();
|
|
|
|
void onSyntaxCheckIssue(PCompileIssue issue);
|
2021-06-24 16:05:19 +08:00
|
|
|
|
2021-04-20 22:24:33 +08:00
|
|
|
private:
|
|
|
|
Compiler* mCompiler;
|
2021-06-23 22:38:02 +08:00
|
|
|
int mCompileErrorCount;
|
2021-09-26 22:52:19 +08:00
|
|
|
int mCompileIssueCount;
|
2021-06-23 22:38:02 +08:00
|
|
|
int mSyntaxCheckErrorCount;
|
2021-09-26 22:52:19 +08:00
|
|
|
int mSyntaxCheckIssueCount;
|
2021-04-20 22:24:33 +08:00
|
|
|
Compiler* mBackgroundSyntaxChecker;
|
2021-11-01 09:18:23 +08:00
|
|
|
Runner* mRunner;
|
2022-11-10 09:05:34 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
QRecursiveMutex mCompileMutex;
|
|
|
|
QRecursiveMutex mBackgroundSyntaxCheckMutex;
|
|
|
|
QRecursiveMutex mRunnerMutex;
|
|
|
|
#else
|
2022-01-04 16:50:54 +08:00
|
|
|
QMutex mCompileMutex;
|
|
|
|
QMutex mBackgroundSyntaxCheckMutex;
|
|
|
|
QMutex mRunnerMutex;
|
2022-11-10 09:05:34 +08:00
|
|
|
#endif
|
2021-04-20 22:24:33 +08:00
|
|
|
};
|
|
|
|
|
2021-06-21 11:21:26 +08:00
|
|
|
class CompileError : public BaseError {
|
|
|
|
public:
|
|
|
|
explicit CompileError(const QString& reason);
|
|
|
|
};
|
|
|
|
|
2021-04-20 22:24:33 +08:00
|
|
|
#endif // COMPILERMANAGER_H
|