RedPanda-CPP/RedPandaIDE/compiler/compilermanager.cpp

99 lines
2.8 KiB
C++
Raw Normal View History

2021-04-20 22:24:33 +08:00
#include "compilermanager.h"
#include "filecompiler.h"
#include <QDebug>
#include "../mainwindow.h"
#include "executablerunner.h"
#include "utils.h"
2021-04-20 22:24:33 +08:00
CompilerManager::CompilerManager(QObject *parent) : QObject(parent)
{
mCompiler = nullptr;
mBackgroundSyntaxChecker = nullptr;
mRunner = nullptr;
2021-06-23 22:38:02 +08:00
mSyntaxCheckErrorCount = 0;
mCompileErrorCount = 0;
2021-04-20 22:24:33 +08:00
}
bool CompilerManager::compiling()
{
return mCompiler!=nullptr;
}
bool CompilerManager::backgroundSyntaxChecking()
{
return mBackgroundSyntaxChecker!=nullptr;
}
void CompilerManager::compile(const QString& filename, const QByteArray& encoding, bool silent, bool onlyCheckSyntax)
{
QMutexLocker locker(&compileMutex);
if (mCompiler!=nullptr) {
return;
2021-04-20 22:24:33 +08:00
}
2021-06-23 22:38:02 +08:00
mCompileErrorCount = 0;
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
connect(mCompiler, &Compiler::compileFinished, this ,&CompilerManager::onCompileFinished);
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
2021-06-23 22:38:02 +08:00
connect(mCompiler, &Compiler::compileFinished, pMainWindow, &MainWindow::onCompileFinished);
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog);
2021-04-24 15:57:45 +08:00
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
mCompiler->start();
}
void CompilerManager::run(const QString &filename, const QString &arguments, const QString &workDir)
{
QMutexLocker locker(&runnerMutex);
if (mRunner!=nullptr) {
return;
}
if (programHasConsole(filename)) {
QString newArguments = QString(" 0 \"%1\" %2").arg(toLocalPath(filename)).arg(arguments);
mRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe",newArguments,workDir);
} else {
mRunner = new ExecutableRunner(filename,arguments,workDir);
}
connect(mRunner, &ExecutableRunner::terminated, this ,&CompilerManager::onRunnerTerminated);
mRunner->start();
}
bool CompilerManager::canCompile(const QString &filename)
{
return !compiling();
2021-04-20 22:24:33 +08:00
}
void CompilerManager::onCompileFinished()
{
QMutexLocker locker(&compileMutex);
2021-04-24 15:57:45 +08:00
delete mCompiler;
mCompiler=nullptr;
2021-04-20 22:24:33 +08:00
}
void CompilerManager::onRunnerTerminated()
{
QMutexLocker locker(&runnerMutex);
qDebug() << "Runner Terminated";
mRunner=nullptr;
}
void CompilerManager::onCompileIssue(PCompileIssue)
{
mCompileErrorCount ++;
}
2021-06-23 22:38:02 +08:00
int CompilerManager::syntaxCheckErrorCount() const
{
return mSyntaxCheckErrorCount;
}
int CompilerManager::compileErrorCount() const
{
return mCompileErrorCount;
}
CompileError::CompileError(const QString &reason):BaseError(reason)
{
}