X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/8f0bedf735fe2b306c11c3f4a168245a05e37ccd..14cd6d834ab531525a51c6a6992583b3e9143e02:/BlockImplementation.cpp diff --git a/BlockImplementation.cpp b/BlockImplementation.cpp index 23ec8bc..365ccb7 100644 --- a/BlockImplementation.cpp +++ b/BlockImplementation.cpp @@ -110,217 +110,6 @@ bool BlockImplementation::checkPatterns() { return true; } -QString BlockImplementation::eval(QString line, QTextStream& out) { - QString res, s, begLine, endLine, expr; - evaluator->setExpression(line); - QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)"); - QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)"); - QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*"); - - int nbAt = line.count('@'); - while(nbAt != 0) { - for(int i = 0; i < line.size(); i++) { - if(rxString->indexIn(line)) { - begLine = rxString->cap(1); - s = rxString->cap(2); - endLine = rxString->cap(3); - res = begLine + evalString(s) + endLine + '\n'; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxValue->indexIn(line)) { - begLine = rxValue->cap(1); - s = rxValue->cap(2); - endLine = rxValue->cap(3); - res = begLine + evalValue(s) + endLine + '\n'; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxExpr->indexIn(line)) { - expr = rxExpr->cap(1); - if(expr.count('@') == 0) { - evaluator->setExpression(expr); - s = QString::number(evaluator->evaluate()); - } - res = begLine + s + endLine + '\n'; - nbAt --; - } - } - } - return res; -} - -QString BlockImplementation::evalComplex(QString line, int id) { - QString res, s, begLine, endLine, expr; - QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)"); - QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)"); - QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*"); - QRegExp *rxFor = new QRegExp("@foreach{.*}(@{.*})(.*)@endforeach"); - QRegExp *rxCase = new QRegExp("@caseeach{.*,(.*),(.*)}(@{.*})(.*)@endcaseeach"); - QRegExp *rxCaseDown = new QRegExp("@#-:(.*)"); - QRegExp *rxCaseUp = new QRegExp("@#:(.*)"); - evaluator->setExpression(line); - - int nbAt = line.count('@') - 2; - while(nbAt != 0) { - for(int i = 0; i < line.size(); i++) { - if(rxString->indexIn(line)) { - begLine = rxString->cap(1); - s = rxString->cap(2); - endLine = rxString->cap(3); - if(evalStringComplex(s)->size() == 0) - line = begLine + evalString(s) + endLine; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxValue->indexIn(line)) { - begLine = rxValue->cap(1); - s = rxValue->cap(2); - endLine = rxValue->cap(3); - line = begLine + evalValue(s) + endLine; - nbAt --; - } - } - for(int i = 0; i < line.size(); i++) { - if(rxExpr->indexIn(line)) { - expr = rxExpr->cap(1); - if(expr.count('@') == 0) { - evaluator->setExpression(expr); - s = QString::number(evaluator->evaluate()); - } - res = begLine + s + endLine + '\n'; - nbAt --; - } - } - } - - if(id == 1) { - if(rxFor->indexIn(line)) { - QString intName, instruc; - intName = rxFor->cap(1); - instruc = rxFor->cap(2); - QList *intList = evalStringComplex(intName); - if(intList->size() != 0) { - for(int i = 0; i < intList->size(); i++) { - res = intList->at(i)->getName() + instruc + '\n'; - } - } - } - } - - else if(id == 2) { - if(rxCase->indexIn(line)) { - QString intName, sigName, cases, instruc; - int number; - sigName = rxCase->cap(1); - cases = rxCase->cap(2); - intName = rxCase->cap(3); - instruc = rxCase->cap(4); - QList *intList = evalStringComplex(intName); - int listSize = intList->count(); - res = "case " + sigName + " is\n"; - if(rxCaseUp->indexIn(cases)) { - number = rxCaseUp->cap(1).toInt(); - for(int j = number; j < listSize; j++) { - if(listSize > 0) { - for(int i = 0; i < listSize; i++) { - res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n"; - } - } - else - res += "\twhen " + number + ' ' + intName + instruc + "\n"; - number++; - } - } - if(rxCaseDown->indexIn(cases)) { - number = rxCaseDown->cap(1).toInt(); - for(int j = number; j < listSize; j++) { - if(listSize > 0) { - for(int i = 0; i < listSize; i++) { - res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n"; - } - } - else - res += "\twhen " + number + ' ' + intName + instruc + "\n"; - number--; - } - res += "end case ;\n"; - } - } - } - return res; -} - -QString BlockImplementation::evalString(QString s) { - - QString name = getIfaceUserName(block->AbstractBlock::getIfaceFromName(s)); - return name; -} - -QList* BlockImplementation::evalStringComplex(QString s) { - - int j = 0; - QList *listInterfaces = new QList(); - AbstractInterface *inter = block->AbstractBlock::getIfaceFromName(s); - QList listIntBlock = block->getInterfaces(); - for(int i = 0; i < listIntBlock.size(); i++) { - if(inter->getName().compare(listIntBlock.at(i)->getName()) < -1) { - listInterfaces->insert(j, inter); - j ++; - } - } - return listInterfaces; -} - -QString BlockImplementation::evalValue(QString s) { - - QString val = ""; - if(paramMap.contains(s)) - val = paramMap.value(s); - return val; -} - -QString BlockImplementation::getIfaceUserName(AbstractInterface* refIface) { - - if (! refIface->isReferenceInterface()) return ""; - - AbstractInterface* funcIface = NULL; - - if (refIface->getDirection() == AbstractInterface::Input) { - foreach(AbstractInterface* iface, block->getInputs()) { - FunctionalInterface* fi = (FunctionalInterface*)iface; - if (fi->getReference() == refIface) { - funcIface = iface; - break; - } - } - } - else if (refIface->getDirection() == AbstractInterface::Output) { - foreach(AbstractInterface* iface, block->getOutputs()) { - FunctionalInterface* fi = (FunctionalInterface*)iface; - if (fi->getReference() == refIface) { - funcIface = iface; - break; - } - } - } - else if (refIface->getDirection() == AbstractInterface::InOut) { - foreach(AbstractInterface* iface, block->getBidirs()) { - FunctionalInterface* fi = (FunctionalInterface*)iface; - if (fi->getReference() == refIface) { - funcIface = iface; - break; - } - } - } - if (funcIface == NULL) return ""; - - return funcIface->getName(); -} - QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) { out.setVersion(QDataStream::Qt_5_0); @@ -331,6 +120,7 @@ QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) { toWrite << impl.xmlFile; toWrite << impl.referenceXml; toWrite << impl.referenceMd5; + toWrite << impl.resources; // saving patterns toWrite << impl.noPatterns; toWrite << impl.delta; @@ -354,6 +144,7 @@ QDataStream& operator>>(QDataStream &in, BlockImplementation &impl) { in >> impl.xmlFile; in >> impl.referenceXml; in >> impl.referenceMd5; + in >> impl.resources; // loading patterns in >> impl.noPatterns; in >> impl.delta; @@ -363,38 +154,3 @@ QDataStream& operator>>(QDataStream &in, BlockImplementation &impl) { return in; } - -QString BlockImplementation::calculateWidth(QString s){ - QRegExp *rxWidth = new QRegExp("$*([a-zA-Z0-9_-]*)"); - QStringList matchList = s.split(" "); - int pos = 0; - QString res, line; - QList listParams = reference->getParameters(); - - while ((pos = rxWidth->indexIn(s, pos)) != -1) { - matchList << rxWidth->cap(1); - pos += rxWidth->matchedLength(); - } - - for (int i = 0; i < matchList.size(); i++) { - QString match = matchList.at(i); - if(rxWidth->indexIn(match)) { - for(int j = 0; j < listParams.size(); j++) { - if(match.compare(listParams.at(j)->getName())) { - BlockParameter *param = listParams.at(i); - if(param->getContext() == "generic") { - match = match.remove('$'); - } - else { - match = param->getValue().toString(); - } - } - } - } - } - line = matchList.join(' '); - evaluator->setExpression(line); - res = evaluator->evaluate(); - return res; -} -