Commit 0653d0b8 authored by Victor Yacovlev's avatar Victor Yacovlev

Implemented #kumir2-1579

parent 2b085e70
......@@ -206,6 +206,7 @@
"Must be a file name or empty string";"Должно быть имя файла или пустая строка";"";"";"";"";
"Must be a scalar constant";"Нельзя присвоить список значений";"";"";"";"";
"Must be a variable name";"Это не имя величины";"";"";"";"";
"Name conflict with modules: %1";"Конфликт имен с: %1";"";"";"";"";
"Name contains keyword";"Ключевое слово в имени";"";"";"";"";
"Name contains quotation symbol";"Имя содержит кавычку";"";"";"";"";
"Name does not match header";"Несоответствие имени с заголовком";"";"";"";"";
......
......@@ -1628,6 +1628,54 @@ void SyntaxAnalizer::parseImport(int str)
st.data[1]->error = _("No such module");
return;
}
const QStringList conflictNames = checkForConflictingNames(moduleToImport, st.mod);
if (conflictNames.size() > 0) {
st.data[1]->error = _("Name conflict with modules: %1",
conflictNames.join(", ")
);
moduleToImport->header.usedBy.removeAll(st.mod.toWeakRef());
return;
}
}
QStringList SyntaxAnalizer::checkForConflictingNames(const ModulePtr &moduleToCheck, const ModulePtr & parentModule) const
{
QSet<QString> result;
QStringList thisModuleNames;
Q_FOREACH(const AST::AlgorithmPtr & alg, moduleToCheck->header.algorhitms) {
thisModuleNames << alg->header.name;
}
Q_FOREACH(const AST::Type & type, moduleToCheck->header.types) {
thisModuleNames << type.name;
}
Q_FOREACH(const QString & nameToCheck, thisModuleNames) {
Q_FOREACH(const AST::ModulePtr & module, ast_->modules) {
bool moduleAvailable =
module->builtInID == 0xF0 ||
module->isEnabledFor(parentModule) ||
alwaysEnabledModules_.contains(module->header.name)
;
if (moduleAvailable && module != moduleToCheck) {
Q_FOREACH(const AST::AlgorithmPtr & alg, module->header.algorhitms) {
const QString & algName = alg->header.name;
if (algName == nameToCheck) {
result.insert(module->header.name);
break;
}
}
Q_FOREACH(const AST::Type & type, module->header.types) {
const QString & typeName = type.name;
if (typeName == nameToCheck) {
result.insert(module->header.name);
break;
}
}
}
}
}
return result.toList();
}
AST::ModulePtr SyntaxAnalizer::loadKodFile(const QString &name, QString &error)
......
......@@ -248,6 +248,8 @@ private /*methods*/:
}
static LexemPtr findLexemByType(const QList<LexemPtr> lxs, LexemType type);
QStringList checkForConflictingNames(const AST::ModulePtr & moduleToCheck, const ModulePtr & parentModule) const;
};
} // namespace KumirAnalizer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment