Skip to content

Commit

Permalink
optimize the algorithm for finding compiler sets
Browse files Browse the repository at this point in the history
  • Loading branch information
royqh1979 committed Jul 24, 2022
1 parent 8d51876 commit 8affc31
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
86 changes: 53 additions & 33 deletions RedPandaIDE/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,10 +1464,10 @@ void Settings::Editor::setTabToSpaces(bool tabToSpaces)
}

Settings::CompilerSet::CompilerSet():
mFullLoaded(false),
mAutoAddCharsetParams(true),
mExecCharset(ENCODING_SYSTEM_DEFAULT),
mStaticLink(true),
mFullLoaded(false)
mStaticLink(true)
{

}
Expand All @@ -1482,7 +1482,7 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder, const QString&
setProperties(compilerFolder, cc_prog);

//manually set the directories
setDirectories(compilerFolder, cc_prog);
setDirectories(compilerFolder, mCompilerType);

setExecutables();

Expand All @@ -1504,27 +1504,42 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set):
mDebugger(set.mDebugger),
mProfiler(set.mProfiler),
mResourceCompiler(set.mResourceCompiler),
mDebugServer(set.mDebugServer),

mBinDirs(set.mBinDirs),
mCIncludeDirs(set.mCIncludeDirs),
mCppIncludeDirs(set.mCppIncludeDirs),
mLibDirs(set.mLibDirs),
mDefaultLibDirs(set.mDefaultLibDirs),
mDefaultCIncludeDirs(set.mDefaultCIncludeDirs),
mDefaultCppIncludeDirs(set.mDefaultCppIncludeDirs),

mDumpMachine(set.mDumpMachine),
mVersion(set.mVersion),
mType(set.mType),
mName(set.mName),
mDefines(set.mDefines),
mTarget(set.mTarget),
mCompilerType(set.mCompilerType),
mCompilerSetType(set.mCompilerSetType),

mUseCustomCompileParams(set.mUseCustomCompileParams),
mUseCustomLinkParams(set.mUseCustomLinkParams),
mCustomCompileParams(set.mCustomCompileParams),
mCustomLinkParams(set.mCustomLinkParams),
mAutoAddCharsetParams(set.mAutoAddCharsetParams),
mExecCharset(set.mExecCharset),
mStaticLink(set.mStaticLink),
mCompileOptions(set.mCompileOptions)
{

}

void Settings::CompilerSet::resetCompileOptionts()
{
mCompileOptions.clear();
}

bool Settings::CompilerSet::setCompileOption(const QString &key, int valIndex)
{
PCompilerOption op = CompilerInfoManager::getCompilerOption(mCompilerType, key);
Expand Down Expand Up @@ -1773,7 +1788,7 @@ QStringList &Settings::CompilerSet::defaultCIncludeDirs()
{
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0],mCCompiler);
setDirectories(binDirs()[0],mCompilerType);
setDefines();
}
return mDefaultCIncludeDirs;
Expand All @@ -1783,7 +1798,7 @@ QStringList &Settings::CompilerSet::defaultCppIncludeDirs()
{
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0],mCCompiler);
setDirectories(binDirs()[0],mCompilerType);
setDefines();
}
return mDefaultCppIncludeDirs;
Expand All @@ -1793,7 +1808,7 @@ QStringList &Settings::CompilerSet::defaultLibDirs()
{
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0],mCCompiler);
setDirectories(binDirs()[0],mCompilerType);
setDefines();
}
return mLibDirs;
Expand Down Expand Up @@ -1843,7 +1858,7 @@ const QStringList& Settings::CompilerSet::defines()
{
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0],mCCompiler);
setDirectories(binDirs()[0],mCompilerType);
setDefines();
}
return mDefines;
Expand Down Expand Up @@ -2100,9 +2115,14 @@ void Settings::CompilerSet::setExecutables()
mProfiler = findProgramInBinDirs(GPROF_PROGRAM);
}

