...

Source file src/cuelang.org/go/internal/core/adt/closed2.go

Documentation: cuelang.org/go/internal/core/adt

     1  // Copyright 2020 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package adt
    16  
    17  // CloseDef defines how individual fieldSets (corresponding to conjuncts)
    18  // combine to determine whether a field is contained in a closed set.
    19  //
    20  // A CloseDef combines multiple conjuncts and embeddings. All CloseDefs are
    21  // stored in slice. References to other CloseDefs are indices within this slice.
    22  // Together they define the top of the tree of the expression tree of how
    23  // conjuncts combine together (a canopy).
    24  
    25  // isComplexStruct reports whether the Closed information should be copied as a
    26  // subtree into the parent node using InsertSubtree. If not, the conjuncts can
    27  // just be inserted at the current ID.
    28  func isComplexStruct(ctx *OpContext, v *Vertex) bool {
    29  	return v.IsClosedStruct()
    30  }
    31  
    32  // TODO: cleanup code and error messages. Reduce duplication in some related
    33  // code.
    34  func verifyArc2(ctx *OpContext, f Feature, v *Vertex, isClosed bool) (found bool, err *Bottom) {
    35  	unreachableForDev(ctx)
    36  
    37  	// Don't check computed, temporary vertices.
    38  	if v.Label == InvalidLabel {
    39  		return true, nil
    40  	}
    41  
    42  	// TODO(perf): collect positions in error.
    43  	defer ctx.ReleasePositions(ctx.MarkPositions())
    44  
    45  	// Note: it is okay to use parent here as this only needs to be computed
    46  	// for the original location.
    47  	if ok, required := Accept(ctx, v.Parent, f); ok || (!required && !isClosed) {
    48  		return true, nil
    49  	}
    50  
    51  	if !f.IsString() {
    52  		// if f.IsHidden()  { Also change Accept in composite.go
    53  		return false, nil
    54  	}
    55  
    56  	if v != nil {
    57  		for _, c := range v.Conjuncts {
    58  			if pos := c.Field(); pos != nil {
    59  				ctx.AddPosition(pos)
    60  			}
    61  		}
    62  	}
    63  
    64  	for _, s := range v.Parent.Structs {
    65  		s.AddPositions(ctx)
    66  	}
    67  
    68  	return false, ctx.NewErrf("field not allowed")
    69  }
    70  

View as plain text