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

Method eval

source/ast/builtins/StringMethods.cpp:66–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64 {&builtins.intType}, builtins.byteType, true) {}
65
66 ConstantValue eval(EvalContext& context, const Args& args, SourceRange,
67 const CallExpression::SystemCallInfo&) const final {
68 auto strCv = args[0]->eval(context);
69 auto indexCv = args[1]->eval(context);
70 if (!strCv || !indexCv)
71 return nullptr;
72
73 const std::string& str = strCv.str();
74 int32_t index = indexCv.integer().as<int32_t>().value();
75 if (index < 0 || size_t(index) >= str.length())
76 return SVInt(8, 0, false);
77
78 return SVInt(8, uint64_t(str[size_t(index)]), false);
79 }
80};
81
82class StringUpperLowerMethod : public SimpleSystemSubroutine {

Callers

nothing calls this directly

Calls 4

SVIntFunction · 0.85
strMethod · 0.80
evalMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected