more work on var handling. Inject collection variables.
This commit is contained in:
parent
29064c44be
commit
74cfa3ecbf
@ -36,6 +36,8 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
#include <QtGlobal> // Q_ASSERT
|
||||||
|
|
||||||
#include "PmuppScript.h"
|
#include "PmuppScript.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -85,7 +87,7 @@ int PmuppScript::executeScript()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString cmd;
|
QString cmd;
|
||||||
int status=0;
|
int status;
|
||||||
for (int i=0; i<fScript.size(); i++) {
|
for (int i=0; i<fScript.size(); i++) {
|
||||||
cmd = fScript.at(i);
|
cmd = fScript.at(i);
|
||||||
if (cmd.startsWith("loadPath")) {
|
if (cmd.startsWith("loadPath")) {
|
||||||
@ -109,7 +111,7 @@ int PmuppScript::executeScript()
|
|||||||
} else if (cmd.startsWith("macro")) {
|
} else if (cmd.startsWith("macro")) {
|
||||||
status = macro(cmd);
|
status = macro(cmd);
|
||||||
} else if (cmd.startsWith("var")) {
|
} else if (cmd.startsWith("var")) {
|
||||||
std::cout << "debug> will eventually handle variable definition here ..." << std::endl;
|
status = var_cmd(cmd);
|
||||||
} else if (cmd.startsWith("col")) {
|
} else if (cmd.startsWith("col")) {
|
||||||
std::cout << "debug> will eventually handle linking of a variable to a collection ..." << std::endl;
|
std::cout << "debug> will eventually handle linking of a variable to a collection ..." << std::endl;
|
||||||
} else {
|
} else {
|
||||||
@ -663,6 +665,47 @@ int PmuppScript::macro(const QString str, const QString plotFln)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief PmuppScript::var_cmd
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int PmuppScript::var_cmd(const QString str)
|
||||||
|
{
|
||||||
|
QStringList tok;
|
||||||
|
int idx=0;
|
||||||
|
|
||||||
|
// get linked collection index for further use
|
||||||
|
tok = str.split(' ', QString::SkipEmptyParts);
|
||||||
|
if (tok[1].endsWith("Err")) // error variable no need to do something
|
||||||
|
return 0;
|
||||||
|
idx = getCollectionIndex(tok[1]);
|
||||||
|
if (idx == -1) // var not linked to collection, ignore it
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// check for the related error variable if present
|
||||||
|
QString varErr = QString("%1%2").arg(tok[1]).arg("Err");
|
||||||
|
QString varErrCmd("");
|
||||||
|
for (int i=0; i<fScript.size(); i++) {
|
||||||
|
if (fScript.at(i).contains(varErr, Qt::CaseSensitive)) {
|
||||||
|
varErrCmd = fScript.at(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string parse_str = str.toLatin1().data();
|
||||||
|
if (!varErrCmd.isEmpty()) {
|
||||||
|
parse_str += "\n";
|
||||||
|
parse_str += varErrCmd.toLatin1().data();
|
||||||
|
}
|
||||||
|
|
||||||
|
PVarHandler varHandler(fParamDataHandler->GetCollection(idx), parse_str);
|
||||||
|
fVarHandler.push_back(varHandler);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief PmuppScript::foundLabel
|
* @brief PmuppScript::foundLabel
|
||||||
@ -749,3 +792,34 @@ QString PmuppScript::getNicerLabel(const QString label)
|
|||||||
|
|
||||||
return nice;
|
return nice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief PmuppScript::getCollectionIndex
|
||||||
|
* @param var_name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int PmuppScript::getCollectionIndex(const QString var_name)
|
||||||
|
{
|
||||||
|
int idx = -1;
|
||||||
|
QString cmd;
|
||||||
|
QStringList tok;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
for (int i=0; i<fScript.size(); i++) {
|
||||||
|
cmd = fScript.at(i);
|
||||||
|
if (cmd.startsWith("col")) {
|
||||||
|
tok.clear();
|
||||||
|
tok = cmd.split(' ', QString::SkipEmptyParts);
|
||||||
|
if (tok[3] == var_name) {
|
||||||
|
idx = tok[1].toInt(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
Q_ASSERT(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
@ -64,6 +64,7 @@ class PmuppScript : public QObject
|
|||||||
int addY(const QString str);
|
int addY(const QString str);
|
||||||
int plot(const QString str);
|
int plot(const QString str);
|
||||||
int macro(const QString str, const QString plotFln="");
|
int macro(const QString str, const QString plotFln="");
|
||||||
|
int var_cmd(const QString str);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int executeScript();
|
int executeScript();
|
||||||
@ -90,6 +91,8 @@ class PmuppScript : public QObject
|
|||||||
bool foundLabel(PmuppCollection *coll, const QString label);
|
bool foundLabel(PmuppCollection *coll, const QString label);
|
||||||
void minMax(QVector<double> dvec, double &min, double &max);
|
void minMax(QVector<double> dvec, double &min, double &max);
|
||||||
QString getNicerLabel(const QString label);
|
QString getNicerLabel(const QString label);
|
||||||
|
|
||||||
|
int getCollectionIndex(const QString var_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PMUPPSCRIPT_H_
|
#endif // _PMUPPSCRIPT_H_
|
||||||
|
@ -35,21 +35,25 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include "Pmupp.h"
|
||||||
#include <PAst.hpp>
|
#include <PAst.hpp>
|
||||||
|
|
||||||
class PVarHandler {
|
class PVarHandler {
|
||||||
public:
|
public:
|
||||||
PVarHandler();
|
PVarHandler(PmuppCollection *coll, std::string parse_str);
|
||||||
|
|
||||||
void setInput(QString &str) { fInput = str.toLatin1().data(); }
|
bool isValid() { return fIsValid; }
|
||||||
bool parse();
|
|
||||||
bool semcheck();
|
|
||||||
std::vector<double> getValues();
|
std::vector<double> getValues();
|
||||||
std::vector<double> getErrors();
|
std::vector<double> getErrors();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string fInput; ///< the variable input to be parsed
|
PmuppCollection *fColl; ///< collection need for parsing and evaluation
|
||||||
|
std::string fParseStr; ///< the variable input to be parsed
|
||||||
|
|
||||||
|
bool fIsValid;
|
||||||
mupp::ast::statement_list fAst; ///< the AST
|
mupp::ast::statement_list fAst; ///< the AST
|
||||||
|
|
||||||
|
void injectPredefVariables();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_PVARHANDLER_H_
|
#endif //_PVARHANDLER_H_
|
||||||
|
@ -27,35 +27,26 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "PVarHandler.h"
|
#include "PVarHandler.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include "PSkipper.hpp"
|
||||||
|
#include "PErrorHandler.hpp"
|
||||||
|
#include "PStatement.hpp"
|
||||||
|
#include "PAstDump.hpp"
|
||||||
|
#include "PProgram.hpp"
|
||||||
|
*/
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief PVarHandler::PVarHandler
|
* @brief PVarHandler::PVarHandler
|
||||||
*/
|
*/
|
||||||
PVarHandler::PVarHandler()
|
PVarHandler::PVarHandler(PmuppCollection *coll, std::string parse_str) :
|
||||||
|
fColl(coll), fParseStr(parse_str), fIsValid(false)
|
||||||
{
|
{
|
||||||
fInput = "";
|
injectPredefVariables();
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief PVarHandler::parse
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
bool PVarHandler::parse()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief PVarHandler::semcheck
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
bool PVarHandler::semcheck()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@ -81,3 +72,27 @@ std::vector<double> PVarHandler::getErrors()
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief PVarHandler::injectPredefVariables
|
||||||
|
*/
|
||||||
|
void PVarHandler::injectPredefVariables()
|
||||||
|
{
|
||||||
|
mupp::ast::statement var_stat;
|
||||||
|
mupp::ast::variable_declaration var;
|
||||||
|
|
||||||
|
std::string varName, errVarName;
|
||||||
|
for (int i=0; i<fColl->GetNoOfRuns(); i++) {
|
||||||
|
varName = fColl->GetRun(i).GetName().toLatin1().data();
|
||||||
|
errVarName = varName + "Err";
|
||||||
|
// inject err_name
|
||||||
|
var.lhs.name = errVarName;
|
||||||
|
var_stat = var;
|
||||||
|
fAst.push_front(var_stat);
|
||||||
|
// inject var_name
|
||||||
|
var.lhs.name = varName;
|
||||||
|
var_stat = var;
|
||||||
|
fAst.push_front(var_stat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user