MCPcopy Create free account
hub / github.com/MikePopoloski/slang / eval

Method eval

source/ast/builtins/StringMethods.cpp:155–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153 {&builtins.intType, &builtins.intType}, builtins.stringType, true) {}
154
155 ConstantValue eval(EvalContext& context, const Args& args, SourceRange,
156 const CallExpression::SystemCallInfo&) const final {
157 auto strCv = args[0]->eval(context);
158 auto leftCv = args[1]->eval(context);
159 auto rightCv = args[2]->eval(context);
160 if (!strCv || !leftCv || !rightCv)
161 return nullptr;
162
163 const std::string& str = strCv.str();
164 int32_t left = leftCv.integer().as<int32_t>().value();
165 int32_t right = rightCv.integer().as<int32_t>().value();
166 if (left < 0 || right < left || size_t(right) >= str.length())
167 return ""s;
168
169 int32_t count = right - left + 1;
170 return str.substr(size_t(left), size_t(count));
171 }
172};
173
174class StringAtoIMethod : public SimpleSystemSubroutine {

Callers

nothing calls this directly

Calls 3

strMethod · 0.80
evalMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected