Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New structural generator [WIP] #1345

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ROBOTS_EV3_GENERATOR_BASE_EXPORT Ev3GeneratorFactory : public generatorBas
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName);

~Ev3GeneratorFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Ev3GeneratorCustomizer::Ev3GeneratorCustomizer(const qrRepo::RepoApi &repo
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName
, bool supportsSwitchUnstableToBreaks)
: mFactory(repo, errorReporter, robotModelManager, luaProcessor, generatorName)
: mFactory(repo, errorReporter, robotModelManager, luaProcessor, readableLabelManager, generatorName)
, mSupportsSwitchUnstableToBreaks(supportsSwitchUnstableToBreaks)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Ev3GeneratorCustomizer : public generatorBase::GeneratorCustomizer
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName
, bool supportsSwitchUnstableToBreaks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ Ev3GeneratorFactory::Ev3GeneratorFactory(const qrRepo::RepoApi &repo
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName)
: GeneratorFactoryBase(repo, errorReporter, robotModelManager, luaProcessor)
: GeneratorFactoryBase(repo, errorReporter, robotModelManager, luaProcessor, readableLabelManager)
, mGeneratorName(generatorName)
, mMailboxes({":/" + mGeneratorName + "/templates"})
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Ev3MasterGeneratorBase::Ev3MasterGeneratorBase(const qrRepo::RepoApi &repo

generatorBase::GeneratorCustomizer *Ev3MasterGeneratorBase::createCustomizer()
{
return new Ev3GeneratorCustomizer(mRepo, mErrorReporter, mRobotModelManager, *createLuaProcessor(),
mGeneratorName, supportsSwitchUnstableToBreaks());
return new Ev3GeneratorCustomizer(mRepo, mErrorReporter, mRobotModelManager, *createLuaProcessor()
, *mReadableLabelManager, mGeneratorName, supportsSwitchUnstableToBreaks());
}

void Ev3MasterGeneratorBase::beforeGeneration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Ev3RbfGeneratorCustomizer::Ev3RbfGeneratorCustomizer(const qrRepo::RepoApi &repo
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName
, bool supportsSwitchUnstableToBreaks)
: mFactory(repo, errorReporter, robotModelManager, luaProcessor, generatorName)
: mFactory(repo, errorReporter, robotModelManager, luaProcessor, readableLabelManager, generatorName)
, mSupportsSwitchUnstableToBreaks(supportsSwitchUnstableToBreaks)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Ev3RbfGeneratorCustomizer : public generatorBase::GeneratorCustomizer
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName
, bool supportsSwitchUnstableToBreaks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Ev3RbfGeneratorFactory::Ev3RbfGeneratorFactory(const qrRepo::RepoApi &repo
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName)
: Ev3GeneratorFactory(repo, errorReporter, robotModelManager, luaProcessor, generatorName)
: Ev3GeneratorFactory(repo, errorReporter, robotModelManager, luaProcessor, readableLabelManager, generatorName)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Ev3RbfGeneratorFactory : public Ev3GeneratorFactory
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, generatorBase::lua::LuaProcessor &luaProcessor
, generatorBase::ReadableLabelManager &readableLabelManager
, const QString &generatorName);

generatorBase::simple::AbstractSimpleGenerator *labelGenerator(const qReal::Id &id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ generatorBase::lua::LuaProcessor *Ev3RbfMasterGenerator::createLuaProcessor()
GeneratorCustomizer *Ev3RbfMasterGenerator::createCustomizer()
{
return new Ev3RbfGeneratorCustomizer(mRepo, mErrorReporter
, mRobotModelManager, *createLuaProcessor(), mGeneratorName, supportsSwitchUnstableToBreaks());
, mRobotModelManager, *createLuaProcessor(), *mReadableLabelManager, mGeneratorName, supportsSwitchUnstableToBreaks());
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file>templates/beep.t</file>
<file>templates/break.t</file>
<file>templates/continue.t</file>
<file>templates/pass.t</file>
<file>templates/initialNode.t</file>
<file>templates/finalNodeMain.t</file>
<file>templates/finalNodeSubprogram.t</file>
Expand Down
Empty file.
46 changes: 26 additions & 20 deletions plugins/robots/generators/generatorBase/generatorBase.pri
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,44 @@ HEADERS += \
$$PWD/include/generatorBase/lua/reservedFunctionsConverter.h \
$$PWD/include/generatorBase/gotoControlFlowGenerator.h \
$$PWD/src/converters/dynamicPropertiesConverter.h \
$$PWD/src/readableLabelManager.h \
$$PWD/src/simpleGenerators/passGenerator.h \
$$PWD/src/simpleGenerators/syntheticIfGenerator.h \
$$PWD/src/simpleGenerators/syntheticVariableNameGenerator.h \
$$PWD/src/structuralControlFlowGenerator.h \
$$PWD/src/structurizator.h \
$$PWD/src/structurizer.h \
$$PWD/src/structurizerNodes/breakStructurizerNode.h \
$$PWD/src/structurizerNodes/continuationStructurizerNode.h \
$$PWD/src/structurizerNodes/ifStructurizerNode.h \
$$PWD/src/structurizerNodes/loopStructurizerNode.h \
$$PWD/src/structurizerNodes/sequenceStructurizerNode.h \
$$PWD/src/structurizerNodes/simpleStructurizerNode.h \
$$PWD/src/structurizerNodes/structurizerNode.h \
$$PWD/src/structurizerNodes/switchStructurizerNode.h \

HEADERS += \
$$PWD/src/structurizatorNodes/intermediateStructurizatorNode.h \
$$PWD/src/structurizatorNodes/simpleStructurizatorNode.h \
$$PWD/src/structurizatorNodes/breakStructurizatorNode.h \
$$PWD/src/structurizatorNodes/ifStructurizatorNode.h \
$$PWD/src/structurizatorNodes/structurizatorNodeWithBreaks.h \
$$PWD/src/structurizatorNodes/switchStructurizatorNode.h \
$$PWD/src/structurizatorNodes/blockStructurizatorNode.h \
$$PWD/src/structurizatorNodes/whileStructurizatorNode.h \
$$PWD/src/structurizatorNodes/selfLoopStructurizatorNode.h \


SOURCES += \
$$PWD/src/readableLabelManager.cpp \
$$PWD/src/robotsGeneratorPluginBase.cpp \
$$PWD/src/masterGeneratorBase.cpp \
$$PWD/src/generatorCustomizer.cpp \
$$PWD/src/controlFlowGeneratorBase.cpp \
$$PWD/src/robotsDiagramVisitor.cpp \
$$PWD/src/primaryControlFlowValidator.cpp \
$$PWD/src/generatorFactoryBase.cpp \
$$PWD/src/simpleGenerators/passGenerator.cpp \
$$PWD/src/simpleGenerators/syntheticIfGenerator.cpp \
$$PWD/src/simpleGenerators/syntheticVariableNameGenerator.cpp \
$$PWD/src/structurizerNodes/breakStructurizerNode.cpp \
$$PWD/src/structurizerNodes/continuationStructurizerNode.cpp \
$$PWD/src/structurizerNodes/ifStructurizerNode.cpp \
$$PWD/src/structurizerNodes/loopStructurizerNode.cpp \
$$PWD/src/structurizerNodes/sequenceStructurizerNode.cpp \
$$PWD/src/structurizerNodes/simpleStructurizerNode.cpp \
$$PWD/src/structurizerNodes/structurizerNode.cpp \
$$PWD/src/structurizerNodes/switchStructurizerNode.cpp \
$$PWD/src/templateParametrizedEntity.cpp \
$$PWD/src/parts/variables.cpp \
$$PWD/src/parts/subprograms.cpp \
Expand All @@ -113,7 +128,7 @@ SOURCES += \
$$PWD/src/gotoControlFlowGenerator.cpp \
$$PWD/src/converters/dynamicPropertiesConverter.cpp \
$$PWD/src/structuralControlFlowGenerator.cpp \
$$PWD/src/structurizator.cpp \
$$PWD/src/structurizer.cpp \

# Simple element generators & converters

Expand Down Expand Up @@ -253,12 +268,3 @@ SOURCES += \
$$PWD/src/lua/precedenceConverter.cpp \

SOURCES += \
$$PWD/src/structurizatorNodes/intermediateStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/simpleStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/breakStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/ifStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/structurizatorNodeWithBreaks.cpp \
$$PWD/src/structurizatorNodes/switchStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/blockStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/whileStructurizatorNode.cpp \
$$PWD/src/structurizatorNodes/selfLoopStructurizatorNode.cpp \
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class LuaProcessor;
}

class GeneratorCustomizer;
class ReadableLabelManager;

/// This class must be inherited in each concrete generator. Implementation
/// must specify every generator part (starting from simple block generators
Expand All @@ -53,7 +54,8 @@ class ROBOTS_GENERATOR_EXPORT GeneratorFactoryBase : public QObject
GeneratorFactoryBase(const qrRepo::RepoApi &repo
, qReal::ErrorReporterInterface &errorReporter
, const kitBase::robotModel::RobotModelManagerInterface &robotModelManager
, lua::LuaProcessor &luaProcessor);
, lua::LuaProcessor &luaProcessor
, ReadableLabelManager &readableLabelManager);

virtual ~GeneratorFactoryBase();

Expand Down Expand Up @@ -97,6 +99,14 @@ class ROBOTS_GENERATOR_EXPORT GeneratorFactoryBase : public QObject
, bool elseIsEmpty
, bool needInverting);

/// Returns a pointer to a code generator for blocks with if semantics
virtual simple::AbstractSimpleGenerator *syntheticIfGenerator(const qReal::Id &id
, const QMap<qReal::Id, bool> &ids
, GeneratorCustomizer &customizer
, bool elseIsEmpty
, QString syntheticCondition
, bool needInverting);

