Skip to content

Commit

Permalink
Add support for multiple builders per language definition
Browse files Browse the repository at this point in the history
  • Loading branch information
bweir committed Jul 26, 2016
1 parent 8c95c7b commit 6699865
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 12 deletions.
55 changes: 49 additions & 6 deletions src/propelleride/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,26 @@ void Language::load(QString name, QString filename)
_lookup[ext] = name;
}

foreach (QVariant stepvar, lang["buildsteps"].toArray().toVariantList())
data.builder = 0;

foreach (QVariant steplistvar, lang["buildsteps"].toArray().toVariantList())
{
data.buildsteps << stepvar.toString();
QStringList steplist = steplistvar.toStringList();
QStringList buildsteps;

foreach (QString s, steplist)
{
buildsteps << s;
}

data.buildsteps << buildsteps;
}

qDebug() << "Loading language definition:"
<< qPrintable(data.name)
<< data.extensions;
// << data.buildsteps;
qDebug() << "Loading language definition:" << qPrintable(data.name);
qDebug() << " Extensions: " << data.extensions;
qDebug() << " Build steps:";
foreach (QStringList sl, data.buildsteps)
qDebug() << " " << sl;

data.includes = lang["includes"].toBool();

Expand Down Expand Up @@ -273,7 +284,39 @@ ProjectParser * Language::parser()
return language().parser;
}


int Language::builder()
{
return language().builder;
}

void Language::setBuilder(int index)
{
if (!_data.contains(_language))
return;

if (!builders())
_data[_language].builder = -1;

if (index < 0)
_data[_language].builder = 0;
else if (index > builders()-1)
_data[_language].builder = builders()-1;
else
_data[_language].builder = index;
}

int Language::builders()
{
return language().buildsteps.size();
}

QStringList Language::listBuildSteps()
{
return language().buildsteps[language().builder];
}

QList<QStringList> Language::listAllBuildSteps()
{
return language().buildsteps;
}
Expand Down
10 changes: 9 additions & 1 deletion src/propelleride/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ class LanguageData
case_sensitive = false;
enable_blocks = false;
includes = false;
builder = -1;
}

QString name;
QStringList extensions;
QStringList buildsteps;

int builder;
QList<QStringList> buildsteps;

ProjectParser * parser;

Expand Down Expand Up @@ -67,7 +70,12 @@ class Language
QStringList extensions();
ProjectParser * parser();

int builder();
void setBuilder(int index);
int builders();
QStringList listBuildSteps();
QList<QStringList> listAllBuildSteps();

QStringList listKeywords();
QStringList listOperators();
QStringList listNumbers();
Expand Down
4 changes: 3 additions & 1 deletion src/propelleride/languages/c.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "C",
"extension": [ "c", "h", "cpp", "hpp" ],
"buildsteps": [ ],
"buildsteps": [
[ ]
],
"includes": true,
"syntax": {
"case_sensitive": true,
Expand Down
4 changes: 3 additions & 1 deletion src/propelleride/languages/propbasic.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "PropBASIC",
"extension": [ "pbas", "plib" ],
"buildsteps": [ "propbasic", "bstc" ],
"buildsteps": [
[ "propbasic", "bstc" ]
],
"includes": false,
"syntax": {
"case_sensitive": false,
Expand Down
5 changes: 4 additions & 1 deletion src/propelleride/languages/spin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "Spin",
"extension": [ "spin" ],
"buildsteps": [ "bstc" ],
"buildsteps": [
[ "bstc" ],
[ "openspin" ]
],
"includes": true,
"syntax": {
"case_sensitive": false,
Expand Down
19 changes: 18 additions & 1 deletion src/propelleride/pathselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ PathSelector::PathSelector(QString languagekey,

ui.name->setText(language.name());
ui.compiler->clear();
ui.compiler->addItem(language.listBuildSteps().join(" > "));

foreach (QStringList buildsteps, language.listAllBuildSteps())
ui.compiler->addItem(buildsteps.join(" > "));

restore();

load();
save();

connect(ui.compiler, SIGNAL(currentIndexChanged(int)), this, SLOT(setBuildSteps(int)));
connect(ui.deletePath, SIGNAL(clicked()), this, SLOT(deletePath()));
connect(ui.addPath, SIGNAL(clicked()), this, SLOT(addPath()));
}
Expand Down Expand Up @@ -48,6 +51,12 @@ void PathSelector::setDefaultIncludes(QStringList paths)
defaultincludes = paths;
}

void PathSelector::setBuildSteps(int index)
{
language.setBuilder(index);
qDebug() << "COMPILER" << language.listBuildSteps();
}

void PathSelector::addPath()
{
int i = ui.includes->currentRow();
Expand Down Expand Up @@ -102,6 +111,7 @@ void PathSelector::save()
settings.beginGroup("Paths");
settings.beginGroup(language.key());

settings.setValue("builder",ui.compiler->currentIndex());
settings.setValue("includes",includes);

settings.endGroup();
Expand All @@ -114,6 +124,13 @@ void PathSelector::load()
settings.beginGroup("Paths");
settings.beginGroup(language.key());

int builder = -1;
if (language.builders())
builder = settings.value("builder", 0).toInt();

ui.compiler->setCurrentIndex(builder);
language.setBuilder(builder);

QStringList inc = settings.value("includes", defaultincludes).toStringList();
setIncludes(inc);

Expand Down
2 changes: 1 addition & 1 deletion src/propelleride/pathselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PathSelector : public QWidget
private slots:
void setIncludes(const QStringList & paths);

void setBuildSteps(int index);
void addPath();
void deletePath();

Expand All @@ -36,7 +37,6 @@ private slots:
QWidget * parent = 0);
~PathSelector();

void setDefaultCompiler(QString path);
void setDefaultIncludes(QStringList paths);

public slots:
Expand Down

0 comments on commit 6699865

Please sign in to comment.