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

Method eval

source/ast/builtins/StringMethods.cpp:114–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112 ignoreCase(ignoreCase) {}
113
114 ConstantValue eval(EvalContext& context, const Args& args, SourceRange,
115 const CallExpression::SystemCallInfo&) const final {
116 auto lhsCv = args[0]->eval(context);
117 auto rhsCv = args[1]->eval(context);
118 if (!lhsCv || !rhsCv)
119 return nullptr;
120
121 std::string& lhs = lhsCv.str();
122 std::string& rhs = rhsCv.str();
123
124 int result;
125 if (ignoreCase) {
126 // No convenient way to do this with standard lib functions :(
127 const char* p1 = lhs.c_str();
128 const char* p2 = rhs.c_str();
129 while ((result = charToLower(*p1) - charToLower(*p2++)) == 0) {
130 if (*p1++ == '\0')
131 break;
132 }
133 }
134 else {
135 result = lhs.compare(rhs);
136 if (result < 0)
137 result = -1;
138 else if (result > 0)
139 result = 1;
140 }
141
142 return SVInt(32, uint64_t(result), true);
143 }
144
145private:
146 bool ignoreCase;

Callers

nothing calls this directly

Calls 4

charToLowerFunction · 0.85
SVIntFunction · 0.85
strMethod · 0.80
evalMethod · 0.45

Tested by

no test coverage detected