Commit 026b6814 authored by Alexander A. Maly's avatar Alexander A. Maly

Astyled some interfaces in include/kumir2

And some depended files in other directories.
parent c4e0c324
Pipeline #2323 failed with stages
in 1 minute and 47 seconds
......@@ -2,67 +2,80 @@
#define ANALIZER_SOURCEFILEINTERFACE_H
#include <QtCore>
#include <QtPlugin>
namespace Shared { namespace Analizer {
namespace Shared
{
class SourceFileInterface {
namespace Analizer
{
class SourceFileInterface
{
public /*types*/:
struct Data
{
QString visibleText;
QSet<int> protectedLineNumbers;
QString hiddenText;
bool hasHiddenText;
QString sourceEncoding;
QByteArray hiddenTextSignature;
QString canonicalSourceLanguageName; // the same as file suffix after '.'
QUrl sourceUrl;
};
struct Data {
QString visibleText;
QSet<int> protectedLineNumbers;
QString hiddenText;
bool hasHiddenText;
QString sourceEncoding;
QByteArray hiddenTextSignature;
QString canonicalSourceLanguageName; // the same as file suffix after '.'
QUrl sourceUrl;
};
public /*methods*/:
// Abstract methods to read and write from/to string in language-specific way
// Abstract methods to read and write from/to string in language-specific way
virtual QString toString(const Data & data) const = 0;
virtual Data fromString(const QString & string) const = 0;
virtual QString toString(const Data &data) const = 0;
virtual Data fromString(const QString &string) const = 0;
// Generic methods to read and write from/to raw byte array. Default implementation
// assumes UTF-8 encoding with BOM mark, but it is possible to override
// Generic methods to read and write from/to raw byte array. Default implementation
// assumes UTF-8 encoding with BOM mark, but it is possible to override
inline virtual QByteArray toBytes(
const Data &data,
const QString &forceEncoding = ""
) const {
QByteArray buffer;
QTextStream stream(&buffer, QIODevice::WriteOnly);
if (forceEncoding.length() > 0) {
stream.setCodec(forceEncoding.toLatin1().constData());
} else {
stream.setCodec("UTF-8");
stream.setGenerateByteOrderMark(true);
}
stream << toString(data);
stream.flush();
return buffer;
}
inline virtual QByteArray toBytes(const Data & data, const QString & forceEncoding = "") const {
QByteArray buffer;
QTextStream stream(&buffer, QIODevice::WriteOnly);
if (forceEncoding.length() > 0)
stream.setCodec(forceEncoding.toLatin1().constData());
else {
stream.setCodec("UTF-8");
stream.setGenerateByteOrderMark(true);
}
stream << toString(data);
stream.flush();
return buffer;
}
inline virtual Data fromBytes(const QByteArray & bytes, const QString & forceEncoding = "") const {
QByteArray bytesCopy(bytes);
QTextStream stream(&bytesCopy);
if (forceEncoding.length() > 0)
stream.setCodec(forceEncoding.toLatin1().constData());
else {
stream.setCodec("UTF-8");
stream.setAutoDetectUnicode(true);
}
QString string = stream.readAll();
return fromString(string);
}
inline virtual Data fromBytes(
const QByteArray &bytes,
const QString &forceEncoding = ""
) const {
QByteArray bytesCopy(bytes);
QTextStream stream(&bytesCopy);
if (forceEncoding.length() > 0) {
stream.setCodec(forceEncoding.toLatin1().constData());
} else {
stream.setCodec("UTF-8");
stream.setAutoDetectUnicode(true);
}
QString string = stream.readAll();
return fromString(string);
}
};
}}
}
}
Q_DECLARE_INTERFACE(Shared::Analizer::SourceFileInterface,
"kumir2.Analizer.SourceFileInterface")
Q_DECLARE_INTERFACE(
Shared::Analizer::SourceFileInterface,
"kumir2.Analizer.SourceFileInterface"
)
#endif // ANALIZER_SOURCEFILEINTERFACE_H
#ifndef COURSESINTERFACE_H
#define COURSESINTERFACE_H
#include <QtCore>
#include <QWidget>
#include <QMenu>
#include <QtPlugin>
class QWidget;
class QAction;
class QMenu;
namespace Shared
{
class CoursesInterface
{
Q_ENUMS(ProgramRunStatus)
Q_ENUMS(ProgramRunStatus)
public:
enum ProgramRunStatus {
SuccessfullyFinished,
UserTerminated,
AbortedOnError
};
virtual QWidget* mainWindow() const = 0;
virtual QAction* actionPerformCheck() const = 0;
virtual QList<QMenu*> menus() const = 0;
inline virtual QStringList getListOfCourses() const { return QStringList(); }
inline virtual void activateCourseFromList(QString file) { Q_UNUSED(file); }
enum ProgramRunStatus {
SuccessfullyFinished,
UserTerminated,
AbortedOnError
};
virtual QWidget *mainWindow() const = 0;
virtual QAction *actionPerformCheck() const = 0;
virtual QList<QMenu *> menus() const = 0;
inline virtual QStringList getListOfCourses() const
{
return QStringList();
}
inline virtual void activateCourseFromList(QString file)
{
Q_UNUSED(file);
}
public slots:
virtual void setEnabled(bool value) = 0;
virtual void setTestingResult(ProgramRunStatus status, int value) = 0;
virtual void setEnabled(bool value) = 0;
virtual void setTestingResult(ProgramRunStatus status, int value) = 0;
};
}
......
#ifndef EDITOR_INTERFACE
#define EDITOR_INTERFACE
#include "analizerinterface.h"
#include "editor_instanceinterface.h"
#include "analizer_sourcefileinterface.h"
#include <kumir2-libs/dataformats/kumfile.h>
namespace Shared
{
namespace Editor {
class InstanceInterface;
}
class EditorInterface
{
public:
virtual QFont defaultEditorFont() const = 0;
virtual Editor::InstanceInterface * loadDocument(
QIODevice * device,
const QString & fileNameSuffix,
const QString & sourceEncoding,
const QUrl & sourceUrl, QString * error
) = 0;
virtual Editor::InstanceInterface * loadDocument(
const QString & fileName, QString * error) = 0;
virtual Editor::InstanceInterface * loadDocument(
const Analizer::SourceFileInterface::Data &data, QString * error) = 0;
virtual Editor::InstanceInterface * newDocument(
const QString & canonicalLanguageName = "",
const QString & documentDir = "") = 0;
virtual QFont defaultEditorFont() const = 0;
virtual Editor::InstanceInterface *loadDocument(
QIODevice *device,
const QString &fileNameSuffix,
const QString &sourceEncoding,
const QUrl &sourceUrl, QString *error
) = 0;
virtual Editor::InstanceInterface *loadDocument(
const QString &fileName, QString *error
) = 0;
virtual Editor::InstanceInterface *loadDocument(
const Analizer::SourceFileInterface::Data &data,
QString *error
) = 0;
virtual Editor::InstanceInterface *newDocument(
const QString &canonicalLanguageName = "",
const QString &documentDir = ""
) = 0;
};
}
......
......@@ -3,33 +3,35 @@
#include <kumir2-libs/dataformats/ast.h>
namespace Shared {
namespace Shared
{
class GeneratorInterface {
class GeneratorInterface
{
public:
enum DebugLevel {
NoDebug = 0,
LinesOnly = 1,
LinesAndVariables = 2
};
enum DebugLevel {
NoDebug = 0,
LinesOnly = 1,
LinesAndVariables = 2
};
/** Generates execuable by AST
* @param tree IN: abstract syntax tree
* @param out OUT: output buffer to write (if QFile - not opened state)
* @param mimeType OUT: MIME type of result
* @param fileSuffix OUT: suggested filename suffix for result
* @returns pair of string: first is error (or empty), second is mimetype
*/
virtual void setDebugLevel(DebugLevel debugLevel) = 0;
virtual void generateExecutable(
const AST::DataPtr tree,
QByteArray & out,
QString & mimeType,
QString & fileSuffix
) = 0;
virtual void setOutputToText(bool flag) = 0;
virtual void setVerbose(bool v) = 0;
virtual void setTemporaryDir(const QString & path, bool autoclean) = 0;
/** Generates execuable by AST
* @param tree IN: abstract syntax tree
* @param out OUT: output buffer to write (if QFile - not opened state)
* @param mimeType OUT: MIME type of result
* @param fileSuffix OUT: suggested filename suffix for result
* @returns pair of string: first is error (or empty), second is mimetype
*/
virtual void setDebugLevel(DebugLevel debugLevel) = 0;
virtual void generateExecutable(
const AST::DataPtr tree,
QByteArray &out,
QString &mimeType,
QString &fileSuffix
) = 0;
virtual void setOutputToText(bool flag) = 0;
virtual void setVerbose(bool v) = 0;
virtual void setTemporaryDir(const QString &path, bool autoclean) = 0;
};
}
......
#ifndef GUIINTERFACE_H
#define GUIINTERFACE_H
#include <kumir2-libs/dataformats/kumfile.h>
#include <QtCore>
#include <QWidget>
#include <QtPlugin>
#include <kumir2/analizer_sourcefileinterface.h>
namespace Shared
{
class GuiInterface
{
Q_ENUMS(Shared::GuiInterface::ProgramSourceText::Language)
Q_ENUMS(Shared::GuiInterface::ProgramSourceText::Language)
public:
struct ProgramSourceText {
enum Language { Kumir, Pascal, Python, etc = 255 };
Language language;
QDateTime saved;
QDateTime changed;
Shared::Analizer::SourceFileInterface::Data content;
QString title;
QUrl url;
};
public slots:
virtual QObject * pluginObject() = 0;
virtual QObject * mainWindowObject() = 0;
virtual void setProgramSource(const ProgramSourceText &source) = 0;
virtual ProgramSourceText programSource() const = 0;
virtual int overridenEditorFontSize() const = 0;
struct ProgramSourceText {
enum Language { Kumir, Pascal, Python, etc = 255 };
Language language;
QDateTime saved;
QDateTime changed;
Shared::Analizer::SourceFileInterface::Data content;
QString title;
QUrl url;
};
virtual void startTesting() = 0;
public slots:
virtual QObject *pluginObject() = 0;
virtual QObject *mainWindowObject() = 0;
virtual void setProgramSource(const ProgramSourceText &source) = 0;
virtual ProgramSourceText programSource() const = 0;
virtual int overridenEditorFontSize() const = 0;
virtual void startTesting() = 0;
};
}
Q_DECLARE_METATYPE(Shared::GuiInterface::ProgramSourceText)
Q_DECLARE_INTERFACE(Shared::GuiInterface, "kumir2.Gui")
#endif // GUIINTERFACE_H
#ifndef LEXEMTYPE_H
#define LEXEMTYPE_H
#include <QtCore>
#define LX_OFFSET_NAME = 0x00000003
#define LX_OFFSET_SECONDARY_KWD = 0x0000001F
#define LX_OFFSET_PRIMARY_KWD = 0x000007FF
#define LX_OFFSET_CONSTANT = 0x0001FFFF
#define LX_OFFSET_OPERATOR = 0x00100000
namespace Shared {
enum LexemType {
// Lexem type by bit mask
LxTypeEmpty = 0x00000000, // empty mask
LxTypeComment = 0x00000001, // bit 0
LxTypeDoc = 0x00000002, // bit 1
LxTypeName = 0x0000001C, // bits [2..4]
LxTypeSecondaryKwd = 0x000001E0, // bits [5..8]
LxTypePrimaryKwd = 0x0000F800, // bits [11..15]
LxTypeConstant = 0x000E0000, // bits [17..20]
LxTypeOperator = 0x01F00000, // bits [21..25]
LxTypeError = 0x80000000, // bit 31
// LxTypeName values
LxNameClass = 0x4,
LxNameVar = 0x8,
LxNameAlg = 0xc,
LxNameModule = 0x10,
// LxTypeSecondaryKwd values
LxSecFor = 0x20,
LxSecTimes = 0x40,
LxSecFrom = 0x60,
LxSecTo = 0x80,
LxSecStep = 0xa0,
LxSecWhile = 0xc0,
LxSecNewline = 0xe0,
LxSecIf = 0x100,
LxSecAnd = 0x120,
LxSecOr = 0x140,
LxSecNot = 0x160,
LxSecOut = 0x180,
LxSecIn = 0x1a0,
LxSecInout = 0x1c0,
LxSecCurrentStringLength = 0x1c1,
LxSecInclude = 0x1c2,
// LxTypePrimaryKwd values
LxPriModule = 0x800,
LxPriEndModule = 0x1000,
LxPriAlgHeader = 0x1800,
LxPriAlgBegin = 0x2000,
LxPriAlgEnd = 0x2800,
LxPriPre = 0x3000,
LxPriPost = 0x3800,
LxPriIf = 0x4000,
LxPriThen = 0x4800,
LxPriElse = 0x5000,
LxPriFi = 0x5800,
LxPriSwitch = 0x6000,
LxPriCase = 0x6800,
LxPriLoop = 0x7000,
LxPriEndLoop = 0x7800,
LxPriInput = 0x8000,
LxPriOutput = 0x8800,
LxPriAssign = 0xa000,
LxPriAssert = 0xa800,
LxPriImport = 0xb000,
LxPriExit = 0xc000,
LxPriPause = 0xc800,
LxPriHalt = 0xd000,
// LxTypeConstant values
LxConstInteger = 0x20000,
LxConstReal = 0x40000,
LxConstBoolTrue = 0x60000,
LxConstBoolFalse = 0x80000,
LxConstLiteral = 0xa0000,
// LxTypeOperator values
LxOperPlus = 0x200000,
LxOperMinus = 0x400000,
LxOperEqual = 0x600000,
LxOperAsterisk = 0x800000,
LxOperSlash = 0xa00000,
LxOperPower = 0xc00000,
LxOperLeftBr = 0xe00000,
LxOperRightBr = 0x1000000,
LxOperLeftSqBr = 0x1200000,
LxOperRightSqBr = 0x1400000,
LxOperColon = 0x1600000,
LxOperComa = 0x1800000,
LxOperLess = 0x1a00000,
LxOperGreater = 0x1c00000,
LxOperLessOrEqual = 0x1e00000,
LxOperGreaterOrEqual = 0x2000000,
LxOperNotEqual = 0x2200000,
LxOperSemicolon = 0x2400000,
LxOperLeftBrace = 0x2600000,
LxOperRightBrace = 0x2800000,
LxOperBoolEqual = 0x3000000,
LxOperBoolNotEqual = 0x3200000
};
namespace Shared
{
enum LexemType {
// Lexem type by bit mask
LxTypeEmpty = 0x00000000, // empty mask
LxTypeComment = 0x00000001, // bit 0
LxTypeDoc = 0x00000002, // bit 1
LxTypeName = 0x0000001C, // bits [2..4]
LxTypeSecondaryKwd = 0x000001E0, // bits [5..8]
LxTypePrimaryKwd = 0x0000F800, // bits [11..15]
LxTypeConstant = 0x000E0000, // bits [17..20]
LxTypeOperator = 0x01F00000, // bits [21..25]
LxTypeError = 0x80000000, // bit 31
// LxTypeName values
LxNameClass = 0x4,
LxNameVar = 0x8,
LxNameAlg = 0xc,
LxNameModule = 0x10,
// LxTypeSecondaryKwd values
LxSecFor = 0x20,
LxSecTimes = 0x40,
LxSecFrom = 0x60,
LxSecTo = 0x80,
LxSecStep = 0xa0,
LxSecWhile = 0xc0,
LxSecNewline = 0xe0,
LxSecIf = 0x100,
LxSecAnd = 0x120,
LxSecOr = 0x140,
LxSecNot = 0x160,
LxSecOut = 0x180,
LxSecIn = 0x1a0,
LxSecInout = 0x1c0,
LxSecCurrentStringLength = 0x1c1,
LxSecInclude = 0x1c2,
// LxTypePrimaryKwd values
LxPriModule = 0x800,
LxPriEndModule = 0x1000,
LxPriAlgHeader = 0x1800,
LxPriAlgBegin = 0x2000,
LxPriAlgEnd = 0x2800,
LxPriPre = 0x3000,
LxPriPost = 0x3800,
LxPriIf = 0x4000,
LxPriThen = 0x4800,
LxPriElse = 0x5000,
LxPriFi = 0x5800,
LxPriSwitch = 0x6000,
LxPriCase = 0x6800,
LxPriLoop = 0x7000,
LxPriEndLoop = 0x7800,
LxPriInput = 0x8000,
LxPriOutput = 0x8800,
LxPriAssign = 0xa000,
LxPriAssert = 0xa800,
LxPriImport = 0xb000,
LxPriExit = 0xc000,
LxPriPause = 0xc800,
LxPriHalt = 0xd000,
// LxTypeConstant values
LxConstInteger = 0x20000,
LxConstReal = 0x40000,
LxConstBoolTrue = 0x60000,
LxConstBoolFalse = 0x80000,
LxConstLiteral = 0xa0000,
// LxTypeOperator values
LxOperPlus = 0x200000,
LxOperMinus = 0x400000,
LxOperEqual = 0x600000,
LxOperAsterisk = 0x800000,
LxOperSlash = 0xa00000,
LxOperPower = 0xc00000,
LxOperLeftBr = 0xe00000,
LxOperRightBr = 0x1000000,
LxOperLeftSqBr = 0x1200000,
LxOperRightSqBr = 0x1400000,
LxOperColon = 0x1600000,
LxOperComa = 0x1800000,
LxOperLess = 0x1a00000,
LxOperGreater = 0x1c00000,
LxOperLessOrEqual = 0x1e00000,
LxOperGreaterOrEqual = 0x2000000,
LxOperNotEqual = 0x2200000,
LxOperSemicolon = 0x2400000,
LxOperLeftBrace = 0x2600000,
LxOperRightBrace = 0x2800000,
LxOperBoolEqual = 0x3000000,
LxOperBoolNotEqual = 0x3200000
};
}
#endif // LEXEMTYPE_H