void CompileGetFunction::connectParams(shared_ptr<Token> param, shared_ptr<LinkedTokenList>& paramlist) { shared_ptr<Token> connectToken = make_shared<Token>(); shared_ptr<Token> nParam = make_shared<Token>(param); changeVariable(nParam); connectToken->setType(IToken::EQUALS); connectToken->setLevel(nParam->getLevel()); connectToken->setPosition(-1); connectToken->setPositionInList(-1); connectToken->setLineNumber(-1); connectToken->setText("="); shared_ptr<LinkedTokenList> tempList = make_shared<LinkedTokenList>(); tempList->add(nParam); tempList->add(connectToken); shared_ptr<Token> temp = paramlist->getFirst(); while (temp != nullptr) { tempList->add(temp); temp = temp->getNext(); } connectToken = make_shared<Token>(); connectToken->setType(IToken::NEWLINE); connectToken->setLevel(nParam->getLevel()); connectToken->setPosition(-1); connectToken->setPositionInList(-1); connectToken->setLineNumber(-1); connectToken->setText("\n"); tempList->add(connectToken); temp = tempList->getFirst(); paramlist = make_shared<LinkedTokenList>(tempList); }
void CompileGetFunction::changeVariables(const shared_ptr<LinkedTokenList>& list) { shared_ptr<Token> current = list->getFirst(); while (current != nullptr) { changeVariable(current); current = current->getNext(); } }
void SimpleVisApp::changeVariableAndUpdate(const QString &var) { changeVariable(var); variables->blockSignals(true); for(int i = 0; i < variables->count(); ++i) { if(variables->item(i)->text() == var) { variables->setCurrentRow(i); break; } } variables->blockSignals(false); }
void CompileGetFunction::compileUserDefined(const shared_ptr<LinkedTokenList>& tokenList, shared_ptr<Token>& begin, shared_ptr<Token>& end) { CompileFactory factory; shared_ptr<Token> current = begin; shared_ptr<Token> last = end; vector<shared_ptr<LinkedTokenList>> paramList; int count = 0; if (_params.size() > 0) { if (current->getType() != IToken::FUNCTION_DECLARE_CLOSE) { _parameters->add(make_shared<DoNothingNode>()); shared_ptr<LinkedTokenList> param = make_shared<LinkedTokenList>(); stack<IToken> stack; do { if (current->getType() == IToken::FUNCTION_DECLARE_OPEN) { stack.push(current->getType()); } else if (current->getType() == IToken::FUNCTION_DECLARE_CLOSE && stack.size() > 0) { stack.pop(); } if ((size_t)count > _params.size() - 1) { auto error = make_shared<Error>(_name + " has more parameters than expected", ".md", current->getLineNumber(), current->getPosition(), ErrorType::ERROR); ErrorHandler::getInstance()->addError(error); break; } if (stack.size() >= 0) { if (stack.size() == 0 && current->getType() == IToken::AND_PARA) { if (param->getLast() != nullptr) { param->getLast()->setNext(nullptr); param->getFirst()->setPrevious(nullptr); connectParams(_paramTokens.at(count), param); paramList.push_back(param); } else { auto error = make_shared<Error>(_name + " expected filling for the parameter", ".md", current->getLineNumber(),current->getPosition(), ErrorType::ERROR); ErrorHandler::getInstance()->addError(error); } param = make_shared<LinkedTokenList>(); count++; } else { param->add(make_shared<Token>(current)); } } current = current->getNext(); if (stack.size() == 0 && current->getType() == IToken::FUNCTION_DECLARE_CLOSE) { if (param->getLast() != nullptr) { param->getLast()->setNext(nullptr); param->getFirst()->setPrevious(nullptr); connectParams(_paramTokens.at(count), param); paramList.push_back(param); } else { auto error = make_shared<Error>(_name + " expected filling for the parameter", ".md", current->getLineNumber(), current->getPosition(), ErrorType::ERROR); ErrorHandler::getInstance()->addError(error); } param = make_shared<LinkedTokenList>(); break; } } while (current != end); } } if (paramList.size() < _params.size()) { auto error = make_shared<Error>(_name + " has less parameters than expected", ".md", current->getLineNumber(), current->getPosition(), ErrorType::ERROR); ErrorHandler::getInstance()->addError(error); } else if (paramList.size() > _params.size()) { auto error = make_shared<Error>(_name + " has more parameters than expected", ".md", current->getLineNumber(), current->getPosition(), ErrorType::ERROR); ErrorHandler::getInstance()->addError(error); } for (shared_ptr<LinkedTokenList> p : paramList) { CompileEquals condition; auto firstNode= p->getFirst(); auto endNode = p->getLast(); auto eBefore= _parameters->getLast(); condition.compile(p,firstNode, endNode, _parameters,eBefore); } if (_returnToken) { _returnToken = make_shared<Token>(_returnToken); shared_ptr<LinkedActionList> rValue = make_shared<LinkedActionList>(); CompileCondition condition; auto eBefore = rValue->getLast(); condition.compile(tokenList, _returnToken, _returnToken, rValue, eBefore); string sBuffer; string tempVar = getNextLocalVariableName(sBuffer); auto tempToken= make_shared<Token>(_returnToken); shared_ptr<DirectFunctionCall> pDirectFunction = make_shared<DirectFunctionCall>(tempToken); pDirectFunction->setArraySize(2); pDirectFunction->setAt(0, szGetFromReturnValue); pDirectFunction->setAt(1, tempVar.c_str()); rValue->insertBefore(pDirectFunction, rValue->getLast()); _body->add(rValue); } shared_ptr<LinkedTokenList> body = make_shared<LinkedTokenList>(_bodyTokens); changeVariables(body); shared_ptr<Token> currentBody = body->getFirst(); _body->add(make_shared<DoNothingNode>()); while (currentBody != nullptr) { if (currentBody->getType() == IToken::FUNCTION_CLOSE) { currentBody = currentBody->getNext(); break; } shared_ptr<Compiler> compiledBodyPart; bool multiIndex = false; if (currentBody->getType() == IToken::NEWLINE || (currentBody->getNext()->getType() != IToken::FUNCTION_CLOSE && currentBody->getNext()->getType() != IToken::NEWLINE)) { compiledBodyPart = factory.createCompileStatement(currentBody); multiIndex = true; } else { compiledBodyPart = make_shared<CompileSingleStatement>(); } if (compiledBodyPart != nullptr) { auto eNode = body->getLast(); auto eBefore = _body->getLast(); compiledBodyPart->compile(_bodyTokens, currentBody, eNode, _body, eBefore); if (!multiIndex) { currentBody = currentBody->getNext(); } } else { currentBody = currentBody->getNext(); } } if (_returnToken != nullptr) { string sBuffer; string tempVar = getNextLocalVariableName(sBuffer); changeVariable(_returnToken); auto tempToken= make_shared<Token>(_returnToken); shared_ptr<DirectFunctionCall> directFunctionCall = make_shared<DirectFunctionCall>(tempToken); directFunctionCall->setArraySize(2); directFunctionCall->setAt(0, SET_ID_TO_RT); directFunctionCall->setAt(1, _returnToken->getText().c_str()); _body->insertBefore(_body->getLast(), directFunctionCall); } begin = current; }