MCPcopy Index your code
hub / github.com/bazelbuild/bazel / eval

Method eval

src/main/java/net/starlark/java/eval/Eval.java:544–606  ·  view source on GitHub ↗
(StarlarkThread.Frame fr, Expression expr)

Source from the content-addressed store, hash-verified

542 // ---- expressions ----
543
544 private static Object eval(StarlarkThread.Frame fr, Expression expr)
545 throws EvalException, InterruptedException {
546 if (++fr.thread.steps >= fr.thread.stepLimit) {
547 throw new EvalException("Starlark computation cancelled: too many steps");
548 }
549
550 // The switch cases have been split into separate functions
551 // to reduce the stack usage during recursion, which is
552 // especially important in practice for deeply nested a+...+z
553 // expressions; see b/153764542.
554 switch (expr.kind()) {
555 case BINARY_OPERATOR:
556 return evalBinaryOperator(fr, (BinaryOperatorExpression) expr);
557 case COMPREHENSION:
558 return evalComprehension(fr, (Comprehension) expr);
559 case CONDITIONAL:
560 return evalConditional(fr, (ConditionalExpression) expr);
561 case DICT_EXPR:
562 return evalDict(fr, (DictExpression) expr);
563 case DOT:
564 return evalDot(fr, (DotExpression) expr);
565 case CALL:
566 return evalCall(fr, (CallExpression) expr);
567 case CAST:
568 return eval(fr, ((CastExpression) expr).getValue());
569 case ISINSTANCE:
570 fr.setErrorLocation(expr.getStartLocation());
571 throw new EvalException("isinstance() is not yet supported");
572 case IDENTIFIER:
573 return evalIdentifier(fr, (Identifier) expr);
574 case INDEX:
575 return evalIndex(fr, (IndexExpression) expr);
576 case INT_LITERAL:
577 // TODO(adonovan): opt: avoid allocation by saving
578 // the StarlarkInt in the IntLiteral (a temporary hack
579 // until we use a compiled representation).
580 Number n = ((IntLiteral) expr).getValue();
581 if (n instanceof Integer nInt) {
582 return StarlarkInt.of(nInt);
583 } else if (n instanceof Long nLong) {
584 return StarlarkInt.of(nLong);
585 } else {
586 return StarlarkInt.of((BigInteger) n);
587 }
588 case FLOAT_LITERAL:
589 return StarlarkFloat.of(((FloatLiteral) expr).getValue());
590 case LAMBDA:
591 return newFunction(fr, ((LambdaExpression) expr).getResolvedFunction());
592 case LIST_EXPR:
593 return evalList(fr, (ListExpression) expr);
594 case SLICE:
595 return evalSlice(fr, (SliceExpression) expr);
596 case STRING_LITERAL:
597 return ((StringLiteral) expr).getValue();
598 case UNARY_OPERATOR:
599 return evalUnaryOperator(fr, (UnaryOperatorExpression) expr);
600 case ELLIPSIS:
601 case TYPE_APPLICATION:

Callers 15

execAssignmentMethod · 0.95
newFunctionMethod · 0.95
execIfMethod · 0.95
execReturnMethod · 0.95
execMethod · 0.95
assignMethod · 0.95
evalBinaryOperatorMethod · 0.95
evalConditionalMethod · 0.95
evalDictMethod · 0.95
evalDotMethod · 0.95
evalCallMethod · 0.95

Calls 15

evalBinaryOperatorMethod · 0.95
evalComprehensionMethod · 0.95
evalConditionalMethod · 0.95
evalDictMethod · 0.95
evalDotMethod · 0.95
evalCallMethod · 0.95
evalIdentifierMethod · 0.95
evalIndexMethod · 0.95
ofMethod · 0.95
ofMethod · 0.95
newFunctionMethod · 0.95
evalListMethod · 0.95

Tested by

no test coverage detected