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

Method eval

source/ast/builtins/ArrayMethods.cpp:480–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478 }
479
480 ConstantValue eval(EvalContext& context, const Args& args, SourceRange,
481 const CallExpression::SystemCallInfo& callInfo) const final {
482 ConstantValue arr = args[0]->eval(context);
483 if (!arr)
484 return nullptr;
485
486 SVQueue result;
487
488 auto [iterExpr, iterVar] = callInfo.getIteratorInfo();
489 if (iterExpr) {
490 SLANG_ASSERT(iterVar);
491 auto guard = context.disableCaching();
492 auto iterVal = context.createLocal(iterVar);
493
494 uint32_t index = 0;
495 flat_hash_set<ConstantValue> seen;
496 for (auto it = begin(arr); it != end(arr); ++it, ++index) {
497 *iterVal = *it;
498 auto cv = iterExpr->eval(context);
499 if (seen.emplace(cv).second) {
500 if (isIndexed && !arr.isMap())
501 result.emplace_back(SVInt(32, index, true));
502 else if (isIndexed)
503 result.emplace_back(it.key());
504 else
505 result.emplace_back(std::move(*it));
506 }
507 }
508 }
509 else {
510 uint32_t index = 0;
511 flat_hash_set<ConstantValue> seen;
512 for (auto it = begin(arr); it != end(arr); ++it, ++index) {
513 if (seen.emplace(*it).second) {
514 if (isIndexed && !arr.isMap())
515 result.emplace_back(SVInt(32, index, true));
516 else if (isIndexed)
517 result.emplace_back(it.key());
518 else
519 result.emplace_back(std::move(*it));
520 }
521 }
522 }
523
524 return result;
525 }
526
527private:
528 bool isIndexed;

Callers

nothing calls this directly

Calls 8

SVIntFunction · 0.85
getIteratorInfoMethod · 0.80
createLocalMethod · 0.80
emplace_backMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
evalMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected