RedPanda-CPP/RedPandaIDE/compiler/stdincompiler.cpp

73 lines
2.2 KiB
C++
Raw Normal View History

2021-06-24 20:43:09 +08:00
#include "stdincompiler.h"
#include "compilermanager.h"
#include <QFile>
#include <QFileInfo>
#include "../platform.h"
2021-06-24 20:43:09 +08:00
StdinCompiler::StdinCompiler(const QString &filename, const QString& content,bool isAscii, bool silent, bool onlyCheckSyntax):
2021-06-24 20:43:09 +08:00
Compiler(filename,silent,onlyCheckSyntax),
mContent(content),
mIsAscii(isAscii)
2021-06-24 20:43:09 +08:00
{
}
bool StdinCompiler::prepareForCompile()
{
log(tr("Checking file syntax..."));
log("------------------");
log(tr("- Filename: %1").arg(mFilename));
log(tr("- Compiler Set Name: %1").arg(compilerSet()->name()));
log("");
FileType fileType = getFileType(mFilename);
if (fileType == FileType::Other)
fileType = FileType::CppSource;
QString strFileType;
if (!mIsAscii)
mArguments += getCharsetArgument(getDefaultSystemEncoding());
2021-06-24 20:43:09 +08:00
switch(fileType) {
case FileType::CSource:
case FileType::CHeader:
2021-06-24 20:43:09 +08:00
mArguments += " -x c - ";
mArguments += getCCompileArguments(mOnlyCheckSyntax);
mArguments += getCIncludeArguments();
2021-09-12 22:45:00 +08:00
mArguments += getProjectIncludeArguments();
2021-06-24 20:43:09 +08:00
strFileType = "C";
mCompiler = compilerSet()->CCompiler();
break;
case FileType::CppSource:
case FileType::CppHeader:
2021-06-24 20:43:09 +08:00
mArguments += " -x c++ - ";
2021-09-12 22:45:00 +08:00
mArguments += getCppCompileArguments(mOnlyCheckSyntax);
mArguments += getCppIncludeArguments();
mArguments += getProjectIncludeArguments();
2021-06-24 20:43:09 +08:00
strFileType = "C++";
mCompiler = compilerSet()->cppCompiler();
break;
default:
throw CompileError(tr("Can't find the compiler for file %1").arg(mFilename));
}
2021-09-04 14:06:48 +08:00
mArguments += getLibraryArguments(fileType);
2021-06-24 20:43:09 +08:00
2021-09-07 10:28:40 +08:00
if (!fileExists(mCompiler)) {
2021-06-24 20:43:09 +08:00
throw CompileError(tr("The Compiler '%1' doesn't exists!").arg(mCompiler));
}
log(tr("Processing %1 source file:").arg(strFileType));
log("------------------");
log(tr("%1 Compiler: %2").arg(strFileType).arg(mCompiler));
log(tr("Command: %1 %2").arg(extractFileName(mCompiler)).arg(mArguments));
2021-09-13 22:45:50 +08:00
mDirectory = extractFileDir(mFilename);
2021-06-24 20:43:09 +08:00
return true;
}
QString StdinCompiler::pipedText()
{
return mContent;
}
2021-06-25 12:40:11 +08:00
bool StdinCompiler::prepareForRebuild()
{
return true;
}