- fix: Crash if close file while auto syntax checking.

- enhancement: support sdcc compiler.
This commit is contained in:
Roy Qu 2023-08-13 14:46:53 +08:00
parent 4b8883062b
commit 738faf0c90
16 changed files with 513 additions and 157 deletions

View File

@ -27,6 +27,7 @@ Red Panda C++ Version 2.24
- fix: Wrong compiler settings if xcode is not installed in mac os. - fix: Wrong compiler settings if xcode is not installed in mac os.
- enhancement: Name for new files will not be different from files openned. - enhancement: Name for new files will not be different from files openned.
- fix: Crash if close file while auto syntax checking. - fix: Crash if close file while auto syntax checking.
- enhancement: support sdcc compiler.
Red Panda C++ Version 2.23 Red Panda C++ Version 2.23

View File

@ -41,8 +41,10 @@ Compiler::Compiler(const QString &filename, bool silent, bool onlyCheckSyntax):
mSilent(silent), mSilent(silent),
mOnlyCheckSyntax(onlyCheckSyntax), mOnlyCheckSyntax(onlyCheckSyntax),
mFilename(filename), mFilename(filename),
mRebuild(false) mRebuild(false),
mParser()
{ {
getParserForFile(filename);
} }
void Compiler::run() void Compiler::run()
@ -170,11 +172,12 @@ CompileIssueType Compiler::getIssueTypeFromOutputLine(QString &line)
int pos = line.indexOf(':'); int pos = line.indexOf(':');
if (pos>=0) { if (pos>=0) {
QString s=line.mid(0,pos); QString s=line.mid(0,pos);
if (s == "error" || s == "fatal error") { if (s == "error" || s == "fatal error"
|| s == "syntax error") {
mErrorCount += 1; mErrorCount += 1;
line = tr("[Error] ")+line.mid(pos+1); line = tr("[Error] ")+line.mid(pos+1);
result = CompileIssueType::Error; result = CompileIssueType::Error;
} else if (s == "warning") { } else if (s.startsWith("warning")) {
mWarningCount += 1; mWarningCount += 1;
line = tr("[Warning] ")+line.mid(pos+1); line = tr("[Warning] ")+line.mid(pos+1);
result = CompileIssueType::Warning; result = CompileIssueType::Warning;
@ -322,30 +325,25 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding,FileType fileTyp
bool forceExecUTF8=false; bool forceExecUTF8=false;
// test if force utf8 from autolink infos // test if force utf8 from autolink infos
if ((fileType == FileType::CSource || if ((fileType == FileType::CSource ||
fileType == FileType::CppSource) && pSettings->editor().enableAutolink() ){ fileType == FileType::CppSource) && pSettings->editor().enableAutolink()
Editor* editor = pMainWindow->editorList()->getOpenedEditorByFilename(mFilename); && mParser){
if (editor) { int waitCount = 0;
PCppParser parser = editor->parser(); //wait parsing ends, at most 1 second
if (parser) { while(mParser->parsing()) {
int waitCount = 0; if (waitCount>10)
//wait parsing ends, at most 1 second break;
while(parser->parsing()) { waitCount++;
if (waitCount>10) QThread::msleep(100);
break; QApplication *app=dynamic_cast<QApplication*>(
waitCount++; QApplication::instance());
QThread::msleep(100); app->processEvents();
QApplication *app=dynamic_cast<QApplication*>( }
QApplication::instance()); if (waitCount<=10) {
app->processEvents(); QSet<QString> parsedFiles;
} forceExecUTF8 = parseForceUTF8ForAutolink(
QSet<QString> parsedFiles; mFilename,
forceExecUTF8 = parseForceUTF8ForAutolink( parsedFiles);
mFilename,
parsedFiles,
parser);
}
} }
} }
if ((forceExecUTF8 || compilerSet()->autoAddCharsetParams()) && encoding != ENCODING_ASCII if ((forceExecUTF8 || compilerSet()->autoAddCharsetParams()) && encoding != ENCODING_ASCII
&& compilerSet()->compilerType()!=CompilerType::Clang) { && compilerSet()->compilerType()!=CompilerType::Clang) {
@ -517,30 +515,25 @@ QString Compiler::getLibraryArguments(FileType fileType)
//Add auto links //Add auto links
// is file and auto link enabled // is file and auto link enabled
if (pSettings->editor().enableAutolink() && (fileType == FileType::CSource || if (pSettings->editor().enableAutolink() && (fileType == FileType::CSource ||
fileType == FileType::CppSource)){ fileType == FileType::CppSource)
Editor* editor = pMainWindow->editorList()->getEditor(); && mParser){
if (editor) { int waitCount = 0;
PCppParser parser = editor->parser(); //wait parsing ends, at most 1 second
if (parser) { while(mParser->parsing()) {
int waitCount = 0; if (waitCount>10)
//wait parsing ends, at most 1 second break;
while(parser->parsing()) { waitCount++;
if (waitCount>10) QThread::msleep(100);
break; QApplication *app=dynamic_cast<QApplication*>(
waitCount++; QApplication::instance());
QThread::msleep(100); app->processEvents();
QApplication *app=dynamic_cast<QApplication*>( }
QApplication::instance()); if (waitCount<=10) {
app->processEvents(); QSet<QString> parsedFiles;
} result += parseFileIncludesForAutolink(
QSet<QString> parsedFiles; mFilename,
result += parseFileIncludesForAutolink( parsedFiles);
editor->filename(),
parsedFiles,
parser);
}
} }
} }
//add compiler set link options //add compiler set link options
@ -600,8 +593,7 @@ QString Compiler::getLibraryArguments(FileType fileType)
QString Compiler::parseFileIncludesForAutolink( QString Compiler::parseFileIncludesForAutolink(
const QString &filename, const QString &filename,
QSet<QString>& parsedFiles, QSet<QString>& parsedFiles)
PCppParser& parser)
{ {
QString result; QString result;
if (parsedFiles.contains(filename)) if (parsedFiles.contains(filename))
@ -611,7 +603,7 @@ QString Compiler::parseFileIncludesForAutolink(
if (autolink) { if (autolink) {
result += ' '+autolink->linkOption; result += ' '+autolink->linkOption;
} }
QStringList includedFiles = parser->getFileDirectIncludes(filename); QStringList includedFiles = mParser->getFileDirectIncludes(filename);
// log(QString("File %1 included:").arg(filename)); // log(QString("File %1 included:").arg(filename));
// for (int i=includedFiles.size()-1;i>=0;i--) { // for (int i=includedFiles.size()-1;i>=0;i--) {
// QString includeFilename = includedFiles[i]; // QString includeFilename = includedFiles[i];
@ -622,13 +614,12 @@ QString Compiler::parseFileIncludesForAutolink(
QString includeFilename = includedFiles[i]; QString includeFilename = includedFiles[i];
result += parseFileIncludesForAutolink( result += parseFileIncludesForAutolink(
includeFilename, includeFilename,
parsedFiles, parsedFiles);
parser);
} }
return result; return result;
} }
bool Compiler::parseForceUTF8ForAutolink(const QString &filename, QSet<QString> &parsedFiles, PCppParser &parser) bool Compiler::parseForceUTF8ForAutolink(const QString &filename, QSet<QString> &parsedFiles)
{ {
bool result; bool result;
if (parsedFiles.contains(filename)) if (parsedFiles.contains(filename))
@ -638,7 +629,7 @@ bool Compiler::parseForceUTF8ForAutolink(const QString &filename, QSet<QString>
if (autolink && autolink->execUseUTF8) { if (autolink && autolink->execUseUTF8) {
return true; return true;
} }
QStringList includedFiles = parser->getFileDirectIncludes(filename); QStringList includedFiles = mParser->getFileDirectIncludes(filename);
// log(QString("File %1 included:").arg(filename)); // log(QString("File %1 included:").arg(filename));
// for (int i=includedFiles.size()-1;i>=0;i--) { // for (int i=includedFiles.size()-1;i>=0;i--) {
// QString includeFilename = includedFiles[i]; // QString includeFilename = includedFiles[i];
@ -649,8 +640,7 @@ bool Compiler::parseForceUTF8ForAutolink(const QString &filename, QSet<QString>
QString includeFilename = includedFiles[i]; QString includeFilename = includedFiles[i];
result = parseForceUTF8ForAutolink( result = parseForceUTF8ForAutolink(
includeFilename, includeFilename,
parsedFiles, parsedFiles);
parser);
if (result) if (result)
return true; return true;
} }
@ -750,6 +740,23 @@ void Compiler::runCommand(const QString &cmd, const QString &arguments, const Q
} }
} }
PCppParser Compiler::parser() const
{
return mParser;
}
void Compiler::getParserForFile(const QString &filename)
{
FileType fileType = getFileType(filename);
if (fileType == FileType::CSource ||
fileType == FileType::CppSource){
Editor* editor = pMainWindow->editorList()->getOpenedEditorByFilename(filename);
if (editor && editor->parser()) {
mParser=editor->parser();
}
}
}
const std::shared_ptr<Project> &Compiler::project() const const std::shared_ptr<Project> &Compiler::project() const
{ {
return mProject; return mProject;

View File

@ -44,6 +44,8 @@ public:
const std::shared_ptr<Project> &project() const; const std::shared_ptr<Project> &project() const;
void setProject(const std::shared_ptr<Project> &newProject); void setProject(const std::shared_ptr<Project> &newProject);
PCppParser parser() const;
signals: signals:
void compileStarted(); void compileStarted();
void compileFinished(QString filename); void compileFinished(QString filename);
@ -56,6 +58,7 @@ public slots:
protected: protected:
void run() override; void run() override;
void processOutput(QString& line); void processOutput(QString& line);
void getParserForFile(const QString& filename);
virtual QString getFileNameFromOutputLine(QString &line); virtual QString getFileNameFromOutputLine(QString &line);
virtual int getLineNumberFromOutputLine(QString &line); virtual int getLineNumberFromOutputLine(QString &line);
virtual int getColunmnFromOutputLine(QString &line); virtual int getColunmnFromOutputLine(QString &line);
@ -75,12 +78,10 @@ protected:
virtual QString getLibraryArguments(FileType fileType); virtual QString getLibraryArguments(FileType fileType);
virtual QString parseFileIncludesForAutolink( virtual QString parseFileIncludesForAutolink(
const QString& filename, const QString& filename,
QSet<QString>& parsedFiles, QSet<QString>& parsedFiles);
PCppParser& parser);
virtual bool parseForceUTF8ForAutolink( virtual bool parseForceUTF8ForAutolink(
const QString& filename, const QString& filename,
QSet<QString>& parsedFiles, QSet<QString>& parsedFiles);
PCppParser& parser);
void log(const QString& msg); void log(const QString& msg);
void error(const QString& msg); void error(const QString& msg);
void runCommand(const QString& cmd, const QString& arguments, const QString& workingDir, const QByteArray& inputText=QByteArray()); void runCommand(const QString& cmd, const QString& arguments, const QString& workingDir, const QByteArray& inputText=QByteArray());
@ -101,6 +102,7 @@ protected:
bool mRebuild; bool mRebuild;
std::shared_ptr<Project> mProject; std::shared_ptr<Project> mProject;
bool mSetLANG; bool mSetLANG;
PCppParser mParser;
private: private:
bool mStop; bool mStop;

View File

@ -27,6 +27,11 @@ bool CompilerInfo::hasCompilerOption(const QString &key) const
return mCompilerOptions.contains(key); return mCompilerOptions.contains(key);
} }
bool CompilerInfo::supportSyntaxCheck()
{
return true;
}
void CompilerInfo::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices) void CompilerInfo::addOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const CompileOptionChoiceList &choices)
{ {
PCompilerOption pOption = std::make_shared<CompilerOption>(); PCompilerOption pOption = std::make_shared<CompilerOption>();
@ -197,18 +202,7 @@ CompilerInfoManager::CompilerInfoManager()
mInfos.insert(CompilerType::Clang, std::make_shared<ClangCompilerInfo>()); mInfos.insert(CompilerType::Clang, std::make_shared<ClangCompilerInfo>());
mInfos.insert(CompilerType::GCC, std::make_shared<GCCCompilerInfo>()); mInfos.insert(CompilerType::GCC, std::make_shared<GCCCompilerInfo>());
mInfos.insert(CompilerType::GCC_UTF8, std::make_shared<GCCUTF8CompilerInfo>()); mInfos.insert(CompilerType::GCC_UTF8, std::make_shared<GCCUTF8CompilerInfo>());
} mInfos.insert(CompilerType::SDCC, std::make_shared<SDCCCompilerInfo>());
bool CompilerInfoManager::supportSyntaxCheck(CompilerType compilerType)
{
switch(compilerType) {
case CompilerType::GCC:
case CompilerType::GCC_UTF8:
case CompilerType::Clang:
return true;
default:
return false;
}
} }
PCompilerInfo CompilerInfoManager::getInfo(CompilerType compilerType) PCompilerInfo CompilerInfoManager::getInfo(CompilerType compilerType)
@ -248,6 +242,22 @@ bool CompilerInfoManager::supportCovertingCharset(CompilerType compilerType)
return pInfo->supportConvertingCharset(); return pInfo->supportConvertingCharset();
} }
bool CompilerInfoManager::supportStaticLink(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->supportStaticLink();
}
bool CompilerInfoManager::supportSyntaxCheck(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->supportSyntaxCheck();
}
bool CompilerInfoManager::forceUTF8InDebugger(CompilerType compilerType) bool CompilerInfoManager::forceUTF8InDebugger(CompilerType compilerType)
{ {
PCompilerInfo pInfo = getInfo(compilerType); PCompilerInfo pInfo = getInfo(compilerType);
@ -290,6 +300,11 @@ bool ClangCompilerInfo::forceUTF8InMakefile()
return false; return false;
} }
bool ClangCompilerInfo::supportStaticLink()
{
return true;
}
GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC) GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC)
{ {
} }
@ -309,6 +324,11 @@ bool GCCCompilerInfo::forceUTF8InMakefile()
return false; return false;
} }
bool GCCCompilerInfo::supportStaticLink()
{
return true;
}
GCCUTF8CompilerInfo::GCCUTF8CompilerInfo():CompilerInfo(COMPILER_GCC_UTF8) GCCUTF8CompilerInfo::GCCUTF8CompilerInfo():CompilerInfo(COMPILER_GCC_UTF8)
{ {
} }
@ -327,3 +347,86 @@ bool GCCUTF8CompilerInfo::forceUTF8InMakefile()
{ {
return true; return true;
} }
bool GCCUTF8CompilerInfo::supportStaticLink()
{
return true;
}
SDCCCompilerInfo::SDCCCompilerInfo():CompilerInfo(COMPILER_SDCC)
{
}
bool SDCCCompilerInfo::supportConvertingCharset()
{
return false;
}
bool SDCCCompilerInfo::forceUTF8InDebugger()
{
return false;
}
bool SDCCCompilerInfo::forceUTF8InMakefile()
{
return false;
}
bool SDCCCompilerInfo::supportStaticLink()
{
return false;
}
bool SDCCCompilerInfo::supportSyntaxCheck()
{
return false;
}
void SDCCCompilerInfo::prepareCompilerOptions()
{
QList<QPair<QString,QString>> sl;
QString groupName;
// // C options
// groupName = QObject::tr("C options");
// addOption(CC_CMD_OPT_ANSI, QObject::tr("Support all ANSI standard C programs (-ansi)"), groupName, true, true, false, "-ansi");
// addOption(CC_CMD_OPT_NO_ASM, QObject::tr("Do not recognize asm,inline or typeof as a keyword (-fno-asm)"), groupName, true, true, false, "-fno-asm");
// addOption(CC_CMD_OPT_TRADITIONAL_CPP, QObject::tr("Imitate traditional C preprocessors (-traditional-cpp)"), groupName, true, true, false, "-traditional-cpp");
groupName = QObject::tr("Code Generation");
// Optimization
sl.clear();
sl.append(QPair<QString,QString>("Intel MCS51","mcs51"));
sl.append(QPair<QString,QString>("Dallas DS80C390","ds390"));
sl.append(QPair<QString,QString>("Dallas DS80C400","ds400"));
sl.append(QPair<QString,QString>("Freescale/Motorola HC08","hc08"));
sl.append(QPair<QString,QString>("Freescale/Motorola S08","s08"));
sl.append(QPair<QString,QString>("Zilog Z80","z80"));
sl.append(QPair<QString,QString>("Zilog Z180","z180"));
sl.append(QPair<QString,QString>("Rabbit 2000/3000","r2k"));
sl.append(QPair<QString,QString>("Rabbit 3000","r3ka"));
sl.append(QPair<QString,QString>("Sharp SM83","sm83"));
sl.append(QPair<QString,QString>("Toshiba TLCS-90","tlcs90"));
sl.append(QPair<QString,QString>("Zilog eZ80","ez80_z80"));
sl.append(QPair<QString,QString>("STM8","stm8"));
sl.append(QPair<QString,QString>("Padauk processors with 13 bit wide program memory","pdk13"));
sl.append(QPair<QString,QString>("Padauk processors with 14 bit wide program memory","pdk14"));
sl.append(QPair<QString,QString>("Padauk processors with 15 bit wide program memory","pdk15"));
sl.append(QPair<QString,QString>("Padauk processors with 15 bit wide program memory","pdk15"));
sl.append(QPair<QString,QString>("Padauk processors with 15 bit wide program memory","pdk15"));
addOption(SDCC_CMD_OPT_PROCESSOR, QObject::tr("Optimization level (-Ox)"), groupName, true, true, false, "-m", sl);
// C++ Language Standards
sl.clear();
sl.append(QPair<QString,QString>("ANSI C89/ISO C90","c89"));
sl.append(QPair<QString,QString>("ISO C99","c99"));
sl.append(QPair<QString,QString>("ISO C11","c11"));
sl.append(QPair<QString,QString>("ISO C17","c17"));
sl.append(QPair<QString,QString>("ISO C2x","c2x"));
sl.append(QPair<QString,QString>("SDCC C89","sdcc89"));
sl.append(QPair<QString,QString>("SDCC C99","sdcc99"));
sl.append(QPair<QString,QString>("SDCC C11","sdcc11"));
sl.append(QPair<QString,QString>("SDCC C17","sdcc17"));
sl.append(QPair<QString,QString>("SDCC C2x","sdcc2x"));
addOption(SDCC_CMD_OPT_STD, QObject::tr("Language standard (-std)"), groupName, false, true, false, "-std-", sl);
}

