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

Method eval

source/ast/builtins/ArrayMethods.cpp:903–929  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901 }
902
903 ConstantValue eval(EvalContext& context, const Args& args, SourceRange,
904 const CallExpression::SystemCallInfo&) const final {
905 auto lval = args[0]->evalLValue(context);
906 if (!lval)
907 return nullptr;
908
909 auto target = lval.resolve();
910 SLANG_ASSERT(target && target->isQueue());
911 auto& q = *target->queue();
912
913 // If no arguments, clear the queue.
914 if (args.size() == 1) {
915 q.clear();
916 return NullConstant;
917 }
918
919 auto ci = args[1]->eval(context);
920 std::optional<int32_t> index = ci.integer().as<int32_t>();
921 if (!index || *index < 0 || size_t(*index) >= q.size()) {
922 context.addDiag(diag::ConstEvalDynamicArrayIndex, args[1]->sourceRange)
923 << ci << *args[0]->type << q.size();
924 return NullConstant;
925 }
926
927 q.erase(q.begin() + *index);
928 return NullConstant;
929 }
930};
931
932class IteratorIndexMethod : public SystemSubroutine {

Callers

nothing calls this directly

Calls 7

evalLValueMethod · 0.80
resolveMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
evalMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected