return true; \r
}\r
\r
-QString BlockImplementation::eval(QString line, QTextStream& out) {\r
- QString res, s, begLine, endLine, expr;\r
- evaluator->setExpression(line);\r
- QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)");\r
- QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)");\r
- QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*");\r
-\r
- int nbAt = line.count('@');\r
- while(nbAt != 0) {\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxString->indexIn(line)) {\r
- begLine = rxString->cap(1);\r
- s = rxString->cap(2);\r
- endLine = rxString->cap(3);\r
- res = begLine + evalString(s) + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxValue->indexIn(line)) {\r
- begLine = rxValue->cap(1);\r
- s = rxValue->cap(2);\r
- endLine = rxValue->cap(3);\r
- res = begLine + evalValue(s) + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxExpr->indexIn(line)) {\r
- expr = rxExpr->cap(1);\r
- if(expr.count('@') == 0) {\r
- evaluator->setExpression(expr);\r
- s = QString::number(evaluator->evaluate());\r
- }\r
- res = begLine + s + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- }\r
- return res;\r
-}\r
-\r
-QString BlockImplementation::evalComplex(QString line, int id) {\r
- QString res, s, begLine, endLine, expr;\r
- QRegExp *rxString = new QRegExp("(.*)@{(.*)}(.*)");\r
- QRegExp *rxValue = new QRegExp("(.*)@val{(.*)}(.*)");\r
- QRegExp *rxExpr = new QRegExp(".*@eval{(.*)}.*");\r
- QRegExp *rxFor = new QRegExp("@foreach{.*}(@{.*})(.*)@endforeach");\r
- QRegExp *rxCase = new QRegExp("@caseeach{.*,(.*),(.*)}(@{.*})(.*)@endcaseeach");\r
- QRegExp *rxCaseDown = new QRegExp("@#-:(.*)");\r
- QRegExp *rxCaseUp = new QRegExp("@#:(.*)");\r
- evaluator->setExpression(line);\r
-\r
- int nbAt = line.count('@') - 2;\r
- while(nbAt != 0) {\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxString->indexIn(line)) {\r
- begLine = rxString->cap(1);\r
- s = rxString->cap(2);\r
- endLine = rxString->cap(3);\r
- if(evalStringComplex(s)->size() == 0)\r
- line = begLine + evalString(s) + endLine;\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxValue->indexIn(line)) {\r
- begLine = rxValue->cap(1);\r
- s = rxValue->cap(2);\r
- endLine = rxValue->cap(3);\r
- line = begLine + evalValue(s) + endLine;\r
- nbAt --;\r
- }\r
- }\r
- for(int i = 0; i < line.size(); i++) {\r
- if(rxExpr->indexIn(line)) {\r
- expr = rxExpr->cap(1);\r
- if(expr.count('@') == 0) {\r
- evaluator->setExpression(expr);\r
- s = QString::number(evaluator->evaluate());\r
- }\r
- res = begLine + s + endLine + '\n';\r
- nbAt --;\r
- }\r
- }\r
- }\r
-\r
- if(id == 1) {\r
- if(rxFor->indexIn(line)) {\r
- QString intName, instruc;\r
- intName = rxFor->cap(1);\r
- instruc = rxFor->cap(2);\r
- QList<AbstractInterface*> *intList = evalStringComplex(intName);\r
- if(intList->size() != 0) {\r
- for(int i = 0; i < intList->size(); i++) {\r
- res = intList->at(i)->getName() + instruc + '\n';\r
- }\r
- }\r
- }\r
- }\r
-\r
- else if(id == 2) {\r
- if(rxCase->indexIn(line)) {\r
- QString intName, sigName, cases, instruc;\r
- int number;\r
- sigName = rxCase->cap(1);\r
- cases = rxCase->cap(2);\r
- intName = rxCase->cap(3);\r
- instruc = rxCase->cap(4);\r
- QList<AbstractInterface*> *intList = evalStringComplex(intName);\r
- int listSize = intList->count();\r
- res = "case " + sigName + " is\n";\r
- if(rxCaseUp->indexIn(cases)) {\r
- number = rxCaseUp->cap(1).toInt();\r
- for(int j = number; j < listSize; j++) {\r
- if(listSize > 0) {\r
- for(int i = 0; i < listSize; i++) {\r
- res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n";\r
- }\r
- }\r
- else\r
- res += "\twhen " + number + ' ' + intName + instruc + "\n";\r
- number++;\r
- }\r
- }\r
- if(rxCaseDown->indexIn(cases)) {\r
- number = rxCaseDown->cap(1).toInt();\r
- for(int j = number; j < listSize; j++) {\r
- if(listSize > 0) {\r
- for(int i = 0; i < listSize; i++) {\r
- res += "\twhen " + QString::number(number) + " " + intList->at(i)->getName() + instruc + "\n";\r
- }\r
- }\r
- else\r
- res += "\twhen " + number + ' ' + intName + instruc + "\n";\r
- number--;\r
- }\r
- res += "end case ;\n";\r
- }\r
- }\r
- }\r
- return res;\r
-}\r
-\r
-QString BlockImplementation::evalString(QString s) {\r
-\r
- QString name = getIfaceUserName(block->AbstractBlock::getIfaceFromName(s));\r
- return name;\r
-}\r
-\r
-QList<AbstractInterface*>* BlockImplementation::evalStringComplex(QString s) {\r
-\r
- int j = 0;\r
- QList<AbstractInterface*> *listInterfaces = new QList<AbstractInterface*>();\r
- AbstractInterface *inter = block->AbstractBlock::getIfaceFromName(s);\r
- QList<AbstractInterface*> listIntBlock = block->getInterfaces();\r
- for(int i = 0; i < listIntBlock.size(); i++) {\r
- if(inter->getName().compare(listIntBlock.at(i)->getName()) < -1) {\r
- listInterfaces->insert(j, inter);\r
- j ++;\r
- }\r
- }\r
- return listInterfaces;\r
-}\r
-\r
-QString BlockImplementation::evalValue(QString s) {\r
-\r
- QString val = "";\r
- if(paramMap.contains(s))\r
- val = paramMap.value(s);\r
- return val;\r
-}\r
-\r
-QString BlockImplementation::getIfaceUserName(AbstractInterface* refIface) {\r
-\r
- if (! refIface->isReferenceInterface()) return "";\r
-\r
- AbstractInterface* funcIface = NULL;\r
-\r
- if (refIface->getDirection() == AbstractInterface::Input) {\r
- foreach(AbstractInterface* iface, block->getInputs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- else if (refIface->getDirection() == AbstractInterface::Output) {\r
- foreach(AbstractInterface* iface, block->getOutputs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- else if (refIface->getDirection() == AbstractInterface::InOut) {\r
- foreach(AbstractInterface* iface, block->getBidirs()) {\r
- FunctionalInterface* fi = (FunctionalInterface*)iface;\r
- if (fi->getReference() == refIface) {\r
- funcIface = iface;\r
- break;\r
- }\r
- }\r
- }\r
- if (funcIface == NULL) return "";\r
-\r
- return funcIface->getName();\r
-}\r
-\r
QDataStream& operator<<(QDataStream &out, const BlockImplementation &impl) {\r
\r
out.setVersion(QDataStream::Qt_5_0);\r
toWrite << impl.xmlFile;\r
toWrite << impl.referenceXml;\r
toWrite << impl.referenceMd5;\r
+ toWrite << impl.resources;\r
// saving patterns\r
toWrite << impl.noPatterns;\r
toWrite << impl.delta;\r
in >> impl.xmlFile;\r
in >> impl.referenceXml;\r
in >> impl.referenceMd5;\r
+ in >> impl.resources;\r
// loading patterns\r
in >> impl.noPatterns;\r
in >> impl.delta;\r
\r
return in;\r
}\r
-\r
-QString BlockImplementation::calculateWidth(QString s){\r
- QRegExp *rxWidth = new QRegExp("$*([a-zA-Z0-9_-]*)");\r
- QStringList matchList = s.split(" ");\r
- int pos = 0;\r
- QString res, line;\r
- QList<BlockParameter*> listParams = reference->getParameters();\r
-\r
- while ((pos = rxWidth->indexIn(s, pos)) != -1) {\r
- matchList << rxWidth->cap(1);\r
- pos += rxWidth->matchedLength();\r
- }\r
-\r
- for (int i = 0; i < matchList.size(); i++) {\r
- QString match = matchList.at(i);\r
- if(rxWidth->indexIn(match)) {\r
- for(int j = 0; j < listParams.size(); j++) {\r
- if(match.compare(listParams.at(j)->getName())) {\r
- BlockParameter *param = listParams.at(i);\r
- if(param->getContext() == "generic") {\r
- match = match.remove('$');\r
- }\r
- else {\r
- match = param->getValue().toString();\r
- }\r
- }\r
- }\r
- }\r
- }\r
- line = matchList.join(' ');\r
- evaluator->setExpression(line);\r
- res = evaluator->evaluate();\r
- return res;\r
-}\r
-\r