View File

@ -8,6 +8,7 @@
#define COMPILER_CLANG "Clang" #define COMPILER_CLANG "Clang"
#define COMPILER_GCC "GCC" #define COMPILER_GCC "GCC"
#define COMPILER_GCC_UTF8 "GCC_UTF8" #define COMPILER_GCC_UTF8 "GCC_UTF8"
#define COMPILER_SDCC "SDCC"
#define C_CMD_OPT_STD "c_cmd_opt_std" #define C_CMD_OPT_STD "c_cmd_opt_std"
@ -45,6 +46,9 @@
#define CC_CMD_OPT_STOP_AFTER_PREPROCESSING "cc_cmd_opt_stop_after_preprocessing" #define CC_CMD_OPT_STOP_AFTER_PREPROCESSING "cc_cmd_opt_stop_after_preprocessing"
#define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe" #define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe"
#define SDCC_CMD_OPT_PROCESSOR "sdcc_cmd_opt_processor"
#define SDCC_CMD_OPT_STD "sdcc_cmd_opt_std"
#define COMPILER_OPTION_ON "on" #define COMPILER_OPTION_ON "on"
#define COMPILER_OPTION_OFF "" #define COMPILER_OPTION_OFF ""
@ -52,6 +56,7 @@ enum class CompilerType {
GCC, GCC,
GCC_UTF8, GCC_UTF8,
Clang, Clang,
SDCC,
Unknown Unknown
}; };
@ -87,6 +92,8 @@ public:
virtual bool supportConvertingCharset()=0; virtual bool supportConvertingCharset()=0;
virtual bool forceUTF8InDebugger()=0; virtual bool forceUTF8InDebugger()=0;
virtual bool forceUTF8InMakefile()=0; virtual bool forceUTF8InMakefile()=0;
virtual bool supportStaticLink()=0;
virtual bool supportSyntaxCheck();
protected: protected:
void addOption(const QString& key, void addOption(const QString& key,
const QString& name, const QString& name,
@ -112,12 +119,13 @@ using PCompilerInfoManager = std::shared_ptr<CompilerInfoManager>;
class CompilerInfoManager { class CompilerInfoManager {
public: public:
CompilerInfoManager(); CompilerInfoManager();
static bool supportSyntaxCheck(CompilerType compilerType);
static PCompilerInfo getInfo(CompilerType compilerType); static PCompilerInfo getInfo(CompilerType compilerType);
static bool hasCompilerOption(CompilerType compilerType, const QString& optKey); static bool hasCompilerOption(CompilerType compilerType, const QString& optKey);
static PCompilerOption getCompilerOption(CompilerType compilerType, const QString& optKey); static PCompilerOption getCompilerOption(CompilerType compilerType, const QString& optKey);
static QList<PCompilerOption> getCompilerOptions(CompilerType compilerType); static QList<PCompilerOption> getCompilerOptions(CompilerType compilerType);
static bool supportCovertingCharset(CompilerType compilerType); static bool supportCovertingCharset(CompilerType compilerType);
static bool supportStaticLink(CompilerType compilerType);
static bool supportSyntaxCheck(CompilerType compilerType);
static bool forceUTF8InDebugger(CompilerType compilerType); static bool forceUTF8InDebugger(CompilerType compilerType);
static PCompilerInfoManager getInstance(); static PCompilerInfoManager getInstance();
static void addInfo(CompilerType compilerType, PCompilerInfo info); static void addInfo(CompilerType compilerType, PCompilerInfo info);
@ -132,6 +140,7 @@ public:
bool supportConvertingCharset() override; bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override; bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override; bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
}; };
class GCCCompilerInfo: public CompilerInfo{ class GCCCompilerInfo: public CompilerInfo{
@ -140,6 +149,7 @@ public:
bool supportConvertingCharset() override; bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override; bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override; bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
}; };
class GCCUTF8CompilerInfo: public CompilerInfo{ class GCCUTF8CompilerInfo: public CompilerInfo{
@ -148,8 +158,20 @@ public:
bool supportConvertingCharset() override; bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override; bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override; bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
};
class SDCCCompilerInfo: public CompilerInfo{
public:
SDCCCompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
bool supportSyntaxCheck() override;
protected:
void prepareCompilerOptions() override;
}; };
#endif // COMPILERINFO_H #endif // COMPILERINFO_H

View File

@ -2948,14 +2948,10 @@ void Editor::initParser()
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& (isCFile(mFilename) || isHFile(mFilename))) { && (isCFile(mFilename) || isHFile(mFilename))) {
if (pSettings->codeCompletion().shareParser()) { if (pSettings->codeCompletion().shareParser()) {
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C); mParser = sharedParser(calcParserLanguage());
} else { } else {
mParser = std::make_shared<CppParser>(); mParser = std::make_shared<CppParser>();
if (mUseCppSyntax) { mParser->setLanguage(calcParserLanguage());
mParser->setLanguage(ParserLanguage::CPlusPlus);
} else {
mParser->setLanguage(ParserLanguage::C);
}
mParser->setOnGetFileStream( mParser->setOnGetFileStream(
std::bind( std::bind(
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(), &EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
@ -2970,6 +2966,16 @@ void Editor::initParser()
} }
} }
ParserLanguage Editor::calcParserLanguage()
{
if (!inProject()
&& pSettings->compilerSets().defaultSet()
&& pSettings->compilerSets().defaultSet()->compilerType()==CompilerType::SDCC) {
return ParserLanguage::SDCC;
}
return mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
}
Editor::QuoteStatus Editor::getQuoteStatus() Editor::QuoteStatus Editor::getQuoteStatus()
{ {
QuoteStatus Result = QuoteStatus::NotQuote; QuoteStatus Result = QuoteStatus::NotQuote;
@ -3110,8 +3116,8 @@ void Editor::reparse(bool resetParser)
return; return;
//qDebug()<<"reparse "<<mFilename; //qDebug()<<"reparse "<<mFilename;
//mParser->setEnabled(pSettings->codeCompletion().enabled()); //mParser->setEnabled(pSettings->codeCompletion().enabled());
ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
if (!inProject()) { if (!inProject()) {
ParserLanguage language = calcParserLanguage();
if (pSettings->codeCompletion().shareParser()) { if (pSettings->codeCompletion().shareParser()) {
if (language!=mParser->language()) { if (language!=mParser->language()) {
mParser->invalidateFile(mFilename); mParser->invalidateFile(mFilename);
@ -3461,12 +3467,21 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
keywords = syntaxer()->keywords(); keywords = syntaxer()->keywords();
} }
} else { } else {
if (mUseCppSyntax) { switch(calcParserLanguage()) {
case ParserLanguage::CPlusPlus:
foreach (const QString& keyword, CppKeywords.keys()) { foreach (const QString& keyword, CppKeywords.keys()) {
keywords.insert(keyword); keywords.insert(keyword);
} }
} else { break;
case ParserLanguage::C:
keywords = CKeywords; keywords = CKeywords;
break;
case ParserLanguage::SDCC:
keywords = CKeywords;
foreach (const QString& keyword, SDCCKeywords.keys()) {
keywords.insert(keyword);
}
break;
} }
if (pSettings->editor().enableCustomCTypeKeywords()) { if (pSettings->editor().enableCustomCTypeKeywords()) {
foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) { foreach (const QString& keyword, pSettings->editor().customCTypeKeywords()) {
@ -5229,6 +5244,14 @@ void Editor::applySettings()
set.insert(s); set.insert(s);
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set); ((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set);
} }
} else if (!inProject() && pSettings->compilerSets().defaultSet()
&& pSettings->compilerSets().defaultSet()->compilerType()==CompilerType::SDCC) {
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) {
QSet<QString> set;
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
set.insert(s);
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set);
}
} else { } else {
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) { if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP) {
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(QSet<QString>()); ((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(QSet<QString>());

View File

@ -262,6 +262,7 @@ private:
bool handleCodeCompletion(QChar key); bool handleCodeCompletion(QChar key);
void initParser(); void initParser();
ParserLanguage calcParserLanguage();
void undoSymbolCompletion(int pos); void undoSymbolCompletion(int pos);
QuoteStatus getQuoteStatus(); QuoteStatus getQuoteStatus();

View File

@ -1945,8 +1945,6 @@ void MainWindow::checkSyntaxInBack(Editor *e)
return; return;
if (mCompilerManager->compiling()) if (mCompilerManager->compiling())
return; return;
if (!pSettings->compilerSets().defaultSet())
return;
if (mCheckSyntaxInBack) if (mCheckSyntaxInBack)
return; return;
@ -1962,8 +1960,15 @@ void MainWindow::checkSyntaxInBack(Editor *e)
clearIssues(); clearIssues();
CompileTarget target =getCompileTarget(); CompileTarget target =getCompileTarget();
if (target ==CompileTarget::Project) { if (target ==CompileTarget::Project) {
int index = mProject->options().compilerSet;
Settings::PCompilerSet set = pSettings->compilerSets().getSet(index);
if (!set || !CompilerInfoManager::supportSyntaxCheck(set->compilerType()))
return;
mCompilerManager->checkSyntax(e->filename(), e->fileEncoding(), e->text(), mProject); mCompilerManager->checkSyntax(e->filename(), e->fileEncoding(), e->text(), mProject);
} else { } else {
Settings::PCompilerSet set = pSettings->compilerSets().defaultSet();
if (!set || !CompilerInfoManager::supportSyntaxCheck(set->compilerType()))
return;
mCompilerManager->checkSyntax(e->filename(),e->fileEncoding(),e->text(), nullptr); mCompilerManager->checkSyntax(e->filename(),e->fileEncoding(),e->text(), nullptr);
} }
} }
@ -3363,13 +3368,17 @@ void MainWindow::newEditor(const QString& suffix)
{ {
try { try {
QString filename; QString filename;
do { do {
filename = QString("untitled%1").arg(getNewFileNumber()); filename = QString("untitled%1").arg(getNewFileNumber());
if (suffix.isEmpty()) { if (suffix.isEmpty()) {
if (pSettings->editor().defaultFileCpp()) if (pSettings->editor().defaultFileCpp()) {
filename+=".cpp"; Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet();
else if (compilerSet && !compilerSet->canCompileCPP()) {
filename+=".c";
} else {
filename+=".cpp";
}
} else
filename+=".c"; filename+=".c";
} else } else
filename+= "." + suffix; filename+= "." + suffix;

View File

@ -2188,6 +2188,23 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
isStatic); isStatic);
return; return;
} else if (mTokenizer[mIndex + 1]->text == '(') { } else if (mTokenizer[mIndex + 1]->text == '(') {
if (mLanguage==ParserLanguage::SDCC && mTokenizer[mIndex]->text=="__at") {
if (!sName.isEmpty()) {
sType = sType+" "+sName;
sName = "";
}
sType+=" __at";
mIndex++;
int idx= mTokenizer[mIndex]->matchIndex;
if (idx<tokenCount) {
for (int i=mIndex;i<=idx;i++) {
sType+=mTokenizer[i]->text;
}
}
mIndex=idx+1;
continue;
}
if (mIndex+2<tokenCount && mTokenizer[mIndex+2]->text == '*') { if (mIndex+2<tokenCount && mTokenizer[mIndex+2]->text == '*') {
//foo(*blabla), it's a function pointer var //foo(*blabla), it's a function pointer var
handleVar(sType+" "+sName,isExtern,isStatic); handleVar(sType+" "+sName,isExtern,isStatic);
@ -2295,8 +2312,9 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType)
isFriend = true; isFriend = true;
else if (s == "extern") else if (s == "extern")
isExtern = true; isExtern = true;
if (!s.isEmpty() && !(s=="extern")) if (!s.isEmpty() && !(s=="extern")) {
sType = sType + ' '+ s; sType = sType + ' '+ s;
}
} }
mIndex++; mIndex++;
} }
@ -6401,7 +6419,18 @@ ParserLanguage CppParser::language() const
void CppParser::setLanguage(ParserLanguage newLanguage) void CppParser::setLanguage(ParserLanguage newLanguage)
{ {
mLanguage = newLanguage; if (mLanguage != newLanguage) {
mLanguage = newLanguage;
if (mLanguage == ParserLanguage::SDCC) {
mCppKeywords = CppKeywords;
mCppTypeKeywords = CppTypeKeywords;
mCppKeywords.insert(SDCCKeywords);
mCppTypeKeywords.unite(SDCCTypeKeywords);
} else {
mCppKeywords = CppKeywords;
mCppTypeKeywords = CppTypeKeywords;
}
}
} }

View File

@ -26,6 +26,8 @@
QStringList CppDirectives; QStringList CppDirectives;
QStringList JavadocTags; QStringList JavadocTags;
QMap<QString,KeywordType> CppKeywords; QMap<QString,KeywordType> CppKeywords;
QMap<QString,KeywordType> SDCCKeywords;
QSet<QString> SDCCTypeKeywords;
QSet<QString> CppControlKeyWords; QSet<QString> CppControlKeyWords;
QSet<QString> CppTypeKeywords; QSet<QString> CppTypeKeywords;
QSet<QString> CKeywords; QSet<QString> CKeywords;
@ -163,6 +165,27 @@ void initParser()
CppKeywords.insert("void",KeywordType::None); CppKeywords.insert("void",KeywordType::None);
CppKeywords.insert("wchar_t",KeywordType::None); CppKeywords.insert("wchar_t",KeywordType::None);
SDCCKeywords.insert("__sfr",KeywordType::None);
SDCCKeywords.insert("__sfr16",KeywordType::None);
SDCCKeywords.insert("__sfr32",KeywordType::None);
SDCCKeywords.insert("__sbit",KeywordType::None);
SDCCKeywords.insert("__bit",KeywordType::None);
SDCCKeywords.insert("__data",KeywordType::SkipItself);
SDCCKeywords.insert("__near",KeywordType::SkipItself);
SDCCKeywords.insert("__xdata",KeywordType::SkipItself);
SDCCKeywords.insert("__far",KeywordType::SkipItself);
SDCCKeywords.insert("__idata",KeywordType::SkipItself);
SDCCKeywords.insert("__pdata",KeywordType::SkipItself);
SDCCKeywords.insert("__code",KeywordType::SkipItself);
SDCCKeywords.insert("__banked",KeywordType::SkipItself);
SDCCKeywords.insert("__at",KeywordType::SkipNextParenthesis);
SDCCTypeKeywords.insert("__sfr");
SDCCTypeKeywords.insert("__sfr16");
SDCCTypeKeywords.insert("__sfr32");
SDCCTypeKeywords.insert("__sbit");
SDCCTypeKeywords.insert("__bit");
// type keywords // type keywords
CppTypeKeywords.insert("auto"); CppTypeKeywords.insert("auto");
CppTypeKeywords.insert("bool"); CppTypeKeywords.insert("bool");

View File

@ -26,7 +26,8 @@ using GetFileStreamCallBack = std::function<bool (const QString&, QStringList&)>
enum ParserLanguage { enum ParserLanguage {
C, C,
CPlusPlus CPlusPlus,
SDCC
}; };
struct CodeSnippet { struct CodeSnippet {
@ -303,6 +304,8 @@ using PFileIncludes = std::shared_ptr<FileIncludes>;
extern QStringList CppDirectives; extern QStringList CppDirectives;
extern QStringList JavadocTags; extern QStringList JavadocTags;
extern QMap<QString,KeywordType> CppKeywords; extern QMap<QString,KeywordType> CppKeywords;
extern QMap<QString,KeywordType> SDCCKeywords;
extern QSet<QString> SDCCTypeKeywords;
extern QSet<QString> CppControlKeyWords; extern QSet<QString> CppControlKeyWords;
extern QSet<QString> CKeywords; extern QSet<QString> CKeywords;
extern QSet<QString> CppTypeKeywords; extern QSet<QString> CppTypeKeywords;

View File

@ -26,6 +26,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QScreen> #include <QScreen>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QRegularExpression>
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#endif #endif
@ -1701,7 +1702,7 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder, const QString&
setProperties(compilerFolder,c_prog); setProperties(compilerFolder,c_prog);
//manually set the directories //manually set the directories
setDirectories(compilerFolder, mCompilerType); setDirectories(compilerFolder);
setExecutables(); setExecutables();
@ -2008,7 +2009,7 @@ QStringList &Settings::CompilerSet::defaultCIncludeDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0],mCompilerType); setDirectories(binDirs()[0]);
} }
return mDefaultCIncludeDirs; return mDefaultCIncludeDirs;
} }
@ -2017,7 +2018,7 @@ QStringList &Settings::CompilerSet::defaultCppIncludeDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0],mCompilerType); setDirectories(binDirs()[0]);
} }
return mDefaultCppIncludeDirs; return mDefaultCppIncludeDirs;
} }
@ -2026,7 +2027,7 @@ QStringList &Settings::CompilerSet::defaultLibDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) { if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true; mFullLoaded=true;
setDirectories(binDirs()[0],mCompilerType); setDirectories(binDirs()[0]);
} }
return mLibDirs; return mLibDirs;
} }
@ -2153,6 +2154,15 @@ static void addExistingDirectory(QStringList& dirs, const QString& directory) {
} }
void Settings::CompilerSet::setProperties(const QString& binDir, const QString& c_prog) void Settings::CompilerSet::setProperties(const QString& binDir, const QString& c_prog)
{
if (c_prog == SDCC_PROGRAM) {
setSDCCProperties(binDir,c_prog);
} else {
setGCCProperties(binDir,c_prog);
}
}
void Settings::CompilerSet::setGCCProperties(const QString& binDir, const QString& c_prog)
{ {
// We have tested before the call // We have tested before the call
// if (!fileExists(c_prog)) // if (!fileExists(c_prog))
@ -2268,10 +2278,6 @@ void Settings::CompilerSet::setProperties(const QString& binDir, const QString&
// Add the default directories // Add the default directories
addExistingDirectory(mBinDirs, includeTrailingPathDelimiter(folder) + "bin"); addExistingDirectory(mBinDirs, includeTrailingPathDelimiter(folder) + "bin");
// addExistingDirectory(mDefaultLibDirs, includeTrailingPathDelimiter(folder) + "lib");
// addExistingDirectory(mDefaultCIncludeDirs, includeTrailingPathDelimiter(folder) + "include");
// addExistingDirectory(mDefaultCppIncludeDirs, includeTrailingPathDelimiter(folder) + "include");
if (!mDumpMachine.isEmpty()) { if (!mDumpMachine.isEmpty()) {
//mingw-w64 bin folder //mingw-w64 bin folder
addExistingDirectory(mBinDirs, addExistingDirectory(mBinDirs,
@ -2281,6 +2287,39 @@ void Settings::CompilerSet::setProperties(const QString& binDir, const QString&
} }
} }
void Settings::CompilerSet::setSDCCProperties(const QString& binDir, const QString& c_prog)
{
// We have tested before the call
// if (!fileExists(c_prog))
// return;
// Obtain version number and compiler distro etc
QStringList arguments;
arguments.append("-v");
QByteArray output = getCompilerOutput(binDir, c_prog,arguments);
if (!output.startsWith("SDCC"))
return;
//Target
int delimPos = 0;
while (delimPos<output.length() && (output[delimPos]>=32))
delimPos++;
QString triplet = output.mid(0,delimPos);
qDebug()<<triplet;
QRegularExpression re("\\s+(\\d+\\.\\d+\\.\\d+)\\s+");
QRegularExpressionMatch match = re.match(triplet);
if (match.hasMatch())
mVersion = match.captured(1);
if (mVersion.isEmpty())
mName = "SDCC";
else
mName = "SDCC "+mVersion;
mCompilerType=CompilerType::SDCC;
addExistingDirectory(mBinDirs, binDir);
}
QStringList Settings::CompilerSet::defines(bool isCpp) { QStringList Settings::CompilerSet::defines(bool isCpp) {
// get default defines // get default defines
QStringList arguments; QStringList arguments;
@ -2288,12 +2327,17 @@ QStringList Settings::CompilerSet::defines(bool isCpp) {
arguments.append("-E"); arguments.append("-E");
arguments.append("-x"); arguments.append("-x");
QString key; QString key;
if (isCpp) { if (mCompilerType==CompilerType::SDCC) {
arguments.append("c++");
key=CC_CMD_OPT_STD;
} else {
arguments.append("c"); arguments.append("c");
key=C_CMD_OPT_STD; key=SDCC_CMD_OPT_PROCESSOR;
} else {
if (isCpp) {
arguments.append("c++");
key=CC_CMD_OPT_STD;
} else {
arguments.append("c");
key=C_CMD_OPT_STD;
}
} }
//language standard //language standard
PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerType(), key); PCompilerOption pOption = CompilerInfoManager::getCompilerOption(compilerType(), key);
@ -2321,7 +2365,11 @@ QStringList Settings::CompilerSet::defines(bool isCpp) {
void Settings::CompilerSet::setExecutables() void Settings::CompilerSet::setExecutables()
{ {
if (mCompilerType == CompilerType::Clang) { if (mCompilerType == CompilerType::SDCC) {
mCCompiler = findProgramInBinDirs(SDCC_PROGRAM);
if (mCCompiler.isEmpty())
mCCompiler = findProgramInBinDirs(SDCC_PROGRAM);
} else if (mCompilerType == CompilerType::Clang) {
mCCompiler = findProgramInBinDirs(CLANG_PROGRAM); mCCompiler = findProgramInBinDirs(CLANG_PROGRAM);
mCppCompiler = findProgramInBinDirs(CLANG_CPP_PROGRAM); mCppCompiler = findProgramInBinDirs(CLANG_CPP_PROGRAM);
mDebugger = findProgramInBinDirs(GDB_PROGRAM); mDebugger = findProgramInBinDirs(GDB_PROGRAM);
@ -2349,11 +2397,20 @@ void Settings::CompilerSet::setExecutables()
mResourceCompiler = findProgramInBinDirs(WINDRES_PROGRAM); mResourceCompiler = findProgramInBinDirs(WINDRES_PROGRAM);
} }
void Settings::CompilerSet::setDirectories(const QString& binDir,CompilerType compilerType) void Settings::CompilerSet::setDirectories(const QString& binDir)
{
if (mCompilerType == CompilerType::SDCC) {
setSDCCDirectories(binDir);
} else {
setGCCDirectories(binDir);
}
}
void Settings::CompilerSet::setGCCDirectories(const QString& binDir)
{ {
QString folder = QFileInfo(binDir).absolutePath(); QString folder = QFileInfo(binDir).absolutePath();
QString c_prog; QString c_prog;
if (compilerType==CompilerType::Clang) if (mCompilerType==CompilerType::Clang)
c_prog = CLANG_PROGRAM; c_prog = CLANG_PROGRAM;
else else
c_prog = GCC_PROGRAM; c_prog = GCC_PROGRAM;
@ -2491,6 +2548,62 @@ void Settings::CompilerSet::setDirectories(const QString& binDir,CompilerType co
} }
} }
void Settings::CompilerSet::setSDCCDirectories(const QString& binDir)
{
QString folder = QFileInfo(binDir).absolutePath();
QString c_prog = SDCC_PROGRAM;
// Find default directories
// C include dirs
QStringList arguments;
arguments.clear();
arguments.append("--print-search-dirs");
QByteArray output = getCompilerOutput(binDir,c_prog,arguments);
//bindirs
QByteArray targetStr = QByteArray("programs:");
int delimPos1 = output.indexOf(targetStr);
int delimPos2 = output.indexOf("datadir:");
if (delimPos1 >0 && delimPos2>delimPos1 ) {
delimPos1 += targetStr.length();
QList<QByteArray> lines = output.mid(delimPos1, delimPos2-delimPos1).split('\n');
for (QByteArray& line:lines) {
QByteArray trimmedLine = line.trimmed();
if (!trimmedLine.isEmpty()) {
addExistingDirectory(mBinDirs,trimmedLine);
}
}
}
targetStr = QByteArray("includedir:");
delimPos1 = output.indexOf(targetStr);
delimPos2 = output.indexOf("libdir:");
if (delimPos1 >0 && delimPos2>delimPos1 ) {
delimPos1 += targetStr.length();
QList<QByteArray> lines = output.mid(delimPos1, delimPos2-delimPos1).split('\n');
for (QByteArray& line:lines) {
QByteArray trimmedLine = line.trimmed();
if (!trimmedLine.isEmpty()) {
addExistingDirectory(mDefaultCIncludeDirs,trimmedLine);
}
}
}
targetStr = QByteArray("libdir:");
delimPos1 = output.indexOf(targetStr);
delimPos2 = output.indexOf("libpath:");
if (delimPos1 >0 && delimPos2>delimPos1 ) {
delimPos1 += targetStr.length();
QList<QByteArray> lines = output.mid(delimPos1, delimPos2-delimPos1).split('\n');
for (QByteArray& line:lines) {
QByteArray trimmedLine = line.trimmed();
if (!trimmedLine.isEmpty()) {
addExistingDirectory(mDefaultLibDirs,trimmedLine);
}
}
}
}
int Settings::CompilerSet::mainVersion() const int Settings::CompilerSet::mainVersion() const
{ {
int i = mVersion.indexOf('.'); int i = mVersion.indexOf('.');
@ -2528,8 +2641,13 @@ void Settings::CompilerSet::setUserInput()
{ {
mUseCustomCompileParams = false; mUseCustomCompileParams = false;
mUseCustomLinkParams = false; mUseCustomLinkParams = false;
mAutoAddCharsetParams = true; if (mCompilerType==CompilerType::SDCC) {
mStaticLink = true; mAutoAddCharsetParams = false;
mStaticLink = false;
} else {
mAutoAddCharsetParams = true;
mStaticLink = true;
}
} }
@ -2812,45 +2930,44 @@ bool Settings::CompilerSets::addSets(const QString &folder, const QString& c_pro
PCompilerSet baseSet = addSet(folder,c_prog); PCompilerSet baseSet = addSet(folder,c_prog);
if (!baseSet || baseSet->name().isEmpty()) if (!baseSet || baseSet->name().isEmpty())
return false; return false;
QString baseName = baseSet->name(); if (c_prog == SDCC_PROGRAM) {
QString platformName; //sdcc do nothing
if (isTarget64Bit(baseSet->target())) {
if (baseName.startsWith("TDM-GCC ")) {
PCompilerSet set= addSet(baseSet);
platformName = "32-bit";
set->setName(baseName + " " + platformName + " Release");
set64_32Options(set);
setReleaseOptions(set);
set = addSet(baseSet);
set->setName(baseName + " " + platformName + " Debug");
set64_32Options(set);
setDebugOptions(set);
}
platformName = "64-bit";
} else { } else {
platformName = "32-bit"; QString baseName = baseSet->name();
} QString platformName;
if (isTarget64Bit(baseSet->target())) {
if (baseName.startsWith("TDM-GCC ")) {
PCompilerSet set= addSet(baseSet);
platformName = "32-bit";
set->setName(baseName + " " + platformName + " Release");
set64_32Options(set);
setReleaseOptions(set);
set = addSet(baseSet);
set->setName(baseName + " " + platformName + " Debug");
set64_32Options(set);
setDebugOptions(set);
}
platformName = "64-bit";
} else {
platformName = "32-bit";
}
PCompilerSet debugSet = addSet(baseSet); PCompilerSet debugSet = addSet(baseSet);
debugSet->setName(baseName + " " + platformName + " Debug"); debugSet->setName(baseName + " " + platformName + " Debug");
setDebugOptions(debugSet); setDebugOptions(debugSet);
// Enable ASan compiler set if it is supported and gdb works with ASan. // Enable ASan compiler set if it is supported and gdb works with ASan.
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
PCompilerSet debugAsanSet = addSet(baseSet); PCompilerSet debugAsanSet = addSet(baseSet);
debugAsanSet->setName(baseName + " " + platformName + " Debug with ASan"); debugAsanSet->setName(baseName + " " + platformName + " Debug with ASan");
setDebugOptions(debugAsanSet, true); setDebugOptions(debugAsanSet, true);
#endif #endif
baseSet->setName(baseName + " " + platformName + " Release"); baseSet->setName(baseName + " " + platformName + " Release");
setReleaseOptions(baseSet); setReleaseOptions(baseSet);
}
// baseSet = addSet(folder);
// baseSet->setName(baseName + " " + platformName + " Profiling");
// baseSet->setCompilerSetType(CompilerSetType::CST_PROFILING);
// setProfileOptions(baseSet);
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
# if defined(__x86_64__) || __SIZEOF_POINTER__ == 4 # if defined(__x86_64__) || __SIZEOF_POINTER__ == 4
@ -2870,17 +2987,19 @@ bool Settings::CompilerSets::addSets(const QString &folder)
{ {
if (!directoryExists(folder)) if (!directoryExists(folder))
return false; return false;
if (!fileExists(folder, GCC_PROGRAM) && !fileExists(folder, CLANG_PROGRAM)) {
return false;
}
if (fileExists(folder, GCC_PROGRAM)) { if (fileExists(folder, GCC_PROGRAM)) {
addSets(folder,GCC_PROGRAM); addSets(folder,GCC_PROGRAM);
return true;
} }
if (fileExists(folder, CLANG_PROGRAM)) { if (fileExists(folder, CLANG_PROGRAM)) {
addSets(folder,CLANG_PROGRAM); addSets(folder,CLANG_PROGRAM);
return true;
} }
return true; if (fileExists(folder, SDCC_PROGRAM)) {
addSets(folder,SDCC_PROGRAM);
return true;
}
return false;
} }
void Settings::CompilerSets::clearSets() void Settings::CompilerSets::clearSets()
@ -3214,6 +3333,8 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
pSet->setCompilerType(CompilerType::GCC); pSet->setCompilerType(CompilerType::GCC);
} else if (temp==COMPILER_GCC_UTF8) { } else if (temp==COMPILER_GCC_UTF8) {
pSet->setCompilerType(CompilerType::GCC_UTF8); pSet->setCompilerType(CompilerType::GCC_UTF8);
} else if (temp==COMPILER_SDCC) {
pSet->setCompilerType(CompilerType::SDCC);
} else { } else {
pSet->setCompilerType((CompilerType)mSettings->mSettings.value("CompilerType").toInt()); pSet->setCompilerType((CompilerType)mSettings->mSettings.value("CompilerType").toInt());
} }

View File

@ -1441,7 +1441,11 @@ public:
bool isCompilerInfoUsingUTF8() const; bool isCompilerInfoUsingUTF8() const;
private: private:
void setDirectories(const QString& binDir, CompilerType mCompilerType); void setGCCProperties(const QString& binDir, const QString& c_prog);
void setSDCCProperties(const QString& binDir, const QString& c_prog);
void setDirectories(const QString& binDir);
void setGCCDirectories(const QString& binDir);
void setSDCCDirectories(const QString& binDir);
//load hard defines //load hard defines
void setExecutables(); void setExecutables();
void setUserInput(); void setUserInput();

View File

@ -74,12 +74,17 @@ void CompilerSetOptionWidget::init()
static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSetOptionWidget* ui) { static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSetOptionWidget* ui) {
ui->chkAutoAddCharset->setEnabled(pSet->compilerType() != CompilerType::Clang); bool supportCharset = CompilerInfoManager::supportCovertingCharset(pSet->compilerType());
ui->chkAutoAddCharset->setVisible(pSet->compilerType() != CompilerType::Clang); ui->chkAutoAddCharset->setEnabled(supportCharset);
ui->cbEncoding->setEnabled(pSet->compilerType() != CompilerType::Clang); ui->cbEncoding->setEnabled(supportCharset);
ui->cbEncoding->setVisible(pSet->compilerType() != CompilerType::Clang); ui->cbEncodingDetails->setEnabled(supportCharset);
ui->cbEncodingDetails->setEnabled(pSet->compilerType() != CompilerType::Clang); ui->panelCharset->setVisible(supportCharset);
ui->cbEncodingDetails->setVisible(pSet->compilerType() != CompilerType::Clang); ui->chkAutoAddCharset->setEnabled(supportCharset);
ui->chkAutoAddCharset->setVisible(supportCharset);
bool supportStaticLink = CompilerInfoManager::supportStaticLink(pSet->compilerType());
ui->chkStaticLink->setEnabled(supportStaticLink);
ui->chkStaticLink->setVisible(supportStaticLink);
ui->chkUseCustomCompilerParams->setChecked(pSet->useCustomCompileParams()); ui->chkUseCustomCompilerParams->setChecked(pSet->useCustomCompileParams());
ui->txtCustomCompileParams->setPlainText(pSet->customCompileParams()); ui->txtCustomCompileParams->setPlainText(pSet->customCompileParams());

View File

@ -121,7 +121,7 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QWidget" name="widget" native="true"> <widget class="QWidget" name="panelCharset" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>

View File

@ -37,6 +37,7 @@
#define CLANG_CPP_PROGRAM "clang++.exe" #define CLANG_CPP_PROGRAM "clang++.exe"
#define LLDB_MI_PROGRAM "lldb-mi.exe" #define LLDB_MI_PROGRAM "lldb-mi.exe"
#define LLDB_SERVER_PROGRAM "lldb-server.exe" #define LLDB_SERVER_PROGRAM "lldb-server.exe"
#define SDCC_PROGRAM "sdcc.exe"
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
#define CONSOLE_PAUSER "consolepauser" #define CONSOLE_PAUSER "consolepauser"
#define ASSEMBLER "nasm" #define ASSEMBLER "nasm"
@ -55,6 +56,7 @@
#define CLANG_CPP_PROGRAM "clang++" #define CLANG_CPP_PROGRAM "clang++"
#define LLDB_MI_PROGRAM "lldb-mi" #define LLDB_MI_PROGRAM "lldb-mi"
#define LLDB_SERVER_PROGRAM "lldb-server" #define LLDB_SERVER_PROGRAM "lldb-server"
#define SDCC_PROGRAM "sdcc"
#elif defined(Q_OS_MACOS) #elif defined(Q_OS_MACOS)
#define CONSOLE_PAUSER "consolepauser" #define CONSOLE_PAUSER "consolepauser"
#define ASSEMBLER "nasm" #define ASSEMBLER "nasm"
@ -72,6 +74,7 @@
#define CLANG_CPP_PROGRAM "clang++" #define CLANG_CPP_PROGRAM "clang++"
#define LLDB_MI_PROGRAM "lldb-mi" #define LLDB_MI_PROGRAM "lldb-mi"
#define LLDB_SERVER_PROGRAM "lldb-server" #define LLDB_SERVER_PROGRAM "lldb-server"
#define SDCC_PROGRAM "sdcc"
#else #else
#error "Only support windows, Linux and MacOS now!" #error "Only support windows, Linux and MacOS now!"
#endif #endif