]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hcl2/ext/dynblock/expr_wrap.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / ext / dynblock / expr_wrap.go
1 package dynblock
2
3 import (
4 "github.com/hashicorp/hcl2/hcl"
5 "github.com/zclconf/go-cty/cty"
6 )
7
8 type exprWrap struct {
9 hcl.Expression
10 i *iteration
11 }
12
13 func (e exprWrap) Variables() []hcl.Traversal {
14 raw := e.Expression.Variables()
15 ret := make([]hcl.Traversal, 0, len(raw))
16
17 // Filter out traversals that refer to our iterator name or any
18 // iterator we've inherited; we're going to provide those in
19 // our Value wrapper, so the caller doesn't need to know about them.
20 for _, traversal := range raw {
21 rootName := traversal.RootName()
22 if rootName == e.i.IteratorName {
23 continue
24 }
25 if _, inherited := e.i.Inherited[rootName]; inherited {
26 continue
27 }
28 ret = append(ret, traversal)
29 }
30 return ret
31 }
32
33 func (e exprWrap) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
34 extCtx := e.i.EvalContext(ctx)
35 return e.Expression.Value(extCtx)
36 }
37
38 // UnwrapExpression returns the expression being wrapped by this instance.
39 // This allows the original expression to be recovered by hcl.UnwrapExpression.
40 func (e exprWrap) UnwrapExpression() hcl.Expression {
41 return e.Expression
42 }