inspect_input.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #include "inspect_input.h"
  2. #include <yql/essentials/core/yql_expr_type_annotation.h>
  3. namespace NYql::NPureCalc {
  4. bool TryFetchInputIndexFromSelf(const TExprNode& node, TExprContext& ctx, ui32 inputsCount, ui32& result) {
  5. TIssueScopeGuard issueSope(ctx.IssueManager, [&]() {
  6. return MakeIntrusive<TIssue>(ctx.GetPosition(node.Pos()), TStringBuilder() << "At function: " << node.Content());
  7. });
  8. if (!EnsureArgsCount(node, 1, ctx)) {
  9. return false;
  10. }
  11. if (!EnsureAtom(*node.Child(0), ctx)) {
  12. return false;
  13. }
  14. if (!TryFromString(node.Child(0)->Content(), result)) {
  15. auto message = TStringBuilder() << "Index " << TString{node.Child(0)->Content()}.Quote() << " isn't UI32";
  16. ctx.AddError(TIssue(ctx.GetPosition(node.Child(0)->Pos()), std::move(message)));
  17. return false;
  18. }
  19. if (result >= inputsCount) {
  20. auto message = TStringBuilder() << "Invalid input index: " << result << " is out of range [0;" << inputsCount << ")";
  21. ctx.AddError(TIssue(ctx.GetPosition(node.Child(0)->Pos()), std::move(message)));
  22. return false;
  23. }
  24. return true;
  25. }
  26. }