void Settings::CompilerSet::setDirectories(const QString& binDir,const QString& cc_prog)
void Settings::CompilerSet::setDirectories(const QString& binDir,const QString& compilerType)
{
QString folder = QFileInfo(binDir).absolutePath();
QString cc_prog;
if (compilerType==COMPILER_CLANG)
cc_prog = CLANG_PROGRAM;
else
cc_prog = GCC_PROGRAM;
// Find default directories
// C include dirs
QStringList arguments;
Expand Down Expand Up @@ -2378,6 +2398,13 @@ Settings::PCompilerSet Settings::CompilerSets::addSet(const QString &folder, con
return p;
}

Settings::PCompilerSet Settings::CompilerSets::addSet(const PCompilerSet &pSet)
{
PCompilerSet p=std::make_shared<CompilerSet>(*pSet);
mList.push_back(p);
return p;
}

static void set64_32Options(Settings::PCompilerSet pSet) {
pSet->setCompileOption(CC_CMD_OPT_POINTER_SIZE,"32");
}
Expand Down Expand Up @@ -2414,39 +2441,34 @@ bool Settings::CompilerSets::addSets(const QString &folder, const QString& cc_pr
QString platformName;
if (baseSet->target() == "x86_64") {
if (baseName.startsWith("TDM-GCC ")) {
PCompilerSet set= addSet(baseSet);
platformName = "32-bit";
baseSet->setName(baseName + " " + platformName + " Release");
baseSet->setCompilerSetType(CompilerSetType::CST_RELEASE);
set64_32Options(baseSet);
setReleaseOptions(baseSet);

baseSet = addSet(folder,cc_prog);
baseSet->setName(baseName + " " + platformName + " Debug");
baseSet->setCompilerSetType(CompilerSetType::CST_DEBUG);
set64_32Options(baseSet);
setDebugOptions(baseSet);

// baseSet = addSet(folder);
// baseSet->setName(baseName + " " + platformName + " Profiling");
// baseSet->setCompilerSetType(CompilerSetType::CST_PROFILING);
// set64_32Options(baseSet);
// setProfileOptions(baseSet);

baseSet = addSet(folder,cc_prog);
set->setName(baseName + " " + platformName + " Release");
set->setCompilerSetType(CompilerSetType::CST_RELEASE);
set64_32Options(set);
setReleaseOptions(set);

set = addSet(baseSet);
set->setName(baseName + " " + platformName + " Debug");
set->setCompilerSetType(CompilerSetType::CST_DEBUG);
set64_32Options(set);
setDebugOptions(set);
}
platformName = "64-bit";
} else {
platformName = "32-bit";
}


PCompilerSet set = addSet(baseSet);
set->setName(baseName + " " + platformName + " Debug");
set->setCompilerSetType(CompilerSetType::CST_DEBUG);
setDebugOptions(set);

baseSet->setName(baseName + " " + platformName + " Release");
baseSet->setCompilerSetType(CompilerSetType::CST_RELEASE);
setReleaseOptions(baseSet);

baseSet = addSet(folder,cc_prog);
baseSet->setName(baseName + " " + platformName + " Debug");
baseSet->setCompilerSetType(CompilerSetType::CST_DEBUG);
setDebugOptions(baseSet);

// baseSet = addSet(folder);
// baseSet->setName(baseName + " " + platformName + " Profiling");
// baseSet->setCompilerSetType(CompilerSetType::CST_PROFILING);
Expand Down Expand Up @@ -2833,8 +2855,6 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
if (pSet->binDirs().isEmpty())
return PCompilerSet();

//pSet->setDirectories(pSet->binDirs()[0]);
//pSet->setDefines();
return pSet;
}

Expand Down
14 changes: 8 additions & 6 deletions RedPandaIDE/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1176,15 +1176,17 @@ class Settings
CompilerSet& operator= (const CompilerSet& ) = delete;
CompilerSet& operator= (const CompilerSet&& ) = delete;

// Initialization
void setProperties(const QString& binDir, const QString& cc_prog);

void resetCompileOptionts();
bool setCompileOption(const QString& key, int valIndex);
bool setCompileOption(const QString& key, const QString& value);
void unsetCompileOption(const QString& key);
void setCompileOptions(const QMap<QString, QString> options);

QString getCompileOptionValue(const QString& key);

void setProperties(const QString& binDir, const QString& cc_prog);
void setDirectories(const QString& binDir, const QString& cc_prog);
int mainVersion();

bool dirsValid(QString& msg);
Expand Down Expand Up @@ -1239,9 +1241,6 @@ class Settings
//Converts options to and from memory format ( for old settings compatibility)
void setIniOptions(const QByteArray& value);

//load hard defines
void setDefines();

bool staticLink() const;
void setStaticLink(bool newStaticLink);

Expand All @@ -1261,7 +1260,9 @@ class Settings
const QMap<QString, QString> &compileOptions() const;

private:
// Initialization
void setDirectories(const QString& binDir, const QString& mCompilerType);
//load hard defines
void setDefines();
void setExecutables();
void setUserInput();

Expand Down Expand Up @@ -1337,6 +1338,7 @@ class Settings

private:
PCompilerSet addSet(const QString& folder, const QString& cc_prog);
PCompilerSet addSet(const PCompilerSet &pSet);
bool addSets(const QString& folder, const QString& cc_prog);
void savePath(const QString& name, const QString& path);
void savePathList(const QString& name, const QStringList& pathList);
Expand Down

0 comments on commit 8affc31

Please sign in to comment.