------------------------------------------------------------------------------
| 413 | |
| 414 | //------------------------------------------------------------------------------ |
| 415 | int vtkExprTkFunctionParser::Parse(ParseMode mode) |
| 416 | { |
| 417 | if (this->Function.empty()) |
| 418 | { |
| 419 | vtkErrorMacro("Parse: no function has been set"); |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | // During the parsing of the first mode, perform the necessary changes in the function |
| 424 | if (mode == ParseMode::DetectReturnType) |
| 425 | { |
| 426 | // Before parsing, replace the original variable names in the function |
| 427 | // with the valid ones if needed. |
| 428 | for (size_t i = 0; i < this->OriginalScalarVariableNames.size(); ++i) |
| 429 | { |
| 430 | if (this->OriginalScalarVariableNames[i] != this->UsedScalarVariableNames[i]) |
| 431 | { |
| 432 | vtksys::SystemTools::ReplaceString(this->FunctionWithUsedVariableNames, |
| 433 | this->OriginalScalarVariableNames[i], this->UsedScalarVariableNames[i]); |
| 434 | } |
| 435 | } |
| 436 | for (size_t i = 0; i < this->OriginalVectorVariableNames.size(); ++i) |
| 437 | { |
| 438 | if (this->OriginalVectorVariableNames[i] != this->UsedVectorVariableNames[i]) |
| 439 | { |
| 440 | vtksys::SystemTools::ReplaceString(this->FunctionWithUsedVariableNames, |
| 441 | this->OriginalVectorVariableNames[i], this->UsedVectorVariableNames[i]); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | // remove spaces to perform replacement for norm and cross |
| 446 | this->FunctionWithUsedVariableNames = RemoveSpacesFrom(this->FunctionWithUsedVariableNames); |
| 447 | |
| 448 | // check for usage of old dot format product, e.g. (v1.v2) instead of dot(v1,v2) |
| 449 | if (this->CheckOldFormatOfDotProductUsage()) |
| 450 | { |
| 451 | std::string oldDotUsageError = |
| 452 | "Warn: 0000 Type: [Old Usage] Msg: " |
| 453 | "Possible usage of old format of dot product v1.v2. Please use dot(v1,v2)." |
| 454 | "\tExpression: " + |
| 455 | this->Function + '\n'; |
| 456 | vtkWarningMacro(<< oldDotUsageError); |
| 457 | } |
| 458 | |
| 459 | // fix cross occurrences with something that ExprTk can understand |
| 460 | this->FunctionWithUsedVariableNames = |
| 461 | FixVectorReturningFunctionOccurrences(VectorReturningFunction::Cross); |
| 462 | |
| 463 | // fix norm occurrences with something that ExprTk can understand |
| 464 | this->FunctionWithUsedVariableNames = |
| 465 | FixVectorReturningFunctionOccurrences(VectorReturningFunction::Norm); |
| 466 | } |
| 467 | |
| 468 | if (mode == ParseMode::DetectReturnType) |
| 469 | { |
| 470 | // ExprTK, in order to extract vector and scalar results, and identify the result type, |
| 471 | // it requires to "return results" instead of just evaluating an expression |
| 472 | auto function = this->FunctionWithUsedVariableNames; |
no test coverage detected