/// Returns a pointer to a code generator for infinite loops
virtual simple::AbstractSimpleGenerator *infiniteLoopGenerator(const qReal::Id &id
, GeneratorCustomizer &customizer);
Expand Down Expand Up @@ -143,10 +153,18 @@ class ROBOTS_GENERATOR_EXPORT GeneratorFactoryBase : public QObject
virtual simple::AbstractSimpleGenerator *continueGenerator(const qReal::Id &id
, GeneratorCustomizer &customizer);

/// Returns a pointer to a code generator for 'pass' instruction
virtual simple::AbstractSimpleGenerator *passGenerator(const qReal::Id &id
, GeneratorCustomizer &customizer);

/// Returns a pointer to a code generator for goto label declaration
virtual simple::AbstractSimpleGenerator *labelGenerator(const qReal::Id &id
, GeneratorCustomizer &customizer);

/// Returns a pointer to a code generator for goto label declaration
virtual simple::AbstractSimpleGenerator *syntheticVariableNameGenerator(const qReal::Id &id
, GeneratorCustomizer &customizer);

/// Returns a pointer to a code generator for 'goto' instruction
virtual simple::AbstractSimpleGenerator *gotoSimpleGenerator(const qReal::Id &id
, GeneratorCustomizer &customizer);
Expand Down Expand Up @@ -276,6 +294,7 @@ class ROBOTS_GENERATOR_EXPORT GeneratorFactoryBase : public QObject
QScopedPointer<parts::Sensors> mSensors;
QScopedPointer<parts::Functions> mFunctions;
QScopedPointer<parts::DeviceVariables> mDeviceVariables;
ReadableLabelManager &mReadableLabelManager;
int mLoopGeneratorIndex { 0 };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "templateParametrizedEntity.h"
#include "primaryControlFlowValidator.h"

#include "src/readableLabelManager.h"

class QFileInfo;

namespace utils {
Expand Down Expand Up @@ -114,6 +116,9 @@ class ROBOTS_GENERATOR_EXPORT MasterGeneratorBase : public QObject, public Templ
QString mProjectDir;
int mCurInitialNodeNumber {};
const utils::ParserErrorReporter &mParserErrorReporter;

/// Storage and generator for human-readable goto labels.
QScopedPointer<ReadableLabelManager> mReadableLabelManager;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ class ROBOTS_GENERATOR_EXPORT IfNode : public ConditionalNode
{
public:
explicit IfNode(const qReal::Id &idBinded, QObject *parent = nullptr);
explicit IfNode(QObject *parent = nullptr);

ZoneNode *thenZone();
ZoneNode *elseZone();

/// Will be called when both branches link to same block, making thus if statement unnesesary.
void transformToSimple();

void setSyntheticCondition(const QString &s, const QMap<qReal::Id, bool> &l);

protected:
QLinkedList<SemanticNode *> children() const override;
QString toStringImpl(GeneratorCustomizer &customizer, int indent, const QString &indentString) const override;

private:
void init();

ZoneNode *mThenZone; // Takes ownership
ZoneNode *mElseZone; // Takes ownership
bool mIsSimple;
bool mIsSimple {false};
bool mIsSynthetic;
QString mSyntheticCondition;
QMap<qReal::Id, bool> mIdWasUsedBefore;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ROBOTS_GENERATOR_EXPORT SimpleNode : public NonZoneNode
, breakNode
, continueNode
, gotoNode
, tempVariableNode
, passNode
};

explicit SimpleNode(const qReal::Id &idBinded, QObject *parent = nullptr);
Expand All @@ -41,6 +43,9 @@ class ROBOTS_GENERATOR_EXPORT SimpleNode : public NonZoneNode
void bindToSyntheticConstruction(SyntheticBlockType type);

static SimpleNode *createBreakNode(QObject *parent);
static SimpleNode *createPassNode(QObject *parent);
static SimpleNode *createSyntheticVariableNode(const qReal::Id &id, QObject *parent);

protected:
QLinkedList<SemanticNode *> children() const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class ROBOTS_GENERATOR_EXPORT SwitchNode : public NonZoneNode
explicit SwitchNode(const qReal::Id &idBinded, QObject *parent = nullptr);

/// Adds new branch for the switch value (i.e. branch zone will be created for the given value).
void addBranch(const QString &value, SemanticNode * const node);
void addBranch(const QString &value);

/// Binds existing branch with the switch value (i.e. value will be binded with the parent zone of the node).
void mergeBranch(const QString &value, NonZoneNode * const node);
/// Binds existing branch with the switch value (i.e. value will be binded with zone node of the branch).
void mergeBranch(const QString &value, ZoneNode * const zone);

/// Returns true if branches for this switch block were already merged.
/// This can help to resolve confusion in case when one branch enter into the middle of another.
Expand All @@ -43,6 +43,9 @@ class ROBOTS_GENERATOR_EXPORT SwitchNode : public NonZoneNode

void setGenerateIfs();

/// Returns branch zone node by guard value.
ZoneNode *branchZoneByValue(const QString &value);

protected:
QLinkedList<SemanticNode *> children() const override;
QString toStringImpl(GeneratorCustomizer &customizer, int indent, const QString &indentString) const override;
Expand Down
Loading