Commit 9af87b86 authored by Alexander A. Maly's avatar Alexander A. Maly

Astyled widgets

parent 4aa5e175
Pipeline #2435 passed with stages
in 3 minutes and 48 seconds
......@@ -2,6 +2,7 @@
#define GUIINTERFACE_H
#include <QtPlugin>
#include <QDateTime>
#include "kumir2/analizer_sourcefileinterface.h"
namespace Shared
......
......@@ -3,6 +3,7 @@
#include "ast_module.h"
#include <QtGlobal>
#include <QDateTime>
#undef ABSTRACTSYNTAXTREE_EXPORT
......
#include "ast_algorhitm.h"
#include <QtCore>
namespace AST {
namespace AST
{
Algorithm::Algorithm()
{
header.specialType = AlgorithmTypeRegular;
header.returnType.kind = TypeNone;
header.implType = AlgorhitmCompiled;
header.broken = false;
header.specialType = AlgorithmTypeRegular;
header.returnType.kind = TypeNone;
header.implType = AlgorhitmCompiled;
header.broken = false;
}
Algorithm::Algorithm(const AlgorithmPtr src)
{
header.specialType = src->header.specialType;
header.returnType = src->header.returnType;
header.implType = src->header.implType;
header.name = src->header.name;
header.error = src->header.error;
header.broken = src->header.broken;
header.specialType = src->header.specialType;
header.returnType = src->header.returnType;
header.implType = src->header.implType;
header.name = src->header.name;
header.error = src->header.error;
header.broken = src->header.broken;
for (int i=0; i<src->impl.locals.size(); i++) {
impl.locals << src->impl.locals[i];
}
for (int i=0; i<src->impl.pre.size(); i++) {
impl.pre << src->impl.pre[i];
}
for (int i=0; i<src->impl.post.size(); i++) {
impl.post << src->impl.post[i];
}
for (int i=0; i<src->impl.body.size(); i++) {
impl.body << src->impl.body[i];
}
for (int i = 0; i < src->impl.locals.size(); i++) {
impl.locals << src->impl.locals[i];
}
for (int i = 0; i < src->impl.pre.size(); i++) {
impl.pre << src->impl.pre[i];
}
for (int i = 0; i < src->impl.post.size(); i++) {
impl.post << src->impl.post[i];
}
for (int i = 0; i < src->impl.body.size(); i++) {
impl.body << src->impl.body[i];
}
}
void Algorithm::updateReferences(const Algorithm * src, const struct Data * srcData, const struct Data *data)
void Algorithm::updateReferences(const Algorithm *src, const struct Data *srcData, const struct Data *data)
{
for (int i=0; i<impl.locals.size(); i++) {
impl.locals[i]->updateReferences(src->impl.locals[i].data(), srcData, data);
}
for (int i=0; i<impl.pre.size(); i++) {
impl.pre[i]->updateReferences(src->impl.pre[i].data(), srcData, data);
}
for (int i=0; i<impl.post.size(); i++) {
impl.post[i]->updateReferences(src->impl.post[i].data(), srcData, data);
}
for (int i=0; i<impl.body.size(); i++) {
impl.body[i]->updateReferences(src->impl.body[i].data(), srcData, data);
}
for (int i = 0; i < impl.locals.size(); i++) {
impl.locals[i]->updateReferences(src->impl.locals[i].data(), srcData, data);
}
for (int i = 0; i < impl.pre.size(); i++) {
impl.pre[i]->updateReferences(src->impl.pre[i].data(), srcData, data);
}
for (int i = 0; i < impl.post.size(); i++) {
impl.post[i]->updateReferences(src->impl.post[i].data(), srcData, data);
}
for (int i = 0; i < impl.body.size(); i++) {
impl.body[i]->updateReferences(src->impl.body[i].data(), srcData, data);
}
for (int i=0; i<src->header.arguments.size(); i++) {
int index = -1;
for (int j=0; j<src->impl.locals.size(); j++) {
if (src->impl.locals[j]==src->header.arguments[i]) {
index = j;
break;
}
}
Q_ASSERT(index != -1);
header.arguments << impl.locals[index];
}
for (int i = 0; i < src->header.arguments.size(); i++) {
int index = -1;
for (int j = 0; j < src->impl.locals.size(); j++) {
if (src->impl.locals[j] == src->header.arguments[i]) {
index = j;
break;
}
}
Q_ASSERT(index != -1);
header.arguments << impl.locals[index];
}
}
} // namespace AST
}
#ifndef AST_ALGORHITM_H
#define AST_ALGORHITM_H
#include <QString>
#include <QList>
#include <QtGlobal>
#include "ast_variabletype.h"
#include "ast_statement.h"
#include "ast_variable.h"
#include "ast_type.h"
......@@ -18,7 +16,8 @@
#define ABSTRACTSYNTAXTREE_EXPORT Q_DECL_IMPORT
#endif
namespace AST {
namespace AST
{
typedef QSharedPointer<struct Algorithm> AlgorithmPtr;
......@@ -31,107 +30,107 @@ typedef QSharedPointer<struct Data> DataPtr;
/** Specific algorhitm types */
enum AlgorhitmType {
/** Regular algorhitm */
AlgorithmTypeRegular,
/** Regular algorhitm */
AlgorithmTypeRegular,
/** Available to write only by teacher */
AlgorithmTypeTeacher,
/** Available to write only by teacher */
AlgorithmTypeTeacher,
/** Testing mode entry point */
AlgorithmTypeTesting
/** Testing mode entry point */
AlgorithmTypeTesting
};
/** Algorhitm implementation type */
enum AlgorhitmImplementationType {
/** Kumir-compiled algorhitm */
AlgorhitmCompiled,
/** Kumir-compiled algorhitm */
AlgorhitmCompiled,
/** External or builtin algorhitm */
AlgorhitmExternal
/** External or builtin algorhitm */
AlgorhitmExternal
};
/** External reference for out-of module algorhitm */
struct AlgorhitmExternalReference {
QString moduleName;
QByteArray moduleAsciiName;
QByteArray algorithmAsciiName;
quint16 id;
QString moduleName;
QByteArray moduleAsciiName;
QByteArray algorithmAsciiName;
quint16 id;
};
/** Algorhitm public header */
struct AlgorhitmHeader {
/** Algorhitm name, may be empty (for first algorhitm) */
QString name;
/** Algorhitm name, may be empty (for first algorhitm) */
QString name;
/** Algorhitm special type */
enum AlgorhitmType specialType;
/** Algorhitm special type */
enum AlgorhitmType specialType;
/** Algorhitm implementation type*/
enum AlgorhitmImplementationType implType;
/** Algorhitm implementation type*/
enum AlgorhitmImplementationType implType;
/** Algorhitm external reference, if defined */
struct AlgorhitmExternalReference external;
/** Algorhitm external reference, if defined */
struct AlgorhitmExternalReference external;
/** Return type */
Type returnType;
/** Return type */
Type returnType;
/** Formal arguments, represented as
* references to corresponding local variables */
QList<VariablePtr> arguments;
/** Formal arguments, represented as
* references to corresponding local variables */
QList<VariablePtr> arguments;
/** Not empty if algorhitm header contains error,
* but algorhitm name still reachable */
QString error;
/** Not empty if algorhitm header contains error,
* but algorhitm name still reachable */
QString error;
/** True if algorithm declaration wrong */
bool broken;
/** True if algorithm declaration wrong */
bool broken;
};
/** Algorhitm body (private to other components) */
struct AlgorhitmImplementation {
/** Local variables and constants table */
QList<VariablePtr> locals;
/** Local variables and constants table */
QList<VariablePtr> locals;
/** Statements of pre-condition block (russian: dano) */
QList<StatementPtr> pre;
/** Statements of pre-condition block (russian: dano) */
QList<StatementPtr> pre;
/** Statements of pre-condition block (russian: nado) */
QList<StatementPtr> post;
/** Statements of pre-condition block (russian: nado) */
QList<StatementPtr> post;
/** Statements of algorhitm body */
QList<StatementPtr> body;
/** Statements of algorhitm body */
QList<StatementPtr> body;
/** Header lexems */
QList<LexemPtr> headerLexems;
/** Header lexems */
QList<LexemPtr> headerLexems;
/** Begin lexems */
QList<LexemPtr> beginLexems;
/** Begin lexems */
QList<LexemPtr> beginLexems;
/** End lexems */
QList<LexemPtr> endLexems;
/** End lexems */
QList<LexemPtr> endLexems;
QString headerRuntimeError;
int headerRuntimeErrorLine;
QString headerRuntimeError;
int headerRuntimeErrorLine;
};
/** Algorhitm representation */
struct ABSTRACTSYNTAXTREE_EXPORT Algorithm {
/** Public header for use in module etc. */
struct AlgorhitmHeader header;
/** Public header for use in module etc. */
struct AlgorhitmHeader header;
/** Internal representation */
struct AlgorhitmImplementation impl;
/** Internal representation */
struct AlgorhitmImplementation impl;
explicit Algorithm();
explicit Algorithm(const AlgorithmPtr src);
void updateReferences(const Algorithm * src,
const struct Data * srcData,
const struct Data * data);
explicit Algorithm();
explicit Algorithm(const AlgorithmPtr src);
void updateReferences(const Algorithm *src,
const struct Data *srcData,
const struct Data *data);
};
......
#include "ast.h"
#include "ast_type.h"
#include "ast_module.h"
#include "ast_algorhitm.h"
#include "lexem.h"
#include <QtCore>
namespace AST {
namespace AST
{
Module::Module()
{
impl.firstLineNumber = impl.lastLineNumber = -1;
builtInID = 0;
header.type = ModTypeUser;
impl.firstLineNumber = impl.lastLineNumber = -1;
builtInID = 0;
header.type = ModTypeUser;
}
Module::Module(const ModulePtr src)
{
impl.firstLineNumber = src->impl.firstLineNumber;
impl.lastLineNumber = src->impl.lastLineNumber;
for (int i=0; i<src->impl.globals.size(); i++) {
impl.globals << src->impl.globals[i];
}
impl.firstLineNumber = src->impl.firstLineNumber;
impl.lastLineNumber = src->impl.lastLineNumber;
for (int i = 0; i < src->impl.globals.size(); i++) {
impl.globals << src->impl.globals[i];
}
for (int i=0; i<src->impl.algorhitms.size(); i++) {
impl.algorhitms << src->impl.algorhitms[i];
}
for (int i = 0; i < src->impl.algorhitms.size(); i++) {
impl.algorhitms << src->impl.algorhitms[i];
}
for (int i=0; i<src->impl.initializerBody.size(); i++) {
impl.initializerBody << src->impl.initializerBody[i];
}
for (int i = 0; i < src->impl.initializerBody.size(); i++) {
impl.initializerBody << src->impl.initializerBody[i];
}
header.type = src->header.type;
header.name = src->header.name;
header.types = src->header.types;
header.type = src->header.type;
header.name = src->header.name;
header.types = src->header.types;
}
void Module::updateReferences(const Module * src, const Data* srcData, const Data* data)
void Module::updateReferences(const Module *src, const Data *srcData, const Data *data)
{
for (int i=0; i<impl.globals.size(); i++) {
impl.globals[i]->updateReferences(src->impl.globals[i].data(), srcData, data);
}
for (int i=0; i<impl.algorhitms.size(); i++) {
impl.algorhitms[i]->updateReferences(src->impl.algorhitms[i].data(), srcData, data);
}
for (int i=0; i<impl.initializerBody.size(); i++) {
impl.initializerBody[i]->updateReferences(src->impl.initializerBody[i].data(), srcData, data);
}
if (header.type==ModTypeExternal) {
header.algorhitms = src->header.algorhitms;
}
else {
for (int i=0; i<src->header.algorhitms.size(); i++) {
int index = -1;
for (int j=0; j<src->impl.algorhitms.size(); j++) {
if (src->impl.algorhitms[j]==src->header.algorhitms[i]) {
index = j;
break;
}
}
Q_ASSERT(index != -1);
header.algorhitms << impl.algorhitms[index];
}
}
for (int i = 0; i < impl.globals.size(); i++) {
impl.globals[i]->updateReferences(src->impl.globals[i].data(), srcData, data);
}
for (int i = 0; i < impl.algorhitms.size(); i++) {
impl.algorhitms[i]->updateReferences(src->impl.algorhitms[i].data(), srcData, data);
}
for (int i = 0; i < impl.initializerBody.size(); i++) {
impl.initializerBody[i]->updateReferences(src->impl.initializerBody[i].data(), srcData, data);
}
if (header.type == ModTypeExternal) {
header.algorhitms = src->header.algorhitms;
} else {
for (int i = 0; i < src->header.algorhitms.size(); i++) {
int index = -1;
for (int j = 0; j < src->impl.algorhitms.size(); j++) {
if (src->impl.algorhitms[j] == src->header.algorhitms[i]) {
index = j;
break;
}
}
Q_ASSERT(index != -1);
header.algorhitms << impl.algorhitms[index];
}
}
}
bool Module::isEnabledFor(const ModulePtr currentModule) const
{
if (!currentModule)
return false;
if (header.type == ModTypeUser)
return true;
if (builtInID == 0xF0) // Standard library module
return true;
if (currentModule->header.type == ModTypeTeacher || currentModule->header.type == ModTypeTeacherMain) {
if (header.type == ModTypeUser)
return true;
if (header.type == ModTypeExternal) {
foreach (AST::ModuleWPtr reference, header.usedBy) {
bool usedByUserMainModule =
reference &&
reference.data()->header.type == ModTypeUserMain;
if (usedByUserMainModule)
return true;
}
}
}
if (!currentModule) {
return false;
}
if (header.type == ModTypeUser) {
return true;
}
if (builtInID == 0xF0) { // Standard library module
return true;
}
if (currentModule->header.type == ModTypeTeacher || currentModule->header.type == ModTypeTeacherMain) {
if (header.type == ModTypeUser) {
return true;
}
if (header.type == ModTypeExternal) {
foreach (AST::ModuleWPtr reference, header.usedBy) {
bool usedByUserMainModule =
reference &&
reference.data()->header.type == ModTypeUserMain;
if (usedByUserMainModule) {
return true;
}
}
}
}
bool enabled = currentModule.data() == this;
if (!enabled) {
foreach (AST::ModuleWPtr reference, header.usedBy) {
if (reference && currentModule && reference.data()==currentModule.data()) {
enabled = true;
break;
}
}
}
return enabled;
bool enabled = currentModule.data() == this;
if (!enabled) {
foreach (AST::ModuleWPtr reference, header.usedBy) {
if (reference && currentModule && reference.data() == currentModule.data()) {
enabled = true;
break;
}
}
}
return enabled;
}
}
#ifndef AST_MODULE_TYPE_H
#define AST_MODULE_TYPE_H
#include <QString>
#include <QtGlobal>
#include <QPair>
#include <QList>
#include "ast_variabletype.h"
......
......@@ -49,6 +49,6 @@ enum VariableAccessType {
};
}
} // namespace AST
#endif // AST_VARIABLETYPE_H
#include "kumfile.h"
#include <kumir2/analizer_sourcefileinterface.h>
#include <QRegExp>
#include <QStringList>
#include <QDebug>
//#if !defined(HAS_QCA) && defined(Q_OS_LINUX)
//# define HAS_QCA
//#endif
#ifdef HAS_QCA
# include <QtCrypto/qca.h>
#endif
Shared::Analizer::SourceFileInterface::Data KumFile::insertTeacherMark(Shared::Analizer::SourceFileInterface::Data & data)//Inserts |#%% if needed.
{
static const QRegExp teacherMark("(^|\\n)\\|#%%");
if(data.visibleText.indexOf(teacherMark)>-1)
{
//qDebug()<<" TM POS:"<<data.visibleText.indexOf("\n|#%%");
return data;
};
if(data.hiddenText.indexOf(teacherMark)>-1)
{ // qDebug()<<" TM POS:"<<data.visibleText.indexOf("\n|#%%");
return data;
};
// static const QRegExp speclAlg(QString::fromUtf8("^\\s*алг\\s*(\\S\\S\\S)?\\s+@"));
static const QRegExp speclAlg(QString::fromUtf8("^|\\s*алг\\s*(\\S\\S\\S)?\\s*@"));
Shared::Analizer::SFData KumFile::insertTeacherMark(
Shared::Analizer::SFData &data
) { //Inserts |#%% if needed.
static const QRegExp teacherMark("(^|\\n)\\|#%%");
if (data.visibleText.indexOf(teacherMark) > -1) {
//qDebug()<<" TM POS:"<<data.visibleText.indexOf("\n|#%%");
return data;
};
if (data.hiddenText.indexOf(teacherMark) > -1) {
// qDebug()<<" TM POS:"<<data.visibleText.indexOf("\n|#%%");