diff --git a/vendor/github.com/golang/protobuf/LICENSE b/vendor/github.com/golang/protobuf/LICENSE deleted file mode 100644 index 1b1b1921efa6dded19f74b196f76a96bf39c83dc..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/LICENSE +++ /dev/null @@ -1,31 +0,0 @@ -Go support for Protocol Buffers - Google's data interchange format - -Copyright 2010 The Go Authors. All rights reserved. -https://github.com/golang/protobuf - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/vendor/github.com/golang/protobuf/proto/Makefile b/vendor/github.com/golang/protobuf/proto/Makefile deleted file mode 100644 index e2e0651a934d3ab8fe6393dfd2556bbc4bd0792e..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# Go support for Protocol Buffers - Google's data interchange format -# -# Copyright 2010 The Go Authors. All rights reserved. -# https://github.com/golang/protobuf -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -install: - go install - -test: install generate-test-pbs - go test - - -generate-test-pbs: - make install - make -C testdata - protoc --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto - make diff --git a/vendor/github.com/golang/protobuf/proto/clone.go b/vendor/github.com/golang/protobuf/proto/clone.go deleted file mode 100644 index e392575b353afa4f22f513d3f22ff64a8f5fdbf1..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/clone.go +++ /dev/null @@ -1,229 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2011 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Protocol buffer deep copy and merge. -// TODO: RawMessage. - -package proto - -import ( - "log" - "reflect" - "strings" -) - -// Clone returns a deep copy of a protocol buffer. -func Clone(pb Message) Message { - in := reflect.ValueOf(pb) - if in.IsNil() { - return pb - } - - out := reflect.New(in.Type().Elem()) - // out is empty so a merge is a deep copy. - mergeStruct(out.Elem(), in.Elem()) - return out.Interface().(Message) -} - -// Merge merges src into dst. -// Required and optional fields that are set in src will be set to that value in dst. -// Elements of repeated fields will be appended. -// Merge panics if src and dst are not the same type, or if dst is nil. -func Merge(dst, src Message) { - in := reflect.ValueOf(src) - out := reflect.ValueOf(dst) - if out.IsNil() { - panic("proto: nil destination") - } - if in.Type() != out.Type() { - // Explicit test prior to mergeStruct so that mistyped nils will fail - panic("proto: type mismatch") - } - if in.IsNil() { - // Merging nil into non-nil is a quiet no-op - return - } - mergeStruct(out.Elem(), in.Elem()) -} - -func mergeStruct(out, in reflect.Value) { - sprop := GetProperties(in.Type()) - for i := 0; i < in.NumField(); i++ { - f := in.Type().Field(i) - if strings.HasPrefix(f.Name, "XXX_") { - continue - } - mergeAny(out.Field(i), in.Field(i), false, sprop.Prop[i]) - } - - if emIn, ok := extendable(in.Addr().Interface()); ok { - emOut, _ := extendable(out.Addr().Interface()) - mIn, muIn := emIn.extensionsRead() - if mIn != nil { - mOut := emOut.extensionsWrite() - muIn.Lock() - mergeExtension(mOut, mIn) - muIn.Unlock() - } - } - - uf := in.FieldByName("XXX_unrecognized") - if !uf.IsValid() { - return - } - uin := uf.Bytes() - if len(uin) > 0 { - out.FieldByName("XXX_unrecognized").SetBytes(append([]byte(nil), uin...)) - } -} - -// mergeAny performs a merge between two values of the same type. -// viaPtr indicates whether the values were indirected through a pointer (implying proto2). -// prop is set if this is a struct field (it may be nil). -func mergeAny(out, in reflect.Value, viaPtr bool, prop *Properties) { - if in.Type() == protoMessageType { - if !in.IsNil() { - if out.IsNil() { - out.Set(reflect.ValueOf(Clone(in.Interface().(Message)))) - } else { - Merge(out.Interface().(Message), in.Interface().(Message)) - } - } - return - } - switch in.Kind() { - case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, - reflect.String, reflect.Uint32, reflect.Uint64: - if !viaPtr && isProto3Zero(in) { - return - } - out.Set(in) - case reflect.Interface: - // Probably a oneof field; copy non-nil values. - if in.IsNil() { - return - } - // Allocate destination if it is not set, or set to a different type. - // Otherwise we will merge as normal. - if out.IsNil() || out.Elem().Type() != in.Elem().Type() { - out.Set(reflect.New(in.Elem().Elem().Type())) // interface -> *T -> T -> new(T) - } - mergeAny(out.Elem(), in.Elem(), false, nil) - case reflect.Map: - if in.Len() == 0 { - return - } - if out.IsNil() { - out.Set(reflect.MakeMap(in.Type())) - } - // For maps with value types of *T or []byte we need to deep copy each value. - elemKind := in.Type().Elem().Kind() - for _, key := range in.MapKeys() { - var val reflect.Value - switch elemKind { - case reflect.Ptr: - val = reflect.New(in.Type().Elem().Elem()) - mergeAny(val, in.MapIndex(key), false, nil) - case reflect.Slice: - val = in.MapIndex(key) - val = reflect.ValueOf(append([]byte{}, val.Bytes()...)) - default: - val = in.MapIndex(key) - } - out.SetMapIndex(key, val) - } - case reflect.Ptr: - if in.IsNil() { - return - } - if out.IsNil() { - out.Set(reflect.New(in.Elem().Type())) - } - mergeAny(out.Elem(), in.Elem(), true, nil) - case reflect.Slice: - if in.IsNil() { - return - } - if in.Type().Elem().Kind() == reflect.Uint8 { - // []byte is a scalar bytes field, not a repeated field. - - // Edge case: if this is in a proto3 message, a zero length - // bytes field is considered the zero value, and should not - // be merged. - if prop != nil && prop.proto3 && in.Len() == 0 { - return - } - - // Make a deep copy. - // Append to []byte{} instead of []byte(nil) so that we never end up - // with a nil result. - out.SetBytes(append([]byte{}, in.Bytes()...)) - return - } - n := in.Len() - if out.IsNil() { - out.Set(reflect.MakeSlice(in.Type(), 0, n)) - } - switch in.Type().Elem().Kind() { - case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, - reflect.String, reflect.Uint32, reflect.Uint64: - out.Set(reflect.AppendSlice(out, in)) - default: - for i := 0; i < n; i++ { - x := reflect.Indirect(reflect.New(in.Type().Elem())) - mergeAny(x, in.Index(i), false, nil) - out.Set(reflect.Append(out, x)) - } - } - case reflect.Struct: - mergeStruct(out, in) - default: - // unknown type, so not a protocol buffer - log.Printf("proto: don't know how to copy %v", in) - } -} - -func mergeExtension(out, in map[int32]Extension) { - for extNum, eIn := range in { - eOut := Extension{desc: eIn.desc} - if eIn.value != nil { - v := reflect.New(reflect.TypeOf(eIn.value)).Elem() - mergeAny(v, reflect.ValueOf(eIn.value), false, nil) - eOut.value = v.Interface() - } - if eIn.enc != nil { - eOut.enc = make([]byte, len(eIn.enc)) - copy(eOut.enc, eIn.enc) - } - - out[extNum] = eOut - } -} diff --git a/vendor/github.com/golang/protobuf/proto/decode.go b/vendor/github.com/golang/protobuf/proto/decode.go deleted file mode 100644 index aa207298f997665117f3ba88e65646f95c83f08a..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/decode.go +++ /dev/null @@ -1,970 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -/* - * Routines for decoding protocol buffer data to construct in-memory representations. - */ - -import ( - "errors" - "fmt" - "io" - "os" - "reflect" -) - -// errOverflow is returned when an integer is too large to be represented. -var errOverflow = errors.New("proto: integer overflow") - -// ErrInternalBadWireType is returned by generated code when an incorrect -// wire type is encountered. It does not get returned to user code. -var ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof") - -// The fundamental decoders that interpret bytes on the wire. -// Those that take integer types all return uint64 and are -// therefore of type valueDecoder. - -// DecodeVarint reads a varint-encoded integer from the slice. -// It returns the integer and the number of bytes consumed, or -// zero if there is not enough. -// This is the format for the -// int32, int64, uint32, uint64, bool, and enum -// protocol buffer types. -func DecodeVarint(buf []byte) (x uint64, n int) { - for shift := uint(0); shift < 64; shift += 7 { - if n >= len(buf) { - return 0, 0 - } - b := uint64(buf[n]) - n++ - x |= (b & 0x7F) << shift - if (b & 0x80) == 0 { - return x, n - } - } - - // The number is too large to represent in a 64-bit value. - return 0, 0 -} - -func (p *Buffer) decodeVarintSlow() (x uint64, err error) { - i := p.index - l := len(p.buf) - - for shift := uint(0); shift < 64; shift += 7 { - if i >= l { - err = io.ErrUnexpectedEOF - return - } - b := p.buf[i] - i++ - x |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - p.index = i - return - } - } - - // The number is too large to represent in a 64-bit value. - err = errOverflow - return -} - -// DecodeVarint reads a varint-encoded integer from the Buffer. -// This is the format for the -// int32, int64, uint32, uint64, bool, and enum -// protocol buffer types. -func (p *Buffer) DecodeVarint() (x uint64, err error) { - i := p.index - buf := p.buf - - if i >= len(buf) { - return 0, io.ErrUnexpectedEOF - } else if buf[i] < 0x80 { - p.index++ - return uint64(buf[i]), nil - } else if len(buf)-i < 10 { - return p.decodeVarintSlow() - } - - var b uint64 - // we already checked the first byte - x = uint64(buf[i]) - 0x80 - i++ - - b = uint64(buf[i]) - i++ - x += b << 7 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 7 - - b = uint64(buf[i]) - i++ - x += b << 14 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 14 - - b = uint64(buf[i]) - i++ - x += b << 21 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 21 - - b = uint64(buf[i]) - i++ - x += b << 28 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 28 - - b = uint64(buf[i]) - i++ - x += b << 35 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 35 - - b = uint64(buf[i]) - i++ - x += b << 42 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 42 - - b = uint64(buf[i]) - i++ - x += b << 49 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 49 - - b = uint64(buf[i]) - i++ - x += b << 56 - if b&0x80 == 0 { - goto done - } - x -= 0x80 << 56 - - b = uint64(buf[i]) - i++ - x += b << 63 - if b&0x80 == 0 { - goto done - } - // x -= 0x80 << 63 // Always zero. - - return 0, errOverflow - -done: - p.index = i - return x, nil -} - -// DecodeFixed64 reads a 64-bit integer from the Buffer. -// This is the format for the -// fixed64, sfixed64, and double protocol buffer types. -func (p *Buffer) DecodeFixed64() (x uint64, err error) { - // x, err already 0 - i := p.index + 8 - if i < 0 || i > len(p.buf) { - err = io.ErrUnexpectedEOF - return - } - p.index = i - - x = uint64(p.buf[i-8]) - x |= uint64(p.buf[i-7]) << 8 - x |= uint64(p.buf[i-6]) << 16 - x |= uint64(p.buf[i-5]) << 24 - x |= uint64(p.buf[i-4]) << 32 - x |= uint64(p.buf[i-3]) << 40 - x |= uint64(p.buf[i-2]) << 48 - x |= uint64(p.buf[i-1]) << 56 - return -} - -// DecodeFixed32 reads a 32-bit integer from the Buffer. -// This is the format for the -// fixed32, sfixed32, and float protocol buffer types. -func (p *Buffer) DecodeFixed32() (x uint64, err error) { - // x, err already 0 - i := p.index + 4 - if i < 0 || i > len(p.buf) { - err = io.ErrUnexpectedEOF - return - } - p.index = i - - x = uint64(p.buf[i-4]) - x |= uint64(p.buf[i-3]) << 8 - x |= uint64(p.buf[i-2]) << 16 - x |= uint64(p.buf[i-1]) << 24 - return -} - -// DecodeZigzag64 reads a zigzag-encoded 64-bit integer -// from the Buffer. -// This is the format used for the sint64 protocol buffer type. -func (p *Buffer) DecodeZigzag64() (x uint64, err error) { - x, err = p.DecodeVarint() - if err != nil { - return - } - x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63) - return -} - -// DecodeZigzag32 reads a zigzag-encoded 32-bit integer -// from the Buffer. -// This is the format used for the sint32 protocol buffer type. -func (p *Buffer) DecodeZigzag32() (x uint64, err error) { - x, err = p.DecodeVarint() - if err != nil { - return - } - x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31)) - return -} - -// These are not ValueDecoders: they produce an array of bytes or a string. -// bytes, embedded messages - -// DecodeRawBytes reads a count-delimited byte buffer from the Buffer. -// This is the format used for the bytes protocol buffer -// type and for embedded messages. -func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) { - n, err := p.DecodeVarint() - if err != nil { - return nil, err - } - - nb := int(n) - if nb < 0 { - return nil, fmt.Errorf("proto: bad byte length %d", nb) - } - end := p.index + nb - if end < p.index || end > len(p.buf) { - return nil, io.ErrUnexpectedEOF - } - - if !alloc { - // todo: check if can get more uses of alloc=false - buf = p.buf[p.index:end] - p.index += nb - return - } - - buf = make([]byte, nb) - copy(buf, p.buf[p.index:]) - p.index += nb - return -} - -// DecodeStringBytes reads an encoded string from the Buffer. -// This is the format used for the proto2 string type. -func (p *Buffer) DecodeStringBytes() (s string, err error) { - buf, err := p.DecodeRawBytes(false) - if err != nil { - return - } - return string(buf), nil -} - -// Skip the next item in the buffer. Its wire type is decoded and presented as an argument. -// If the protocol buffer has extensions, and the field matches, add it as an extension. -// Otherwise, if the XXX_unrecognized field exists, append the skipped data there. -func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base structPointer, unrecField field) error { - oi := o.index - - err := o.skip(t, tag, wire) - if err != nil { - return err - } - - if !unrecField.IsValid() { - return nil - } - - ptr := structPointer_Bytes(base, unrecField) - - // Add the skipped field to struct field - obuf := o.buf - - o.buf = *ptr - o.EncodeVarint(uint64(tag<<3 | wire)) - *ptr = append(o.buf, obuf[oi:o.index]...) - - o.buf = obuf - - return nil -} - -// Skip the next item in the buffer. Its wire type is decoded and presented as an argument. -func (o *Buffer) skip(t reflect.Type, tag, wire int) error { - - var u uint64 - var err error - - switch wire { - case WireVarint: - _, err = o.DecodeVarint() - case WireFixed64: - _, err = o.DecodeFixed64() - case WireBytes: - _, err = o.DecodeRawBytes(false) - case WireFixed32: - _, err = o.DecodeFixed32() - case WireStartGroup: - for { - u, err = o.DecodeVarint() - if err != nil { - break - } - fwire := int(u & 0x7) - if fwire == WireEndGroup { - break - } - ftag := int(u >> 3) - err = o.skip(t, ftag, fwire) - if err != nil { - break - } - } - default: - err = fmt.Errorf("proto: can't skip unknown wire type %d for %s", wire, t) - } - return err -} - -// Unmarshaler is the interface representing objects that can -// unmarshal themselves. The method should reset the receiver before -// decoding starts. The argument points to data that may be -// overwritten, so implementations should not keep references to the -// buffer. -type Unmarshaler interface { - Unmarshal([]byte) error -} - -// Unmarshal parses the protocol buffer representation in buf and places the -// decoded result in pb. If the struct underlying pb does not match -// the data in buf, the results can be unpredictable. -// -// Unmarshal resets pb before starting to unmarshal, so any -// existing data in pb is always removed. Use UnmarshalMerge -// to preserve and append to existing data. -func Unmarshal(buf []byte, pb Message) error { - pb.Reset() - return UnmarshalMerge(buf, pb) -} - -// UnmarshalMerge parses the protocol buffer representation in buf and -// writes the decoded result to pb. If the struct underlying pb does not match -// the data in buf, the results can be unpredictable. -// -// UnmarshalMerge merges into existing data in pb. -// Most code should use Unmarshal instead. -func UnmarshalMerge(buf []byte, pb Message) error { - // If the object can unmarshal itself, let it. - if u, ok := pb.(Unmarshaler); ok { - return u.Unmarshal(buf) - } - return NewBuffer(buf).Unmarshal(pb) -} - -// DecodeMessage reads a count-delimited message from the Buffer. -func (p *Buffer) DecodeMessage(pb Message) error { - enc, err := p.DecodeRawBytes(false) - if err != nil { - return err - } - return NewBuffer(enc).Unmarshal(pb) -} - -// DecodeGroup reads a tag-delimited group from the Buffer. -func (p *Buffer) DecodeGroup(pb Message) error { - typ, base, err := getbase(pb) - if err != nil { - return err - } - return p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), true, base) -} - -// Unmarshal parses the protocol buffer representation in the -// Buffer and places the decoded result in pb. If the struct -// underlying pb does not match the data in the buffer, the results can be -// unpredictable. -// -// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal. -func (p *Buffer) Unmarshal(pb Message) error { - // If the object can unmarshal itself, let it. - if u, ok := pb.(Unmarshaler); ok { - err := u.Unmarshal(p.buf[p.index:]) - p.index = len(p.buf) - return err - } - - typ, base, err := getbase(pb) - if err != nil { - return err - } - - err = p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), false, base) - - if collectStats { - stats.Decode++ - } - - return err -} - -// unmarshalType does the work of unmarshaling a structure. -func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group bool, base structPointer) error { - var state errorState - required, reqFields := prop.reqCount, uint64(0) - - var err error - for err == nil && o.index < len(o.buf) { - oi := o.index - var u uint64 - u, err = o.DecodeVarint() - if err != nil { - break - } - wire := int(u & 0x7) - if wire == WireEndGroup { - if is_group { - if required > 0 { - // Not enough information to determine the exact field. - // (See below.) - return &RequiredNotSetError{"{Unknown}"} - } - return nil // input is satisfied - } - return fmt.Errorf("proto: %s: wiretype end group for non-group", st) - } - tag := int(u >> 3) - if tag <= 0 { - return fmt.Errorf("proto: %s: illegal tag %d (wire type %d)", st, tag, wire) - } - fieldnum, ok := prop.decoderTags.get(tag) - if !ok { - // Maybe it's an extension? - if prop.extendable { - if e, _ := extendable(structPointer_Interface(base, st)); isExtensionField(e, int32(tag)) { - if err = o.skip(st, tag, wire); err == nil { - extmap := e.extensionsWrite() - ext := extmap[int32(tag)] // may be missing - ext.enc = append(ext.enc, o.buf[oi:o.index]...) - extmap[int32(tag)] = ext - } - continue - } - } - // Maybe it's a oneof? - if prop.oneofUnmarshaler != nil { - m := structPointer_Interface(base, st).(Message) - // First return value indicates whether tag is a oneof field. - ok, err = prop.oneofUnmarshaler(m, tag, wire, o) - if err == ErrInternalBadWireType { - // Map the error to something more descriptive. - // Do the formatting here to save generated code space. - err = fmt.Errorf("bad wiretype for oneof field in %T", m) - } - if ok { - continue - } - } - err = o.skipAndSave(st, tag, wire, base, prop.unrecField) - continue - } - p := prop.Prop[fieldnum] - - if p.dec == nil { - fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", st, st.Field(fieldnum).Name) - continue - } - dec := p.dec - if wire != WireStartGroup && wire != p.WireType { - if wire == WireBytes && p.packedDec != nil { - // a packable field - dec = p.packedDec - } else { - err = fmt.Errorf("proto: bad wiretype for field %s.%s: got wiretype %d, want %d", st, st.Field(fieldnum).Name, wire, p.WireType) - continue - } - } - decErr := dec(o, p, base) - if decErr != nil && !state.shouldContinue(decErr, p) { - err = decErr - } - if err == nil && p.Required { - // Successfully decoded a required field. - if tag <= 64 { - // use bitmap for fields 1-64 to catch field reuse. - var mask uint64 = 1 << uint64(tag-1) - if reqFields&mask == 0 { - // new required field - reqFields |= mask - required-- - } - } else { - // This is imprecise. It can be fooled by a required field - // with a tag > 64 that is encoded twice; that's very rare. - // A fully correct implementation would require allocating - // a data structure, which we would like to avoid. - required-- - } - } - } - if err == nil { - if is_group { - return io.ErrUnexpectedEOF - } - if state.err != nil { - return state.err - } - if required > 0 { - // Not enough information to determine the exact field. If we use extra - // CPU, we could determine the field only if the missing required field - // has a tag <= 64 and we check reqFields. - return &RequiredNotSetError{"{Unknown}"} - } - } - return err -} - -// Individual type decoders -// For each, -// u is the decoded value, -// v is a pointer to the field (pointer) in the struct - -// Sizes of the pools to allocate inside the Buffer. -// The goal is modest amortization and allocation -// on at least 16-byte boundaries. -const ( - boolPoolSize = 16 - uint32PoolSize = 8 - uint64PoolSize = 4 -) - -// Decode a bool. -func (o *Buffer) dec_bool(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - if len(o.bools) == 0 { - o.bools = make([]bool, boolPoolSize) - } - o.bools[0] = u != 0 - *structPointer_Bool(base, p.field) = &o.bools[0] - o.bools = o.bools[1:] - return nil -} - -func (o *Buffer) dec_proto3_bool(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - *structPointer_BoolVal(base, p.field) = u != 0 - return nil -} - -// Decode an int32. -func (o *Buffer) dec_int32(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - word32_Set(structPointer_Word32(base, p.field), o, uint32(u)) - return nil -} - -func (o *Buffer) dec_proto3_int32(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - word32Val_Set(structPointer_Word32Val(base, p.field), uint32(u)) - return nil -} - -// Decode an int64. -func (o *Buffer) dec_int64(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - word64_Set(structPointer_Word64(base, p.field), o, u) - return nil -} - -func (o *Buffer) dec_proto3_int64(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - word64Val_Set(structPointer_Word64Val(base, p.field), o, u) - return nil -} - -// Decode a string. -func (o *Buffer) dec_string(p *Properties, base structPointer) error { - s, err := o.DecodeStringBytes() - if err != nil { - return err - } - *structPointer_String(base, p.field) = &s - return nil -} - -func (o *Buffer) dec_proto3_string(p *Properties, base structPointer) error { - s, err := o.DecodeStringBytes() - if err != nil { - return err - } - *structPointer_StringVal(base, p.field) = s - return nil -} - -// Decode a slice of bytes ([]byte). -func (o *Buffer) dec_slice_byte(p *Properties, base structPointer) error { - b, err := o.DecodeRawBytes(true) - if err != nil { - return err - } - *structPointer_Bytes(base, p.field) = b - return nil -} - -// Decode a slice of bools ([]bool). -func (o *Buffer) dec_slice_bool(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - v := structPointer_BoolSlice(base, p.field) - *v = append(*v, u != 0) - return nil -} - -// Decode a slice of bools ([]bool) in packed format. -func (o *Buffer) dec_slice_packed_bool(p *Properties, base structPointer) error { - v := structPointer_BoolSlice(base, p.field) - - nn, err := o.DecodeVarint() - if err != nil { - return err - } - nb := int(nn) // number of bytes of encoded bools - fin := o.index + nb - if fin < o.index { - return errOverflow - } - - y := *v - for o.index < fin { - u, err := p.valDec(o) - if err != nil { - return err - } - y = append(y, u != 0) - } - - *v = y - return nil -} - -// Decode a slice of int32s ([]int32). -func (o *Buffer) dec_slice_int32(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - structPointer_Word32Slice(base, p.field).Append(uint32(u)) - return nil -} - -// Decode a slice of int32s ([]int32) in packed format. -func (o *Buffer) dec_slice_packed_int32(p *Properties, base structPointer) error { - v := structPointer_Word32Slice(base, p.field) - - nn, err := o.DecodeVarint() - if err != nil { - return err - } - nb := int(nn) // number of bytes of encoded int32s - - fin := o.index + nb - if fin < o.index { - return errOverflow - } - for o.index < fin { - u, err := p.valDec(o) - if err != nil { - return err - } - v.Append(uint32(u)) - } - return nil -} - -// Decode a slice of int64s ([]int64). -func (o *Buffer) dec_slice_int64(p *Properties, base structPointer) error { - u, err := p.valDec(o) - if err != nil { - return err - } - - structPointer_Word64Slice(base, p.field).Append(u) - return nil -} - -// Decode a slice of int64s ([]int64) in packed format. -func (o *Buffer) dec_slice_packed_int64(p *Properties, base structPointer) error { - v := structPointer_Word64Slice(base, p.field) - - nn, err := o.DecodeVarint() - if err != nil { - return err - } - nb := int(nn) // number of bytes of encoded int64s - - fin := o.index + nb - if fin < o.index { - return errOverflow - } - for o.index < fin { - u, err := p.valDec(o) - if err != nil { - return err - } - v.Append(u) - } - return nil -} - -// Decode a slice of strings ([]string). -func (o *Buffer) dec_slice_string(p *Properties, base structPointer) error { - s, err := o.DecodeStringBytes() - if err != nil { - return err - } - v := structPointer_StringSlice(base, p.field) - *v = append(*v, s) - return nil -} - -// Decode a slice of slice of bytes ([][]byte). -func (o *Buffer) dec_slice_slice_byte(p *Properties, base structPointer) error { - b, err := o.DecodeRawBytes(true) - if err != nil { - return err - } - v := structPointer_BytesSlice(base, p.field) - *v = append(*v, b) - return nil -} - -// Decode a map field. -func (o *Buffer) dec_new_map(p *Properties, base structPointer) error { - raw, err := o.DecodeRawBytes(false) - if err != nil { - return err - } - oi := o.index // index at the end of this map entry - o.index -= len(raw) // move buffer back to start of map entry - - mptr := structPointer_NewAt(base, p.field, p.mtype) // *map[K]V - if mptr.Elem().IsNil() { - mptr.Elem().Set(reflect.MakeMap(mptr.Type().Elem())) - } - v := mptr.Elem() // map[K]V - - // Prepare addressable doubly-indirect placeholders for the key and value types. - // See enc_new_map for why. - keyptr := reflect.New(reflect.PtrTo(p.mtype.Key())).Elem() // addressable *K - keybase := toStructPointer(keyptr.Addr()) // **K - - var valbase structPointer - var valptr reflect.Value - switch p.mtype.Elem().Kind() { - case reflect.Slice: - // []byte - var dummy []byte - valptr = reflect.ValueOf(&dummy) // *[]byte - valbase = toStructPointer(valptr) // *[]byte - case reflect.Ptr: - // message; valptr is **Msg; need to allocate the intermediate pointer - valptr = reflect.New(reflect.PtrTo(p.mtype.Elem())).Elem() // addressable *V - valptr.Set(reflect.New(valptr.Type().Elem())) - valbase = toStructPointer(valptr) - default: - // everything else - valptr = reflect.New(reflect.PtrTo(p.mtype.Elem())).Elem() // addressable *V - valbase = toStructPointer(valptr.Addr()) // **V - } - - // Decode. - // This parses a restricted wire format, namely the encoding of a message - // with two fields. See enc_new_map for the format. - for o.index < oi { - // tagcode for key and value properties are always a single byte - // because they have tags 1 and 2. - tagcode := o.buf[o.index] - o.index++ - switch tagcode { - case p.mkeyprop.tagcode[0]: - if err := p.mkeyprop.dec(o, p.mkeyprop, keybase); err != nil { - return err - } - case p.mvalprop.tagcode[0]: - if err := p.mvalprop.dec(o, p.mvalprop, valbase); err != nil { - return err - } - default: - // TODO: Should we silently skip this instead? - return fmt.Errorf("proto: bad map data tag %d", raw[0]) - } - } - keyelem, valelem := keyptr.Elem(), valptr.Elem() - if !keyelem.IsValid() { - keyelem = reflect.Zero(p.mtype.Key()) - } - if !valelem.IsValid() { - valelem = reflect.Zero(p.mtype.Elem()) - } - - v.SetMapIndex(keyelem, valelem) - return nil -} - -// Decode a group. -func (o *Buffer) dec_struct_group(p *Properties, base structPointer) error { - bas := structPointer_GetStructPointer(base, p.field) - if structPointer_IsNil(bas) { - // allocate new nested message - bas = toStructPointer(reflect.New(p.stype)) - structPointer_SetStructPointer(base, p.field, bas) - } - return o.unmarshalType(p.stype, p.sprop, true, bas) -} - -// Decode an embedded message. -func (o *Buffer) dec_struct_message(p *Properties, base structPointer) (err error) { - raw, e := o.DecodeRawBytes(false) - if e != nil { - return e - } - - bas := structPointer_GetStructPointer(base, p.field) - if structPointer_IsNil(bas) { - // allocate new nested message - bas = toStructPointer(reflect.New(p.stype)) - structPointer_SetStructPointer(base, p.field, bas) - } - - // If the object can unmarshal itself, let it. - if p.isUnmarshaler { - iv := structPointer_Interface(bas, p.stype) - return iv.(Unmarshaler).Unmarshal(raw) - } - - obuf := o.buf - oi := o.index - o.buf = raw - o.index = 0 - - err = o.unmarshalType(p.stype, p.sprop, false, bas) - o.buf = obuf - o.index = oi - - return err -} - -// Decode a slice of embedded messages. -func (o *Buffer) dec_slice_struct_message(p *Properties, base structPointer) error { - return o.dec_slice_struct(p, false, base) -} - -// Decode a slice of embedded groups. -func (o *Buffer) dec_slice_struct_group(p *Properties, base structPointer) error { - return o.dec_slice_struct(p, true, base) -} - -// Decode a slice of structs ([]*struct). -func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base structPointer) error { - v := reflect.New(p.stype) - bas := toStructPointer(v) - structPointer_StructPointerSlice(base, p.field).Append(bas) - - if is_group { - err := o.unmarshalType(p.stype, p.sprop, is_group, bas) - return err - } - - raw, err := o.DecodeRawBytes(false) - if err != nil { - return err - } - - // If the object can unmarshal itself, let it. - if p.isUnmarshaler { - iv := v.Interface() - return iv.(Unmarshaler).Unmarshal(raw) - } - - obuf := o.buf - oi := o.index - o.buf = raw - o.index = 0 - - err = o.unmarshalType(p.stype, p.sprop, is_group, bas) - - o.buf = obuf - o.index = oi - - return err -} diff --git a/vendor/github.com/golang/protobuf/proto/encode.go b/vendor/github.com/golang/protobuf/proto/encode.go deleted file mode 100644 index 8b84d1b22d4c0933820cb4872e29c918e5429be2..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/encode.go +++ /dev/null @@ -1,1362 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -/* - * Routines for encoding data into the wire format for protocol buffers. - */ - -import ( - "errors" - "fmt" - "reflect" - "sort" -) - -// RequiredNotSetError is the error returned if Marshal is called with -// a protocol buffer struct whose required fields have not -// all been initialized. It is also the error returned if Unmarshal is -// called with an encoded protocol buffer that does not include all the -// required fields. -// -// When printed, RequiredNotSetError reports the first unset required field in a -// message. If the field cannot be precisely determined, it is reported as -// "{Unknown}". -type RequiredNotSetError struct { - field string -} - -func (e *RequiredNotSetError) Error() string { - return fmt.Sprintf("proto: required field %q not set", e.field) -} - -var ( - // errRepeatedHasNil is the error returned if Marshal is called with - // a struct with a repeated field containing a nil element. - errRepeatedHasNil = errors.New("proto: repeated field has nil element") - - // errOneofHasNil is the error returned if Marshal is called with - // a struct with a oneof field containing a nil element. - errOneofHasNil = errors.New("proto: oneof field has nil value") - - // ErrNil is the error returned if Marshal is called with nil. - ErrNil = errors.New("proto: Marshal called with nil") - - // ErrTooLarge is the error returned if Marshal is called with a - // message that encodes to >2GB. - ErrTooLarge = errors.New("proto: message encodes to over 2 GB") -) - -// The fundamental encoders that put bytes on the wire. -// Those that take integer types all accept uint64 and are -// therefore of type valueEncoder. - -const maxVarintBytes = 10 // maximum length of a varint - -// maxMarshalSize is the largest allowed size of an encoded protobuf, -// since C++ and Java use signed int32s for the size. -const maxMarshalSize = 1<<31 - 1 - -// EncodeVarint returns the varint encoding of x. -// This is the format for the -// int32, int64, uint32, uint64, bool, and enum -// protocol buffer types. -// Not used by the package itself, but helpful to clients -// wishing to use the same encoding. -func EncodeVarint(x uint64) []byte { - var buf [maxVarintBytes]byte - var n int - for n = 0; x > 127; n++ { - buf[n] = 0x80 | uint8(x&0x7F) - x >>= 7 - } - buf[n] = uint8(x) - n++ - return buf[0:n] -} - -// EncodeVarint writes a varint-encoded integer to the Buffer. -// This is the format for the -// int32, int64, uint32, uint64, bool, and enum -// protocol buffer types. -func (p *Buffer) EncodeVarint(x uint64) error { - for x >= 1<<7 { - p.buf = append(p.buf, uint8(x&0x7f|0x80)) - x >>= 7 - } - p.buf = append(p.buf, uint8(x)) - return nil -} - -// SizeVarint returns the varint encoding size of an integer. -func SizeVarint(x uint64) int { - return sizeVarint(x) -} - -func sizeVarint(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} - -// EncodeFixed64 writes a 64-bit integer to the Buffer. -// This is the format for the -// fixed64, sfixed64, and double protocol buffer types. -func (p *Buffer) EncodeFixed64(x uint64) error { - p.buf = append(p.buf, - uint8(x), - uint8(x>>8), - uint8(x>>16), - uint8(x>>24), - uint8(x>>32), - uint8(x>>40), - uint8(x>>48), - uint8(x>>56)) - return nil -} - -func sizeFixed64(x uint64) int { - return 8 -} - -// EncodeFixed32 writes a 32-bit integer to the Buffer. -// This is the format for the -// fixed32, sfixed32, and float protocol buffer types. -func (p *Buffer) EncodeFixed32(x uint64) error { - p.buf = append(p.buf, - uint8(x), - uint8(x>>8), - uint8(x>>16), - uint8(x>>24)) - return nil -} - -func sizeFixed32(x uint64) int { - return 4 -} - -// EncodeZigzag64 writes a zigzag-encoded 64-bit integer -// to the Buffer. -// This is the format used for the sint64 protocol buffer type. -func (p *Buffer) EncodeZigzag64(x uint64) error { - // use signed number to get arithmetic right shift. - return p.EncodeVarint((x << 1) ^ uint64((int64(x) >> 63))) -} - -func sizeZigzag64(x uint64) int { - return sizeVarint((x << 1) ^ uint64((int64(x) >> 63))) -} - -// EncodeZigzag32 writes a zigzag-encoded 32-bit integer -// to the Buffer. -// This is the format used for the sint32 protocol buffer type. -func (p *Buffer) EncodeZigzag32(x uint64) error { - // use signed number to get arithmetic right shift. - return p.EncodeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31)))) -} - -func sizeZigzag32(x uint64) int { - return sizeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31)))) -} - -// EncodeRawBytes writes a count-delimited byte buffer to the Buffer. -// This is the format used for the bytes protocol buffer -// type and for embedded messages. -func (p *Buffer) EncodeRawBytes(b []byte) error { - p.EncodeVarint(uint64(len(b))) - p.buf = append(p.buf, b...) - return nil -} - -func sizeRawBytes(b []byte) int { - return sizeVarint(uint64(len(b))) + - len(b) -} - -// EncodeStringBytes writes an encoded string to the Buffer. -// This is the format used for the proto2 string type. -func (p *Buffer) EncodeStringBytes(s string) error { - p.EncodeVarint(uint64(len(s))) - p.buf = append(p.buf, s...) - return nil -} - -func sizeStringBytes(s string) int { - return sizeVarint(uint64(len(s))) + - len(s) -} - -// Marshaler is the interface representing objects that can marshal themselves. -type Marshaler interface { - Marshal() ([]byte, error) -} - -// Marshal takes the protocol buffer -// and encodes it into the wire format, returning the data. -func Marshal(pb Message) ([]byte, error) { - // Can the object marshal itself? - if m, ok := pb.(Marshaler); ok { - return m.Marshal() - } - p := NewBuffer(nil) - err := p.Marshal(pb) - if p.buf == nil && err == nil { - // Return a non-nil slice on success. - return []byte{}, nil - } - return p.buf, err -} - -// EncodeMessage writes the protocol buffer to the Buffer, -// prefixed by a varint-encoded length. -func (p *Buffer) EncodeMessage(pb Message) error { - t, base, err := getbase(pb) - if structPointer_IsNil(base) { - return ErrNil - } - if err == nil { - var state errorState - err = p.enc_len_struct(GetProperties(t.Elem()), base, &state) - } - return err -} - -// Marshal takes the protocol buffer -// and encodes it into the wire format, writing the result to the -// Buffer. -func (p *Buffer) Marshal(pb Message) error { - // Can the object marshal itself? - if m, ok := pb.(Marshaler); ok { - data, err := m.Marshal() - p.buf = append(p.buf, data...) - return err - } - - t, base, err := getbase(pb) - if structPointer_IsNil(base) { - return ErrNil - } - if err == nil { - err = p.enc_struct(GetProperties(t.Elem()), base) - } - - if collectStats { - (stats).Encode++ // Parens are to work around a goimports bug. - } - - if len(p.buf) > maxMarshalSize { - return ErrTooLarge - } - return err -} - -// Size returns the encoded size of a protocol buffer. -func Size(pb Message) (n int) { - // Can the object marshal itself? If so, Size is slow. - // TODO: add Size to Marshaler, or add a Sizer interface. - if m, ok := pb.(Marshaler); ok { - b, _ := m.Marshal() - return len(b) - } - - t, base, err := getbase(pb) - if structPointer_IsNil(base) { - return 0 - } - if err == nil { - n = size_struct(GetProperties(t.Elem()), base) - } - - if collectStats { - (stats).Size++ // Parens are to work around a goimports bug. - } - - return -} - -// Individual type encoders. - -// Encode a bool. -func (o *Buffer) enc_bool(p *Properties, base structPointer) error { - v := *structPointer_Bool(base, p.field) - if v == nil { - return ErrNil - } - x := 0 - if *v { - x = 1 - } - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, uint64(x)) - return nil -} - -func (o *Buffer) enc_proto3_bool(p *Properties, base structPointer) error { - v := *structPointer_BoolVal(base, p.field) - if !v { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, 1) - return nil -} - -func size_bool(p *Properties, base structPointer) int { - v := *structPointer_Bool(base, p.field) - if v == nil { - return 0 - } - return len(p.tagcode) + 1 // each bool takes exactly one byte -} - -func size_proto3_bool(p *Properties, base structPointer) int { - v := *structPointer_BoolVal(base, p.field) - if !v && !p.oneof { - return 0 - } - return len(p.tagcode) + 1 // each bool takes exactly one byte -} - -// Encode an int32. -func (o *Buffer) enc_int32(p *Properties, base structPointer) error { - v := structPointer_Word32(base, p.field) - if word32_IsNil(v) { - return ErrNil - } - x := int32(word32_Get(v)) // permit sign extension to use full 64-bit range - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, uint64(x)) - return nil -} - -func (o *Buffer) enc_proto3_int32(p *Properties, base structPointer) error { - v := structPointer_Word32Val(base, p.field) - x := int32(word32Val_Get(v)) // permit sign extension to use full 64-bit range - if x == 0 { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, uint64(x)) - return nil -} - -func size_int32(p *Properties, base structPointer) (n int) { - v := structPointer_Word32(base, p.field) - if word32_IsNil(v) { - return 0 - } - x := int32(word32_Get(v)) // permit sign extension to use full 64-bit range - n += len(p.tagcode) - n += p.valSize(uint64(x)) - return -} - -func size_proto3_int32(p *Properties, base structPointer) (n int) { - v := structPointer_Word32Val(base, p.field) - x := int32(word32Val_Get(v)) // permit sign extension to use full 64-bit range - if x == 0 && !p.oneof { - return 0 - } - n += len(p.tagcode) - n += p.valSize(uint64(x)) - return -} - -// Encode a uint32. -// Exactly the same as int32, except for no sign extension. -func (o *Buffer) enc_uint32(p *Properties, base structPointer) error { - v := structPointer_Word32(base, p.field) - if word32_IsNil(v) { - return ErrNil - } - x := word32_Get(v) - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, uint64(x)) - return nil -} - -func (o *Buffer) enc_proto3_uint32(p *Properties, base structPointer) error { - v := structPointer_Word32Val(base, p.field) - x := word32Val_Get(v) - if x == 0 { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, uint64(x)) - return nil -} - -func size_uint32(p *Properties, base structPointer) (n int) { - v := structPointer_Word32(base, p.field) - if word32_IsNil(v) { - return 0 - } - x := word32_Get(v) - n += len(p.tagcode) - n += p.valSize(uint64(x)) - return -} - -func size_proto3_uint32(p *Properties, base structPointer) (n int) { - v := structPointer_Word32Val(base, p.field) - x := word32Val_Get(v) - if x == 0 && !p.oneof { - return 0 - } - n += len(p.tagcode) - n += p.valSize(uint64(x)) - return -} - -// Encode an int64. -func (o *Buffer) enc_int64(p *Properties, base structPointer) error { - v := structPointer_Word64(base, p.field) - if word64_IsNil(v) { - return ErrNil - } - x := word64_Get(v) - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, x) - return nil -} - -func (o *Buffer) enc_proto3_int64(p *Properties, base structPointer) error { - v := structPointer_Word64Val(base, p.field) - x := word64Val_Get(v) - if x == 0 { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, x) - return nil -} - -func size_int64(p *Properties, base structPointer) (n int) { - v := structPointer_Word64(base, p.field) - if word64_IsNil(v) { - return 0 - } - x := word64_Get(v) - n += len(p.tagcode) - n += p.valSize(x) - return -} - -func size_proto3_int64(p *Properties, base structPointer) (n int) { - v := structPointer_Word64Val(base, p.field) - x := word64Val_Get(v) - if x == 0 && !p.oneof { - return 0 - } - n += len(p.tagcode) - n += p.valSize(x) - return -} - -// Encode a string. -func (o *Buffer) enc_string(p *Properties, base structPointer) error { - v := *structPointer_String(base, p.field) - if v == nil { - return ErrNil - } - x := *v - o.buf = append(o.buf, p.tagcode...) - o.EncodeStringBytes(x) - return nil -} - -func (o *Buffer) enc_proto3_string(p *Properties, base structPointer) error { - v := *structPointer_StringVal(base, p.field) - if v == "" { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - o.EncodeStringBytes(v) - return nil -} - -func size_string(p *Properties, base structPointer) (n int) { - v := *structPointer_String(base, p.field) - if v == nil { - return 0 - } - x := *v - n += len(p.tagcode) - n += sizeStringBytes(x) - return -} - -func size_proto3_string(p *Properties, base structPointer) (n int) { - v := *structPointer_StringVal(base, p.field) - if v == "" && !p.oneof { - return 0 - } - n += len(p.tagcode) - n += sizeStringBytes(v) - return -} - -// All protocol buffer fields are nillable, but be careful. -func isNil(v reflect.Value) bool { - switch v.Kind() { - case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - return v.IsNil() - } - return false -} - -// Encode a message struct. -func (o *Buffer) enc_struct_message(p *Properties, base structPointer) error { - var state errorState - structp := structPointer_GetStructPointer(base, p.field) - if structPointer_IsNil(structp) { - return ErrNil - } - - // Can the object marshal itself? - if p.isMarshaler { - m := structPointer_Interface(structp, p.stype).(Marshaler) - data, err := m.Marshal() - if err != nil && !state.shouldContinue(err, nil) { - return err - } - o.buf = append(o.buf, p.tagcode...) - o.EncodeRawBytes(data) - return state.err - } - - o.buf = append(o.buf, p.tagcode...) - return o.enc_len_struct(p.sprop, structp, &state) -} - -func size_struct_message(p *Properties, base structPointer) int { - structp := structPointer_GetStructPointer(base, p.field) - if structPointer_IsNil(structp) { - return 0 - } - - // Can the object marshal itself? - if p.isMarshaler { - m := structPointer_Interface(structp, p.stype).(Marshaler) - data, _ := m.Marshal() - n0 := len(p.tagcode) - n1 := sizeRawBytes(data) - return n0 + n1 - } - - n0 := len(p.tagcode) - n1 := size_struct(p.sprop, structp) - n2 := sizeVarint(uint64(n1)) // size of encoded length - return n0 + n1 + n2 -} - -// Encode a group struct. -func (o *Buffer) enc_struct_group(p *Properties, base structPointer) error { - var state errorState - b := structPointer_GetStructPointer(base, p.field) - if structPointer_IsNil(b) { - return ErrNil - } - - o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup)) - err := o.enc_struct(p.sprop, b) - if err != nil && !state.shouldContinue(err, nil) { - return err - } - o.EncodeVarint(uint64((p.Tag << 3) | WireEndGroup)) - return state.err -} - -func size_struct_group(p *Properties, base structPointer) (n int) { - b := structPointer_GetStructPointer(base, p.field) - if structPointer_IsNil(b) { - return 0 - } - - n += sizeVarint(uint64((p.Tag << 3) | WireStartGroup)) - n += size_struct(p.sprop, b) - n += sizeVarint(uint64((p.Tag << 3) | WireEndGroup)) - return -} - -// Encode a slice of bools ([]bool). -func (o *Buffer) enc_slice_bool(p *Properties, base structPointer) error { - s := *structPointer_BoolSlice(base, p.field) - l := len(s) - if l == 0 { - return ErrNil - } - for _, x := range s { - o.buf = append(o.buf, p.tagcode...) - v := uint64(0) - if x { - v = 1 - } - p.valEnc(o, v) - } - return nil -} - -func size_slice_bool(p *Properties, base structPointer) int { - s := *structPointer_BoolSlice(base, p.field) - l := len(s) - if l == 0 { - return 0 - } - return l * (len(p.tagcode) + 1) // each bool takes exactly one byte -} - -// Encode a slice of bools ([]bool) in packed format. -func (o *Buffer) enc_slice_packed_bool(p *Properties, base structPointer) error { - s := *structPointer_BoolSlice(base, p.field) - l := len(s) - if l == 0 { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - o.EncodeVarint(uint64(l)) // each bool takes exactly one byte - for _, x := range s { - v := uint64(0) - if x { - v = 1 - } - p.valEnc(o, v) - } - return nil -} - -func size_slice_packed_bool(p *Properties, base structPointer) (n int) { - s := *structPointer_BoolSlice(base, p.field) - l := len(s) - if l == 0 { - return 0 - } - n += len(p.tagcode) - n += sizeVarint(uint64(l)) - n += l // each bool takes exactly one byte - return -} - -// Encode a slice of bytes ([]byte). -func (o *Buffer) enc_slice_byte(p *Properties, base structPointer) error { - s := *structPointer_Bytes(base, p.field) - if s == nil { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - o.EncodeRawBytes(s) - return nil -} - -func (o *Buffer) enc_proto3_slice_byte(p *Properties, base structPointer) error { - s := *structPointer_Bytes(base, p.field) - if len(s) == 0 { - return ErrNil - } - o.buf = append(o.buf, p.tagcode...) - o.EncodeRawBytes(s) - return nil -} - -func size_slice_byte(p *Properties, base structPointer) (n int) { - s := *structPointer_Bytes(base, p.field) - if s == nil && !p.oneof { - return 0 - } - n += len(p.tagcode) - n += sizeRawBytes(s) - return -} - -func size_proto3_slice_byte(p *Properties, base structPointer) (n int) { - s := *structPointer_Bytes(base, p.field) - if len(s) == 0 && !p.oneof { - return 0 - } - n += len(p.tagcode) - n += sizeRawBytes(s) - return -} - -// Encode a slice of int32s ([]int32). -func (o *Buffer) enc_slice_int32(p *Properties, base structPointer) error { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return ErrNil - } - for i := 0; i < l; i++ { - o.buf = append(o.buf, p.tagcode...) - x := int32(s.Index(i)) // permit sign extension to use full 64-bit range - p.valEnc(o, uint64(x)) - } - return nil -} - -func size_slice_int32(p *Properties, base structPointer) (n int) { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return 0 - } - for i := 0; i < l; i++ { - n += len(p.tagcode) - x := int32(s.Index(i)) // permit sign extension to use full 64-bit range - n += p.valSize(uint64(x)) - } - return -} - -// Encode a slice of int32s ([]int32) in packed format. -func (o *Buffer) enc_slice_packed_int32(p *Properties, base structPointer) error { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return ErrNil - } - // TODO: Reuse a Buffer. - buf := NewBuffer(nil) - for i := 0; i < l; i++ { - x := int32(s.Index(i)) // permit sign extension to use full 64-bit range - p.valEnc(buf, uint64(x)) - } - - o.buf = append(o.buf, p.tagcode...) - o.EncodeVarint(uint64(len(buf.buf))) - o.buf = append(o.buf, buf.buf...) - return nil -} - -func size_slice_packed_int32(p *Properties, base structPointer) (n int) { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return 0 - } - var bufSize int - for i := 0; i < l; i++ { - x := int32(s.Index(i)) // permit sign extension to use full 64-bit range - bufSize += p.valSize(uint64(x)) - } - - n += len(p.tagcode) - n += sizeVarint(uint64(bufSize)) - n += bufSize - return -} - -// Encode a slice of uint32s ([]uint32). -// Exactly the same as int32, except for no sign extension. -func (o *Buffer) enc_slice_uint32(p *Properties, base structPointer) error { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return ErrNil - } - for i := 0; i < l; i++ { - o.buf = append(o.buf, p.tagcode...) - x := s.Index(i) - p.valEnc(o, uint64(x)) - } - return nil -} - -func size_slice_uint32(p *Properties, base structPointer) (n int) { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return 0 - } - for i := 0; i < l; i++ { - n += len(p.tagcode) - x := s.Index(i) - n += p.valSize(uint64(x)) - } - return -} - -// Encode a slice of uint32s ([]uint32) in packed format. -// Exactly the same as int32, except for no sign extension. -func (o *Buffer) enc_slice_packed_uint32(p *Properties, base structPointer) error { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return ErrNil - } - // TODO: Reuse a Buffer. - buf := NewBuffer(nil) - for i := 0; i < l; i++ { - p.valEnc(buf, uint64(s.Index(i))) - } - - o.buf = append(o.buf, p.tagcode...) - o.EncodeVarint(uint64(len(buf.buf))) - o.buf = append(o.buf, buf.buf...) - return nil -} - -func size_slice_packed_uint32(p *Properties, base structPointer) (n int) { - s := structPointer_Word32Slice(base, p.field) - l := s.Len() - if l == 0 { - return 0 - } - var bufSize int - for i := 0; i < l; i++ { - bufSize += p.valSize(uint64(s.Index(i))) - } - - n += len(p.tagcode) - n += sizeVarint(uint64(bufSize)) - n += bufSize - return -} - -// Encode a slice of int64s ([]int64). -func (o *Buffer) enc_slice_int64(p *Properties, base structPointer) error { - s := structPointer_Word64Slice(base, p.field) - l := s.Len() - if l == 0 { - return ErrNil - } - for i := 0; i < l; i++ { - o.buf = append(o.buf, p.tagcode...) - p.valEnc(o, s.Index(i)) - } - return nil -} - -func size_slice_int64(p *Properties, base structPointer) (n int) { - s := structPointer_Word64Slice(base, p.field) - l := s.Len() - if l == 0 { - return 0 - } - for i := 0; i < l; i++ { - n += len(p.tagcode) - n += p.valSize(s.Index(i)) - } - return -} - -// Encode a slice of int64s ([]int64) in packed format. -func (o *Buffer) enc_slice_packed_int64(p *Properties, base structPointer) error { - s := structPointer_Word64Slice(base, p.field) - l := s.Len() - if l == 0 { - return ErrNil - } - // TODO: Reuse a Buffer. - buf := NewBuffer(nil) - for i := 0; i < l; i++ { - p.valEnc(buf, s.Index(i)) - } - - o.buf = append(o.buf, p.tagcode...) - o.EncodeVarint(uint64(len(buf.buf))) - o.buf = append(o.buf, buf.buf...) - return nil -} - -func size_slice_packed_int64(p *Properties, base structPointer) (n int) { - s := structPointer_Word64Slice(base, p.field) - l := s.Len() - if l == 0 { - return 0 - } - var bufSize int - for i := 0; i < l; i++ { - bufSize += p.valSize(s.Index(i)) - } - - n += len(p.tagcode) - n += sizeVarint(uint64(bufSize)) - n += bufSize - return -} - -// Encode a slice of slice of bytes ([][]byte). -func (o *Buffer) enc_slice_slice_byte(p *Properties, base structPointer) error { - ss := *structPointer_BytesSlice(base, p.field) - l := len(ss) - if l == 0 { - return ErrNil - } - for i := 0; i < l; i++ { - o.buf = append(o.buf, p.tagcode...) - o.EncodeRawBytes(ss[i]) - } - return nil -} - -func size_slice_slice_byte(p *Properties, base structPointer) (n int) { - ss := *structPointer_BytesSlice(base, p.field) - l := len(ss) - if l == 0 { - return 0 - } - n += l * len(p.tagcode) - for i := 0; i < l; i++ { - n += sizeRawBytes(ss[i]) - } - return -} - -// Encode a slice of strings ([]string). -func (o *Buffer) enc_slice_string(p *Properties, base structPointer) error { - ss := *structPointer_StringSlice(base, p.field) - l := len(ss) - for i := 0; i < l; i++ { - o.buf = append(o.buf, p.tagcode...) - o.EncodeStringBytes(ss[i]) - } - return nil -} - -func size_slice_string(p *Properties, base structPointer) (n int) { - ss := *structPointer_StringSlice(base, p.field) - l := len(ss) - n += l * len(p.tagcode) - for i := 0; i < l; i++ { - n += sizeStringBytes(ss[i]) - } - return -} - -// Encode a slice of message structs ([]*struct). -func (o *Buffer) enc_slice_struct_message(p *Properties, base structPointer) error { - var state errorState - s := structPointer_StructPointerSlice(base, p.field) - l := s.Len() - - for i := 0; i < l; i++ { - structp := s.Index(i) - if structPointer_IsNil(structp) { - return errRepeatedHasNil - } - - // Can the object marshal itself? - if p.isMarshaler { - m := structPointer_Interface(structp, p.stype).(Marshaler) - data, err := m.Marshal() - if err != nil && !state.shouldContinue(err, nil) { - return err - } - o.buf = append(o.buf, p.tagcode...) - o.EncodeRawBytes(data) - continue - } - - o.buf = append(o.buf, p.tagcode...) - err := o.enc_len_struct(p.sprop, structp, &state) - if err != nil && !state.shouldContinue(err, nil) { - if err == ErrNil { - return errRepeatedHasNil - } - return err - } - } - return state.err -} - -func size_slice_struct_message(p *Properties, base structPointer) (n int) { - s := structPointer_StructPointerSlice(base, p.field) - l := s.Len() - n += l * len(p.tagcode) - for i := 0; i < l; i++ { - structp := s.Index(i) - if structPointer_IsNil(structp) { - return // return the size up to this point - } - - // Can the object marshal itself? - if p.isMarshaler { - m := structPointer_Interface(structp, p.stype).(Marshaler) - data, _ := m.Marshal() - n += sizeRawBytes(data) - continue - } - - n0 := size_struct(p.sprop, structp) - n1 := sizeVarint(uint64(n0)) // size of encoded length - n += n0 + n1 - } - return -} - -// Encode a slice of group structs ([]*struct). -func (o *Buffer) enc_slice_struct_group(p *Properties, base structPointer) error { - var state errorState - s := structPointer_StructPointerSlice(base, p.field) - l := s.Len() - - for i := 0; i < l; i++ { - b := s.Index(i) - if structPointer_IsNil(b) { - return errRepeatedHasNil - } - - o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup)) - - err := o.enc_struct(p.sprop, b) - - if err != nil && !state.shouldContinue(err, nil) { - if err == ErrNil { - return errRepeatedHasNil - } - return err - } - - o.EncodeVarint(uint64((p.Tag << 3) | WireEndGroup)) - } - return state.err -} - -func size_slice_struct_group(p *Properties, base structPointer) (n int) { - s := structPointer_StructPointerSlice(base, p.field) - l := s.Len() - - n += l * sizeVarint(uint64((p.Tag<<3)|WireStartGroup)) - n += l * sizeVarint(uint64((p.Tag<<3)|WireEndGroup)) - for i := 0; i < l; i++ { - b := s.Index(i) - if structPointer_IsNil(b) { - return // return size up to this point - } - - n += size_struct(p.sprop, b) - } - return -} - -// Encode an extension map. -func (o *Buffer) enc_map(p *Properties, base structPointer) error { - exts := structPointer_ExtMap(base, p.field) - if err := encodeExtensionsMap(*exts); err != nil { - return err - } - - return o.enc_map_body(*exts) -} - -func (o *Buffer) enc_exts(p *Properties, base structPointer) error { - exts := structPointer_Extensions(base, p.field) - - v, mu := exts.extensionsRead() - if v == nil { - return nil - } - - mu.Lock() - defer mu.Unlock() - if err := encodeExtensionsMap(v); err != nil { - return err - } - - return o.enc_map_body(v) -} - -func (o *Buffer) enc_map_body(v map[int32]Extension) error { - // Fast-path for common cases: zero or one extensions. - if len(v) <= 1 { - for _, e := range v { - o.buf = append(o.buf, e.enc...) - } - return nil - } - - // Sort keys to provide a deterministic encoding. - keys := make([]int, 0, len(v)) - for k := range v { - keys = append(keys, int(k)) - } - sort.Ints(keys) - - for _, k := range keys { - o.buf = append(o.buf, v[int32(k)].enc...) - } - return nil -} - -func size_map(p *Properties, base structPointer) int { - v := structPointer_ExtMap(base, p.field) - return extensionsMapSize(*v) -} - -func size_exts(p *Properties, base structPointer) int { - v := structPointer_Extensions(base, p.field) - return extensionsSize(v) -} - -// Encode a map field. -func (o *Buffer) enc_new_map(p *Properties, base structPointer) error { - var state errorState // XXX: or do we need to plumb this through? - - /* - A map defined as - map<key_type, value_type> map_field = N; - is encoded in the same way as - message MapFieldEntry { - key_type key = 1; - value_type value = 2; - } - repeated MapFieldEntry map_field = N; - */ - - v := structPointer_NewAt(base, p.field, p.mtype).Elem() // map[K]V - if v.Len() == 0 { - return nil - } - - keycopy, valcopy, keybase, valbase := mapEncodeScratch(p.mtype) - - enc := func() error { - if err := p.mkeyprop.enc(o, p.mkeyprop, keybase); err != nil { - return err - } - if err := p.mvalprop.enc(o, p.mvalprop, valbase); err != nil && err != ErrNil { - return err - } - return nil - } - - // Don't sort map keys. It is not required by the spec, and C++ doesn't do it. - for _, key := range v.MapKeys() { - val := v.MapIndex(key) - - keycopy.Set(key) - valcopy.Set(val) - - o.buf = append(o.buf, p.tagcode...) - if err := o.enc_len_thing(enc, &state); err != nil { - return err - } - } - return nil -} - -func size_new_map(p *Properties, base structPointer) int { - v := structPointer_NewAt(base, p.field, p.mtype).Elem() // map[K]V - - keycopy, valcopy, keybase, valbase := mapEncodeScratch(p.mtype) - - n := 0 - for _, key := range v.MapKeys() { - val := v.MapIndex(key) - keycopy.Set(key) - valcopy.Set(val) - - // Tag codes for key and val are the responsibility of the sub-sizer. - keysize := p.mkeyprop.size(p.mkeyprop, keybase) - valsize := p.mvalprop.size(p.mvalprop, valbase) - entry := keysize + valsize - // Add on tag code and length of map entry itself. - n += len(p.tagcode) + sizeVarint(uint64(entry)) + entry - } - return n -} - -// mapEncodeScratch returns a new reflect.Value matching the map's value type, -// and a structPointer suitable for passing to an encoder or sizer. -func mapEncodeScratch(mapType reflect.Type) (keycopy, valcopy reflect.Value, keybase, valbase structPointer) { - // Prepare addressable doubly-indirect placeholders for the key and value types. - // This is needed because the element-type encoders expect **T, but the map iteration produces T. - - keycopy = reflect.New(mapType.Key()).Elem() // addressable K - keyptr := reflect.New(reflect.PtrTo(keycopy.Type())).Elem() // addressable *K - keyptr.Set(keycopy.Addr()) // - keybase = toStructPointer(keyptr.Addr()) // **K - - // Value types are more varied and require special handling. - switch mapType.Elem().Kind() { - case reflect.Slice: - // []byte - var dummy []byte - valcopy = reflect.ValueOf(&dummy).Elem() // addressable []byte - valbase = toStructPointer(valcopy.Addr()) - case reflect.Ptr: - // message; the generated field type is map[K]*Msg (so V is *Msg), - // so we only need one level of indirection. - valcopy = reflect.New(mapType.Elem()).Elem() // addressable V - valbase = toStructPointer(valcopy.Addr()) - default: - // everything else - valcopy = reflect.New(mapType.Elem()).Elem() // addressable V - valptr := reflect.New(reflect.PtrTo(valcopy.Type())).Elem() // addressable *V - valptr.Set(valcopy.Addr()) // - valbase = toStructPointer(valptr.Addr()) // **V - } - return -} - -// Encode a struct. -func (o *Buffer) enc_struct(prop *StructProperties, base structPointer) error { - var state errorState - // Encode fields in tag order so that decoders may use optimizations - // that depend on the ordering. - // https://developers.google.com/protocol-buffers/docs/encoding#order - for _, i := range prop.order { - p := prop.Prop[i] - if p.enc != nil { - err := p.enc(o, p, base) - if err != nil { - if err == ErrNil { - if p.Required && state.err == nil { - state.err = &RequiredNotSetError{p.Name} - } - } else if err == errRepeatedHasNil { - // Give more context to nil values in repeated fields. - return errors.New("repeated field " + p.OrigName + " has nil element") - } else if !state.shouldContinue(err, p) { - return err - } - } - if len(o.buf) > maxMarshalSize { - return ErrTooLarge - } - } - } - - // Do oneof fields. - if prop.oneofMarshaler != nil { - m := structPointer_Interface(base, prop.stype).(Message) - if err := prop.oneofMarshaler(m, o); err == ErrNil { - return errOneofHasNil - } else if err != nil { - return err - } - } - - // Add unrecognized fields at the end. - if prop.unrecField.IsValid() { - v := *structPointer_Bytes(base, prop.unrecField) - if len(o.buf)+len(v) > maxMarshalSize { - return ErrTooLarge - } - if len(v) > 0 { - o.buf = append(o.buf, v...) - } - } - - return state.err -} - -func size_struct(prop *StructProperties, base structPointer) (n int) { - for _, i := range prop.order { - p := prop.Prop[i] - if p.size != nil { - n += p.size(p, base) - } - } - - // Add unrecognized fields at the end. - if prop.unrecField.IsValid() { - v := *structPointer_Bytes(base, prop.unrecField) - n += len(v) - } - - // Factor in any oneof fields. - if prop.oneofSizer != nil { - m := structPointer_Interface(base, prop.stype).(Message) - n += prop.oneofSizer(m) - } - - return -} - -var zeroes [20]byte // longer than any conceivable sizeVarint - -// Encode a struct, preceded by its encoded length (as a varint). -func (o *Buffer) enc_len_struct(prop *StructProperties, base structPointer, state *errorState) error { - return o.enc_len_thing(func() error { return o.enc_struct(prop, base) }, state) -} - -// Encode something, preceded by its encoded length (as a varint). -func (o *Buffer) enc_len_thing(enc func() error, state *errorState) error { - iLen := len(o.buf) - o.buf = append(o.buf, 0, 0, 0, 0) // reserve four bytes for length - iMsg := len(o.buf) - err := enc() - if err != nil && !state.shouldContinue(err, nil) { - return err - } - lMsg := len(o.buf) - iMsg - lLen := sizeVarint(uint64(lMsg)) - switch x := lLen - (iMsg - iLen); { - case x > 0: // actual length is x bytes larger than the space we reserved - // Move msg x bytes right. - o.buf = append(o.buf, zeroes[:x]...) - copy(o.buf[iMsg+x:], o.buf[iMsg:iMsg+lMsg]) - case x < 0: // actual length is x bytes smaller than the space we reserved - // Move msg x bytes left. - copy(o.buf[iMsg+x:], o.buf[iMsg:iMsg+lMsg]) - o.buf = o.buf[:len(o.buf)+x] // x is negative - } - // Encode the length in the reserved space. - o.buf = o.buf[:iLen] - o.EncodeVarint(uint64(lMsg)) - o.buf = o.buf[:len(o.buf)+lMsg] - return state.err -} - -// errorState maintains the first error that occurs and updates that error -// with additional context. -type errorState struct { - err error -} - -// shouldContinue reports whether encoding should continue upon encountering the -// given error. If the error is RequiredNotSetError, shouldContinue returns true -// and, if this is the first appearance of that error, remembers it for future -// reporting. -// -// If prop is not nil, it may update any error with additional context about the -// field with the error. -func (s *errorState) shouldContinue(err error, prop *Properties) bool { - // Ignore unset required fields. - reqNotSet, ok := err.(*RequiredNotSetError) - if !ok { - return false - } - if s.err == nil { - if prop != nil { - err = &RequiredNotSetError{prop.Name + "." + reqNotSet.field} - } - s.err = err - } - return true -} diff --git a/vendor/github.com/golang/protobuf/proto/equal.go b/vendor/github.com/golang/protobuf/proto/equal.go deleted file mode 100644 index 2ed1cf596664d3dedb372fc051a04b79da040f21..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/equal.go +++ /dev/null @@ -1,300 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2011 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Protocol buffer comparison. - -package proto - -import ( - "bytes" - "log" - "reflect" - "strings" -) - -/* -Equal returns true iff protocol buffers a and b are equal. -The arguments must both be pointers to protocol buffer structs. - -Equality is defined in this way: - - Two messages are equal iff they are the same type, - corresponding fields are equal, unknown field sets - are equal, and extensions sets are equal. - - Two set scalar fields are equal iff their values are equal. - If the fields are of a floating-point type, remember that - NaN != x for all x, including NaN. If the message is defined - in a proto3 .proto file, fields are not "set"; specifically, - zero length proto3 "bytes" fields are equal (nil == {}). - - Two repeated fields are equal iff their lengths are the same, - and their corresponding elements are equal. Note a "bytes" field, - although represented by []byte, is not a repeated field and the - rule for the scalar fields described above applies. - - Two unset fields are equal. - - Two unknown field sets are equal if their current - encoded state is equal. - - Two extension sets are equal iff they have corresponding - elements that are pairwise equal. - - Two map fields are equal iff their lengths are the same, - and they contain the same set of elements. Zero-length map - fields are equal. - - Every other combination of things are not equal. - -The return value is undefined if a and b are not protocol buffers. -*/ -func Equal(a, b Message) bool { - if a == nil || b == nil { - return a == b - } - v1, v2 := reflect.ValueOf(a), reflect.ValueOf(b) - if v1.Type() != v2.Type() { - return false - } - if v1.Kind() == reflect.Ptr { - if v1.IsNil() { - return v2.IsNil() - } - if v2.IsNil() { - return false - } - v1, v2 = v1.Elem(), v2.Elem() - } - if v1.Kind() != reflect.Struct { - return false - } - return equalStruct(v1, v2) -} - -// v1 and v2 are known to have the same type. -func equalStruct(v1, v2 reflect.Value) bool { - sprop := GetProperties(v1.Type()) - for i := 0; i < v1.NumField(); i++ { - f := v1.Type().Field(i) - if strings.HasPrefix(f.Name, "XXX_") { - continue - } - f1, f2 := v1.Field(i), v2.Field(i) - if f.Type.Kind() == reflect.Ptr { - if n1, n2 := f1.IsNil(), f2.IsNil(); n1 && n2 { - // both unset - continue - } else if n1 != n2 { - // set/unset mismatch - return false - } - b1, ok := f1.Interface().(raw) - if ok { - b2 := f2.Interface().(raw) - // RawMessage - if !bytes.Equal(b1.Bytes(), b2.Bytes()) { - return false - } - continue - } - f1, f2 = f1.Elem(), f2.Elem() - } - if !equalAny(f1, f2, sprop.Prop[i]) { - return false - } - } - - if em1 := v1.FieldByName("XXX_InternalExtensions"); em1.IsValid() { - em2 := v2.FieldByName("XXX_InternalExtensions") - if !equalExtensions(v1.Type(), em1.Interface().(XXX_InternalExtensions), em2.Interface().(XXX_InternalExtensions)) { - return false - } - } - - if em1 := v1.FieldByName("XXX_extensions"); em1.IsValid() { - em2 := v2.FieldByName("XXX_extensions") - if !equalExtMap(v1.Type(), em1.Interface().(map[int32]Extension), em2.Interface().(map[int32]Extension)) { - return false - } - } - - uf := v1.FieldByName("XXX_unrecognized") - if !uf.IsValid() { - return true - } - - u1 := uf.Bytes() - u2 := v2.FieldByName("XXX_unrecognized").Bytes() - if !bytes.Equal(u1, u2) { - return false - } - - return true -} - -// v1 and v2 are known to have the same type. -// prop may be nil. -func equalAny(v1, v2 reflect.Value, prop *Properties) bool { - if v1.Type() == protoMessageType { - m1, _ := v1.Interface().(Message) - m2, _ := v2.Interface().(Message) - return Equal(m1, m2) - } - switch v1.Kind() { - case reflect.Bool: - return v1.Bool() == v2.Bool() - case reflect.Float32, reflect.Float64: - return v1.Float() == v2.Float() - case reflect.Int32, reflect.Int64: - return v1.Int() == v2.Int() - case reflect.Interface: - // Probably a oneof field; compare the inner values. - n1, n2 := v1.IsNil(), v2.IsNil() - if n1 || n2 { - return n1 == n2 - } - e1, e2 := v1.Elem(), v2.Elem() - if e1.Type() != e2.Type() { - return false - } - return equalAny(e1, e2, nil) - case reflect.Map: - if v1.Len() != v2.Len() { - return false - } - for _, key := range v1.MapKeys() { - val2 := v2.MapIndex(key) - if !val2.IsValid() { - // This key was not found in the second map. - return false - } - if !equalAny(v1.MapIndex(key), val2, nil) { - return false - } - } - return true - case reflect.Ptr: - // Maps may have nil values in them, so check for nil. - if v1.IsNil() && v2.IsNil() { - return true - } - if v1.IsNil() != v2.IsNil() { - return false - } - return equalAny(v1.Elem(), v2.Elem(), prop) - case reflect.Slice: - if v1.Type().Elem().Kind() == reflect.Uint8 { - // short circuit: []byte - - // Edge case: if this is in a proto3 message, a zero length - // bytes field is considered the zero value. - if prop != nil && prop.proto3 && v1.Len() == 0 && v2.Len() == 0 { - return true - } - if v1.IsNil() != v2.IsNil() { - return false - } - return bytes.Equal(v1.Interface().([]byte), v2.Interface().([]byte)) - } - - if v1.Len() != v2.Len() { - return false - } - for i := 0; i < v1.Len(); i++ { - if !equalAny(v1.Index(i), v2.Index(i), prop) { - return false - } - } - return true - case reflect.String: - return v1.Interface().(string) == v2.Interface().(string) - case reflect.Struct: - return equalStruct(v1, v2) - case reflect.Uint32, reflect.Uint64: - return v1.Uint() == v2.Uint() - } - - // unknown type, so not a protocol buffer - log.Printf("proto: don't know how to compare %v", v1) - return false -} - -// base is the struct type that the extensions are based on. -// x1 and x2 are InternalExtensions. -func equalExtensions(base reflect.Type, x1, x2 XXX_InternalExtensions) bool { - em1, _ := x1.extensionsRead() - em2, _ := x2.extensionsRead() - return equalExtMap(base, em1, em2) -} - -func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool { - if len(em1) != len(em2) { - return false - } - - for extNum, e1 := range em1 { - e2, ok := em2[extNum] - if !ok { - return false - } - - m1, m2 := e1.value, e2.value - - if m1 != nil && m2 != nil { - // Both are unencoded. - if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2), nil) { - return false - } - continue - } - - // At least one is encoded. To do a semantically correct comparison - // we need to unmarshal them first. - var desc *ExtensionDesc - if m := extensionMaps[base]; m != nil { - desc = m[extNum] - } - if desc == nil { - log.Printf("proto: don't know how to compare extension %d of %v", extNum, base) - continue - } - var err error - if m1 == nil { - m1, err = decodeExtension(e1.enc, desc) - } - if m2 == nil && err == nil { - m2, err = decodeExtension(e2.enc, desc) - } - if err != nil { - // The encoded form is invalid. - log.Printf("proto: badly encoded extension %d of %v: %v", extNum, base, err) - return false - } - if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2), nil) { - return false - } - } - - return true -} diff --git a/vendor/github.com/golang/protobuf/proto/extensions.go b/vendor/github.com/golang/protobuf/proto/extensions.go deleted file mode 100644 index eaad21831263eecc5add3fa980847857d2123bf2..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/extensions.go +++ /dev/null @@ -1,587 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -/* - * Types and routines for supporting protocol buffer extensions. - */ - -import ( - "errors" - "fmt" - "reflect" - "strconv" - "sync" -) - -// ErrMissingExtension is the error returned by GetExtension if the named extension is not in the message. -var ErrMissingExtension = errors.New("proto: missing extension") - -// ExtensionRange represents a range of message extensions for a protocol buffer. -// Used in code generated by the protocol compiler. -type ExtensionRange struct { - Start, End int32 // both inclusive -} - -// extendableProto is an interface implemented by any protocol buffer generated by the current -// proto compiler that may be extended. -type extendableProto interface { - Message - ExtensionRangeArray() []ExtensionRange - extensionsWrite() map[int32]Extension - extensionsRead() (map[int32]Extension, sync.Locker) -} - -// extendableProtoV1 is an interface implemented by a protocol buffer generated by the previous -// version of the proto compiler that may be extended. -type extendableProtoV1 interface { - Message - ExtensionRangeArray() []ExtensionRange - ExtensionMap() map[int32]Extension -} - -// extensionAdapter is a wrapper around extendableProtoV1 that implements extendableProto. -type extensionAdapter struct { - extendableProtoV1 -} - -func (e extensionAdapter) extensionsWrite() map[int32]Extension { - return e.ExtensionMap() -} - -func (e extensionAdapter) extensionsRead() (map[int32]Extension, sync.Locker) { - return e.ExtensionMap(), notLocker{} -} - -// notLocker is a sync.Locker whose Lock and Unlock methods are nops. -type notLocker struct{} - -func (n notLocker) Lock() {} -func (n notLocker) Unlock() {} - -// extendable returns the extendableProto interface for the given generated proto message. -// If the proto message has the old extension format, it returns a wrapper that implements -// the extendableProto interface. -func extendable(p interface{}) (extendableProto, bool) { - if ep, ok := p.(extendableProto); ok { - return ep, ok - } - if ep, ok := p.(extendableProtoV1); ok { - return extensionAdapter{ep}, ok - } - return nil, false -} - -// XXX_InternalExtensions is an internal representation of proto extensions. -// -// Each generated message struct type embeds an anonymous XXX_InternalExtensions field, -// thus gaining the unexported 'extensions' method, which can be called only from the proto package. -// -// The methods of XXX_InternalExtensions are not concurrency safe in general, -// but calls to logically read-only methods such as has and get may be executed concurrently. -type XXX_InternalExtensions struct { - // The struct must be indirect so that if a user inadvertently copies a - // generated message and its embedded XXX_InternalExtensions, they - // avoid the mayhem of a copied mutex. - // - // The mutex serializes all logically read-only operations to p.extensionMap. - // It is up to the client to ensure that write operations to p.extensionMap are - // mutually exclusive with other accesses. - p *struct { - mu sync.Mutex - extensionMap map[int32]Extension - } -} - -// extensionsWrite returns the extension map, creating it on first use. -func (e *XXX_InternalExtensions) extensionsWrite() map[int32]Extension { - if e.p == nil { - e.p = new(struct { - mu sync.Mutex - extensionMap map[int32]Extension - }) - e.p.extensionMap = make(map[int32]Extension) - } - return e.p.extensionMap -} - -// extensionsRead returns the extensions map for read-only use. It may be nil. -// The caller must hold the returned mutex's lock when accessing Elements within the map. -func (e *XXX_InternalExtensions) extensionsRead() (map[int32]Extension, sync.Locker) { - if e.p == nil { - return nil, nil - } - return e.p.extensionMap, &e.p.mu -} - -var extendableProtoType = reflect.TypeOf((*extendableProto)(nil)).Elem() -var extendableProtoV1Type = reflect.TypeOf((*extendableProtoV1)(nil)).Elem() - -// ExtensionDesc represents an extension specification. -// Used in generated code from the protocol compiler. -type ExtensionDesc struct { - ExtendedType Message // nil pointer to the type that is being extended - ExtensionType interface{} // nil pointer to the extension type - Field int32 // field number - Name string // fully-qualified name of extension, for text formatting - Tag string // protobuf tag style - Filename string // name of the file in which the extension is defined -} - -func (ed *ExtensionDesc) repeated() bool { - t := reflect.TypeOf(ed.ExtensionType) - return t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 -} - -// Extension represents an extension in a message. -type Extension struct { - // When an extension is stored in a message using SetExtension - // only desc and value are set. When the message is marshaled - // enc will be set to the encoded form of the message. - // - // When a message is unmarshaled and contains extensions, each - // extension will have only enc set. When such an extension is - // accessed using GetExtension (or GetExtensions) desc and value - // will be set. - desc *ExtensionDesc - value interface{} - enc []byte -} - -// SetRawExtension is for testing only. -func SetRawExtension(base Message, id int32, b []byte) { - epb, ok := extendable(base) - if !ok { - return - } - extmap := epb.extensionsWrite() - extmap[id] = Extension{enc: b} -} - -// isExtensionField returns true iff the given field number is in an extension range. -func isExtensionField(pb extendableProto, field int32) bool { - for _, er := range pb.ExtensionRangeArray() { - if er.Start <= field && field <= er.End { - return true - } - } - return false -} - -// checkExtensionTypes checks that the given extension is valid for pb. -func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error { - var pbi interface{} = pb - // Check the extended type. - if ea, ok := pbi.(extensionAdapter); ok { - pbi = ea.extendableProtoV1 - } - if a, b := reflect.TypeOf(pbi), reflect.TypeOf(extension.ExtendedType); a != b { - return errors.New("proto: bad extended type; " + b.String() + " does not extend " + a.String()) - } - // Check the range. - if !isExtensionField(pb, extension.Field) { - return errors.New("proto: bad extension number; not in declared ranges") - } - return nil -} - -// extPropKey is sufficient to uniquely identify an extension. -type extPropKey struct { - base reflect.Type - field int32 -} - -var extProp = struct { - sync.RWMutex - m map[extPropKey]*Properties -}{ - m: make(map[extPropKey]*Properties), -} - -func extensionProperties(ed *ExtensionDesc) *Properties { - key := extPropKey{base: reflect.TypeOf(ed.ExtendedType), field: ed.Field} - - extProp.RLock() - if prop, ok := extProp.m[key]; ok { - extProp.RUnlock() - return prop - } - extProp.RUnlock() - - extProp.Lock() - defer extProp.Unlock() - // Check again. - if prop, ok := extProp.m[key]; ok { - return prop - } - - prop := new(Properties) - prop.Init(reflect.TypeOf(ed.ExtensionType), "unknown_name", ed.Tag, nil) - extProp.m[key] = prop - return prop -} - -// encode encodes any unmarshaled (unencoded) extensions in e. -func encodeExtensions(e *XXX_InternalExtensions) error { - m, mu := e.extensionsRead() - if m == nil { - return nil // fast path - } - mu.Lock() - defer mu.Unlock() - return encodeExtensionsMap(m) -} - -// encode encodes any unmarshaled (unencoded) extensions in e. -func encodeExtensionsMap(m map[int32]Extension) error { - for k, e := range m { - if e.value == nil || e.desc == nil { - // Extension is only in its encoded form. - continue - } - - // We don't skip extensions that have an encoded form set, - // because the extension value may have been mutated after - // the last time this function was called. - - et := reflect.TypeOf(e.desc.ExtensionType) - props := extensionProperties(e.desc) - - p := NewBuffer(nil) - // If e.value has type T, the encoder expects a *struct{ X T }. - // Pass a *T with a zero field and hope it all works out. - x := reflect.New(et) - x.Elem().Set(reflect.ValueOf(e.value)) - if err := props.enc(p, props, toStructPointer(x)); err != nil { - return err - } - e.enc = p.buf - m[k] = e - } - return nil -} - -func extensionsSize(e *XXX_InternalExtensions) (n int) { - m, mu := e.extensionsRead() - if m == nil { - return 0 - } - mu.Lock() - defer mu.Unlock() - return extensionsMapSize(m) -} - -func extensionsMapSize(m map[int32]Extension) (n int) { - for _, e := range m { - if e.value == nil || e.desc == nil { - // Extension is only in its encoded form. - n += len(e.enc) - continue - } - - // We don't skip extensions that have an encoded form set, - // because the extension value may have been mutated after - // the last time this function was called. - - et := reflect.TypeOf(e.desc.ExtensionType) - props := extensionProperties(e.desc) - - // If e.value has type T, the encoder expects a *struct{ X T }. - // Pass a *T with a zero field and hope it all works out. - x := reflect.New(et) - x.Elem().Set(reflect.ValueOf(e.value)) - n += props.size(props, toStructPointer(x)) - } - return -} - -// HasExtension returns whether the given extension is present in pb. -func HasExtension(pb Message, extension *ExtensionDesc) bool { - // TODO: Check types, field numbers, etc.? - epb, ok := extendable(pb) - if !ok { - return false - } - extmap, mu := epb.extensionsRead() - if extmap == nil { - return false - } - mu.Lock() - _, ok = extmap[extension.Field] - mu.Unlock() - return ok -} - -// ClearExtension removes the given extension from pb. -func ClearExtension(pb Message, extension *ExtensionDesc) { - epb, ok := extendable(pb) - if !ok { - return - } - // TODO: Check types, field numbers, etc.? - extmap := epb.extensionsWrite() - delete(extmap, extension.Field) -} - -// GetExtension parses and returns the given extension of pb. -// If the extension is not present and has no default value it returns ErrMissingExtension. -func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) { - epb, ok := extendable(pb) - if !ok { - return nil, errors.New("proto: not an extendable proto") - } - - if err := checkExtensionTypes(epb, extension); err != nil { - return nil, err - } - - emap, mu := epb.extensionsRead() - if emap == nil { - return defaultExtensionValue(extension) - } - mu.Lock() - defer mu.Unlock() - e, ok := emap[extension.Field] - if !ok { - // defaultExtensionValue returns the default value or - // ErrMissingExtension if there is no default. - return defaultExtensionValue(extension) - } - - if e.value != nil { - // Already decoded. Check the descriptor, though. - if e.desc != extension { - // This shouldn't happen. If it does, it means that - // GetExtension was called twice with two different - // descriptors with the same field number. - return nil, errors.New("proto: descriptor conflict") - } - return e.value, nil - } - - v, err := decodeExtension(e.enc, extension) - if err != nil { - return nil, err - } - - // Remember the decoded version and drop the encoded version. - // That way it is safe to mutate what we return. - e.value = v - e.desc = extension - e.enc = nil - emap[extension.Field] = e - return e.value, nil -} - -// defaultExtensionValue returns the default value for extension. -// If no default for an extension is defined ErrMissingExtension is returned. -func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) { - t := reflect.TypeOf(extension.ExtensionType) - props := extensionProperties(extension) - - sf, _, err := fieldDefault(t, props) - if err != nil { - return nil, err - } - - if sf == nil || sf.value == nil { - // There is no default value. - return nil, ErrMissingExtension - } - - if t.Kind() != reflect.Ptr { - // We do not need to return a Ptr, we can directly return sf.value. - return sf.value, nil - } - - // We need to return an interface{} that is a pointer to sf.value. - value := reflect.New(t).Elem() - value.Set(reflect.New(value.Type().Elem())) - if sf.kind == reflect.Int32 { - // We may have an int32 or an enum, but the underlying data is int32. - // Since we can't set an int32 into a non int32 reflect.value directly - // set it as a int32. - value.Elem().SetInt(int64(sf.value.(int32))) - } else { - value.Elem().Set(reflect.ValueOf(sf.value)) - } - return value.Interface(), nil -} - -// decodeExtension decodes an extension encoded in b. -func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) { - o := NewBuffer(b) - - t := reflect.TypeOf(extension.ExtensionType) - - props := extensionProperties(extension) - - // t is a pointer to a struct, pointer to basic type or a slice. - // Allocate a "field" to store the pointer/slice itself; the - // pointer/slice will be stored here. We pass - // the address of this field to props.dec. - // This passes a zero field and a *t and lets props.dec - // interpret it as a *struct{ x t }. - value := reflect.New(t).Elem() - - for { - // Discard wire type and field number varint. It isn't needed. - if _, err := o.DecodeVarint(); err != nil { - return nil, err - } - - if err := props.dec(o, props, toStructPointer(value.Addr())); err != nil { - return nil, err - } - - if o.index >= len(o.buf) { - break - } - } - return value.Interface(), nil -} - -// GetExtensions returns a slice of the extensions present in pb that are also listed in es. -// The returned slice has the same length as es; missing extensions will appear as nil elements. -func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) { - epb, ok := extendable(pb) - if !ok { - return nil, errors.New("proto: not an extendable proto") - } - extensions = make([]interface{}, len(es)) - for i, e := range es { - extensions[i], err = GetExtension(epb, e) - if err == ErrMissingExtension { - err = nil - } - if err != nil { - return - } - } - return -} - -// ExtensionDescs returns a new slice containing pb's extension descriptors, in undefined order. -// For non-registered extensions, ExtensionDescs returns an incomplete descriptor containing -// just the Field field, which defines the extension's field number. -func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) { - epb, ok := extendable(pb) - if !ok { - return nil, fmt.Errorf("proto: %T is not an extendable proto.Message", pb) - } - registeredExtensions := RegisteredExtensions(pb) - - emap, mu := epb.extensionsRead() - if emap == nil { - return nil, nil - } - mu.Lock() - defer mu.Unlock() - extensions := make([]*ExtensionDesc, 0, len(emap)) - for extid, e := range emap { - desc := e.desc - if desc == nil { - desc = registeredExtensions[extid] - if desc == nil { - desc = &ExtensionDesc{Field: extid} - } - } - - extensions = append(extensions, desc) - } - return extensions, nil -} - -// SetExtension sets the specified extension of pb to the specified value. -func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error { - epb, ok := extendable(pb) - if !ok { - return errors.New("proto: not an extendable proto") - } - if err := checkExtensionTypes(epb, extension); err != nil { - return err - } - typ := reflect.TypeOf(extension.ExtensionType) - if typ != reflect.TypeOf(value) { - return errors.New("proto: bad extension value type") - } - // nil extension values need to be caught early, because the - // encoder can't distinguish an ErrNil due to a nil extension - // from an ErrNil due to a missing field. Extensions are - // always optional, so the encoder would just swallow the error - // and drop all the extensions from the encoded message. - if reflect.ValueOf(value).IsNil() { - return fmt.Errorf("proto: SetExtension called with nil value of type %T", value) - } - - extmap := epb.extensionsWrite() - extmap[extension.Field] = Extension{desc: extension, value: value} - return nil -} - -// ClearAllExtensions clears all extensions from pb. -func ClearAllExtensions(pb Message) { - epb, ok := extendable(pb) - if !ok { - return - } - m := epb.extensionsWrite() - for k := range m { - delete(m, k) - } -} - -// A global registry of extensions. -// The generated code will register the generated descriptors by calling RegisterExtension. - -var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc) - -// RegisterExtension is called from the generated code. -func RegisterExtension(desc *ExtensionDesc) { - st := reflect.TypeOf(desc.ExtendedType).Elem() - m := extensionMaps[st] - if m == nil { - m = make(map[int32]*ExtensionDesc) - extensionMaps[st] = m - } - if _, ok := m[desc.Field]; ok { - panic("proto: duplicate extension registered: " + st.String() + " " + strconv.Itoa(int(desc.Field))) - } - m[desc.Field] = desc -} - -// RegisteredExtensions returns a map of the registered extensions of a -// protocol buffer struct, indexed by the extension number. -// The argument pb should be a nil pointer to the struct type. -func RegisteredExtensions(pb Message) map[int32]*ExtensionDesc { - return extensionMaps[reflect.TypeOf(pb).Elem()] -} diff --git a/vendor/github.com/golang/protobuf/proto/lib.go b/vendor/github.com/golang/protobuf/proto/lib.go deleted file mode 100644 index 1c225504a013c5da68f5b46caa5c110dd32db6cf..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/lib.go +++ /dev/null @@ -1,897 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/* -Package proto converts data structures to and from the wire format of -protocol buffers. It works in concert with the Go source code generated -for .proto files by the protocol compiler. - -A summary of the properties of the protocol buffer interface -for a protocol buffer variable v: - - - Names are turned from camel_case to CamelCase for export. - - There are no methods on v to set fields; just treat - them as structure fields. - - There are getters that return a field's value if set, - and return the field's default value if unset. - The getters work even if the receiver is a nil message. - - The zero value for a struct is its correct initialization state. - All desired fields must be set before marshaling. - - A Reset() method will restore a protobuf struct to its zero state. - - Non-repeated fields are pointers to the values; nil means unset. - That is, optional or required field int32 f becomes F *int32. - - Repeated fields are slices. - - Helper functions are available to aid the setting of fields. - msg.Foo = proto.String("hello") // set field - - Constants are defined to hold the default values of all fields that - have them. They have the form Default_StructName_FieldName. - Because the getter methods handle defaulted values, - direct use of these constants should be rare. - - Enums are given type names and maps from names to values. - Enum values are prefixed by the enclosing message's name, or by the - enum's type name if it is a top-level enum. Enum types have a String - method, and a Enum method to assist in message construction. - - Nested messages, groups and enums have type names prefixed with the name of - the surrounding message type. - - Extensions are given descriptor names that start with E_, - followed by an underscore-delimited list of the nested messages - that contain it (if any) followed by the CamelCased name of the - extension field itself. HasExtension, ClearExtension, GetExtension - and SetExtension are functions for manipulating extensions. - - Oneof field sets are given a single field in their message, - with distinguished wrapper types for each possible field value. - - Marshal and Unmarshal are functions to encode and decode the wire format. - -When the .proto file specifies `syntax="proto3"`, there are some differences: - - - Non-repeated fields of non-message type are values instead of pointers. - - Enum types do not get an Enum method. - -The simplest way to describe this is to see an example. -Given file test.proto, containing - - package example; - - enum FOO { X = 17; } - - message Test { - required string label = 1; - optional int32 type = 2 [default=77]; - repeated int64 reps = 3; - optional group OptionalGroup = 4 { - required string RequiredField = 5; - } - oneof union { - int32 number = 6; - string name = 7; - } - } - -The resulting file, test.pb.go, is: - - package example - - import proto "github.com/golang/protobuf/proto" - import math "math" - - type FOO int32 - const ( - FOO_X FOO = 17 - ) - var FOO_name = map[int32]string{ - 17: "X", - } - var FOO_value = map[string]int32{ - "X": 17, - } - - func (x FOO) Enum() *FOO { - p := new(FOO) - *p = x - return p - } - func (x FOO) String() string { - return proto.EnumName(FOO_name, int32(x)) - } - func (x *FOO) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(FOO_value, data) - if err != nil { - return err - } - *x = FOO(value) - return nil - } - - type Test struct { - Label *string `protobuf:"bytes,1,req,name=label" json:"label,omitempty"` - Type *int32 `protobuf:"varint,2,opt,name=type,def=77" json:"type,omitempty"` - Reps []int64 `protobuf:"varint,3,rep,name=reps" json:"reps,omitempty"` - Optionalgroup *Test_OptionalGroup `protobuf:"group,4,opt,name=OptionalGroup" json:"optionalgroup,omitempty"` - // Types that are valid to be assigned to Union: - // *Test_Number - // *Test_Name - Union isTest_Union `protobuf_oneof:"union"` - XXX_unrecognized []byte `json:"-"` - } - func (m *Test) Reset() { *m = Test{} } - func (m *Test) String() string { return proto.CompactTextString(m) } - func (*Test) ProtoMessage() {} - - type isTest_Union interface { - isTest_Union() - } - - type Test_Number struct { - Number int32 `protobuf:"varint,6,opt,name=number"` - } - type Test_Name struct { - Name string `protobuf:"bytes,7,opt,name=name"` - } - - func (*Test_Number) isTest_Union() {} - func (*Test_Name) isTest_Union() {} - - func (m *Test) GetUnion() isTest_Union { - if m != nil { - return m.Union - } - return nil - } - const Default_Test_Type int32 = 77 - - func (m *Test) GetLabel() string { - if m != nil && m.Label != nil { - return *m.Label - } - return "" - } - - func (m *Test) GetType() int32 { - if m != nil && m.Type != nil { - return *m.Type - } - return Default_Test_Type - } - - func (m *Test) GetOptionalgroup() *Test_OptionalGroup { - if m != nil { - return m.Optionalgroup - } - return nil - } - - type Test_OptionalGroup struct { - RequiredField *string `protobuf:"bytes,5,req" json:"RequiredField,omitempty"` - } - func (m *Test_OptionalGroup) Reset() { *m = Test_OptionalGroup{} } - func (m *Test_OptionalGroup) String() string { return proto.CompactTextString(m) } - - func (m *Test_OptionalGroup) GetRequiredField() string { - if m != nil && m.RequiredField != nil { - return *m.RequiredField - } - return "" - } - - func (m *Test) GetNumber() int32 { - if x, ok := m.GetUnion().(*Test_Number); ok { - return x.Number - } - return 0 - } - - func (m *Test) GetName() string { - if x, ok := m.GetUnion().(*Test_Name); ok { - return x.Name - } - return "" - } - - func init() { - proto.RegisterEnum("example.FOO", FOO_name, FOO_value) - } - -To create and play with a Test object: - - package main - - import ( - "log" - - "github.com/golang/protobuf/proto" - pb "./example.pb" - ) - - func main() { - test := &pb.Test{ - Label: proto.String("hello"), - Type: proto.Int32(17), - Reps: []int64{1, 2, 3}, - Optionalgroup: &pb.Test_OptionalGroup{ - RequiredField: proto.String("good bye"), - }, - Union: &pb.Test_Name{"fred"}, - } - data, err := proto.Marshal(test) - if err != nil { - log.Fatal("marshaling error: ", err) - } - newTest := &pb.Test{} - err = proto.Unmarshal(data, newTest) - if err != nil { - log.Fatal("unmarshaling error: ", err) - } - // Now test and newTest contain the same data. - if test.GetLabel() != newTest.GetLabel() { - log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel()) - } - // Use a type switch to determine which oneof was set. - switch u := test.Union.(type) { - case *pb.Test_Number: // u.Number contains the number. - case *pb.Test_Name: // u.Name contains the string. - } - // etc. - } -*/ -package proto - -import ( - "encoding/json" - "fmt" - "log" - "reflect" - "sort" - "strconv" - "sync" -) - -// Message is implemented by generated protocol buffer messages. -type Message interface { - Reset() - String() string - ProtoMessage() -} - -// Stats records allocation details about the protocol buffer encoders -// and decoders. Useful for tuning the library itself. -type Stats struct { - Emalloc uint64 // mallocs in encode - Dmalloc uint64 // mallocs in decode - Encode uint64 // number of encodes - Decode uint64 // number of decodes - Chit uint64 // number of cache hits - Cmiss uint64 // number of cache misses - Size uint64 // number of sizes -} - -// Set to true to enable stats collection. -const collectStats = false - -var stats Stats - -// GetStats returns a copy of the global Stats structure. -func GetStats() Stats { return stats } - -// A Buffer is a buffer manager for marshaling and unmarshaling -// protocol buffers. It may be reused between invocations to -// reduce memory usage. It is not necessary to use a Buffer; -// the global functions Marshal and Unmarshal create a -// temporary Buffer and are fine for most applications. -type Buffer struct { - buf []byte // encode/decode byte stream - index int // read point - - // pools of basic types to amortize allocation. - bools []bool - uint32s []uint32 - uint64s []uint64 - - // extra pools, only used with pointer_reflect.go - int32s []int32 - int64s []int64 - float32s []float32 - float64s []float64 -} - -// NewBuffer allocates a new Buffer and initializes its internal data to -// the contents of the argument slice. -func NewBuffer(e []byte) *Buffer { - return &Buffer{buf: e} -} - -// Reset resets the Buffer, ready for marshaling a new protocol buffer. -func (p *Buffer) Reset() { - p.buf = p.buf[0:0] // for reading/writing - p.index = 0 // for reading -} - -// SetBuf replaces the internal buffer with the slice, -// ready for unmarshaling the contents of the slice. -func (p *Buffer) SetBuf(s []byte) { - p.buf = s - p.index = 0 -} - -// Bytes returns the contents of the Buffer. -func (p *Buffer) Bytes() []byte { return p.buf } - -/* - * Helper routines for simplifying the creation of optional fields of basic type. - */ - -// Bool is a helper routine that allocates a new bool value -// to store v and returns a pointer to it. -func Bool(v bool) *bool { - return &v -} - -// Int32 is a helper routine that allocates a new int32 value -// to store v and returns a pointer to it. -func Int32(v int32) *int32 { - return &v -} - -// Int is a helper routine that allocates a new int32 value -// to store v and returns a pointer to it, but unlike Int32 -// its argument value is an int. -func Int(v int) *int32 { - p := new(int32) - *p = int32(v) - return p -} - -// Int64 is a helper routine that allocates a new int64 value -// to store v and returns a pointer to it. -func Int64(v int64) *int64 { - return &v -} - -// Float32 is a helper routine that allocates a new float32 value -// to store v and returns a pointer to it. -func Float32(v float32) *float32 { - return &v -} - -// Float64 is a helper routine that allocates a new float64 value -// to store v and returns a pointer to it. -func Float64(v float64) *float64 { - return &v -} - -// Uint32 is a helper routine that allocates a new uint32 value -// to store v and returns a pointer to it. -func Uint32(v uint32) *uint32 { - return &v -} - -// Uint64 is a helper routine that allocates a new uint64 value -// to store v and returns a pointer to it. -func Uint64(v uint64) *uint64 { - return &v -} - -// String is a helper routine that allocates a new string value -// to store v and returns a pointer to it. -func String(v string) *string { - return &v -} - -// EnumName is a helper function to simplify printing protocol buffer enums -// by name. Given an enum map and a value, it returns a useful string. -func EnumName(m map[int32]string, v int32) string { - s, ok := m[v] - if ok { - return s - } - return strconv.Itoa(int(v)) -} - -// UnmarshalJSONEnum is a helper function to simplify recovering enum int values -// from their JSON-encoded representation. Given a map from the enum's symbolic -// names to its int values, and a byte buffer containing the JSON-encoded -// value, it returns an int32 that can be cast to the enum type by the caller. -// -// The function can deal with both JSON representations, numeric and symbolic. -func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) { - if data[0] == '"' { - // New style: enums are strings. - var repr string - if err := json.Unmarshal(data, &repr); err != nil { - return -1, err - } - val, ok := m[repr] - if !ok { - return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr) - } - return val, nil - } - // Old style: enums are ints. - var val int32 - if err := json.Unmarshal(data, &val); err != nil { - return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName) - } - return val, nil -} - -// DebugPrint dumps the encoded data in b in a debugging format with a header -// including the string s. Used in testing but made available for general debugging. -func (p *Buffer) DebugPrint(s string, b []byte) { - var u uint64 - - obuf := p.buf - index := p.index - p.buf = b - p.index = 0 - depth := 0 - - fmt.Printf("\n--- %s ---\n", s) - -out: - for { - for i := 0; i < depth; i++ { - fmt.Print(" ") - } - - index := p.index - if index == len(p.buf) { - break - } - - op, err := p.DecodeVarint() - if err != nil { - fmt.Printf("%3d: fetching op err %v\n", index, err) - break out - } - tag := op >> 3 - wire := op & 7 - - switch wire { - default: - fmt.Printf("%3d: t=%3d unknown wire=%d\n", - index, tag, wire) - break out - - case WireBytes: - var r []byte - - r, err = p.DecodeRawBytes(false) - if err != nil { - break out - } - fmt.Printf("%3d: t=%3d bytes [%d]", index, tag, len(r)) - if len(r) <= 6 { - for i := 0; i < len(r); i++ { - fmt.Printf(" %.2x", r[i]) - } - } else { - for i := 0; i < 3; i++ { - fmt.Printf(" %.2x", r[i]) - } - fmt.Printf(" ..") - for i := len(r) - 3; i < len(r); i++ { - fmt.Printf(" %.2x", r[i]) - } - } - fmt.Printf("\n") - - case WireFixed32: - u, err = p.DecodeFixed32() - if err != nil { - fmt.Printf("%3d: t=%3d fix32 err %v\n", index, tag, err) - break out - } - fmt.Printf("%3d: t=%3d fix32 %d\n", index, tag, u) - - case WireFixed64: - u, err = p.DecodeFixed64() - if err != nil { - fmt.Printf("%3d: t=%3d fix64 err %v\n", index, tag, err) - break out - } - fmt.Printf("%3d: t=%3d fix64 %d\n", index, tag, u) - - case WireVarint: - u, err = p.DecodeVarint() - if err != nil { - fmt.Printf("%3d: t=%3d varint err %v\n", index, tag, err) - break out - } - fmt.Printf("%3d: t=%3d varint %d\n", index, tag, u) - - case WireStartGroup: - fmt.Printf("%3d: t=%3d start\n", index, tag) - depth++ - - case WireEndGroup: - depth-- - fmt.Printf("%3d: t=%3d end\n", index, tag) - } - } - - if depth != 0 { - fmt.Printf("%3d: start-end not balanced %d\n", p.index, depth) - } - fmt.Printf("\n") - - p.buf = obuf - p.index = index -} - -// SetDefaults sets unset protocol buffer fields to their default values. -// It only modifies fields that are both unset and have defined defaults. -// It recursively sets default values in any non-nil sub-messages. -func SetDefaults(pb Message) { - setDefaults(reflect.ValueOf(pb), true, false) -} - -// v is a pointer to a struct. -func setDefaults(v reflect.Value, recur, zeros bool) { - v = v.Elem() - - defaultMu.RLock() - dm, ok := defaults[v.Type()] - defaultMu.RUnlock() - if !ok { - dm = buildDefaultMessage(v.Type()) - defaultMu.Lock() - defaults[v.Type()] = dm - defaultMu.Unlock() - } - - for _, sf := range dm.scalars { - f := v.Field(sf.index) - if !f.IsNil() { - // field already set - continue - } - dv := sf.value - if dv == nil && !zeros { - // no explicit default, and don't want to set zeros - continue - } - fptr := f.Addr().Interface() // **T - // TODO: Consider batching the allocations we do here. - switch sf.kind { - case reflect.Bool: - b := new(bool) - if dv != nil { - *b = dv.(bool) - } - *(fptr.(**bool)) = b - case reflect.Float32: - f := new(float32) - if dv != nil { - *f = dv.(float32) - } - *(fptr.(**float32)) = f - case reflect.Float64: - f := new(float64) - if dv != nil { - *f = dv.(float64) - } - *(fptr.(**float64)) = f - case reflect.Int32: - // might be an enum - if ft := f.Type(); ft != int32PtrType { - // enum - f.Set(reflect.New(ft.Elem())) - if dv != nil { - f.Elem().SetInt(int64(dv.(int32))) - } - } else { - // int32 field - i := new(int32) - if dv != nil { - *i = dv.(int32) - } - *(fptr.(**int32)) = i - } - case reflect.Int64: - i := new(int64) - if dv != nil { - *i = dv.(int64) - } - *(fptr.(**int64)) = i - case reflect.String: - s := new(string) - if dv != nil { - *s = dv.(string) - } - *(fptr.(**string)) = s - case reflect.Uint8: - // exceptional case: []byte - var b []byte - if dv != nil { - db := dv.([]byte) - b = make([]byte, len(db)) - copy(b, db) - } else { - b = []byte{} - } - *(fptr.(*[]byte)) = b - case reflect.Uint32: - u := new(uint32) - if dv != nil { - *u = dv.(uint32) - } - *(fptr.(**uint32)) = u - case reflect.Uint64: - u := new(uint64) - if dv != nil { - *u = dv.(uint64) - } - *(fptr.(**uint64)) = u - default: - log.Printf("proto: can't set default for field %v (sf.kind=%v)", f, sf.kind) - } - } - - for _, ni := range dm.nested { - f := v.Field(ni) - // f is *T or []*T or map[T]*T - switch f.Kind() { - case reflect.Ptr: - if f.IsNil() { - continue - } - setDefaults(f, recur, zeros) - - case reflect.Slice: - for i := 0; i < f.Len(); i++ { - e := f.Index(i) - if e.IsNil() { - continue - } - setDefaults(e, recur, zeros) - } - - case reflect.Map: - for _, k := range f.MapKeys() { - e := f.MapIndex(k) - if e.IsNil() { - continue - } - setDefaults(e, recur, zeros) - } - } - } -} - -var ( - // defaults maps a protocol buffer struct type to a slice of the fields, - // with its scalar fields set to their proto-declared non-zero default values. - defaultMu sync.RWMutex - defaults = make(map[reflect.Type]defaultMessage) - - int32PtrType = reflect.TypeOf((*int32)(nil)) -) - -// defaultMessage represents information about the default values of a message. -type defaultMessage struct { - scalars []scalarField - nested []int // struct field index of nested messages -} - -type scalarField struct { - index int // struct field index - kind reflect.Kind // element type (the T in *T or []T) - value interface{} // the proto-declared default value, or nil -} - -// t is a struct type. -func buildDefaultMessage(t reflect.Type) (dm defaultMessage) { - sprop := GetProperties(t) - for _, prop := range sprop.Prop { - fi, ok := sprop.decoderTags.get(prop.Tag) - if !ok { - // XXX_unrecognized - continue - } - ft := t.Field(fi).Type - - sf, nested, err := fieldDefault(ft, prop) - switch { - case err != nil: - log.Print(err) - case nested: - dm.nested = append(dm.nested, fi) - case sf != nil: - sf.index = fi - dm.scalars = append(dm.scalars, *sf) - } - } - - return dm -} - -// fieldDefault returns the scalarField for field type ft. -// sf will be nil if the field can not have a default. -// nestedMessage will be true if this is a nested message. -// Note that sf.index is not set on return. -func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMessage bool, err error) { - var canHaveDefault bool - switch ft.Kind() { - case reflect.Ptr: - if ft.Elem().Kind() == reflect.Struct { - nestedMessage = true - } else { - canHaveDefault = true // proto2 scalar field - } - - case reflect.Slice: - switch ft.Elem().Kind() { - case reflect.Ptr: - nestedMessage = true // repeated message - case reflect.Uint8: - canHaveDefault = true // bytes field - } - - case reflect.Map: - if ft.Elem().Kind() == reflect.Ptr { - nestedMessage = true // map with message values - } - } - - if !canHaveDefault { - if nestedMessage { - return nil, true, nil - } - return nil, false, nil - } - - // We now know that ft is a pointer or slice. - sf = &scalarField{kind: ft.Elem().Kind()} - - // scalar fields without defaults - if !prop.HasDefault { - return sf, false, nil - } - - // a scalar field: either *T or []byte - switch ft.Elem().Kind() { - case reflect.Bool: - x, err := strconv.ParseBool(prop.Default) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default bool %q: %v", prop.Default, err) - } - sf.value = x - case reflect.Float32: - x, err := strconv.ParseFloat(prop.Default, 32) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default float32 %q: %v", prop.Default, err) - } - sf.value = float32(x) - case reflect.Float64: - x, err := strconv.ParseFloat(prop.Default, 64) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default float64 %q: %v", prop.Default, err) - } - sf.value = x - case reflect.Int32: - x, err := strconv.ParseInt(prop.Default, 10, 32) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default int32 %q: %v", prop.Default, err) - } - sf.value = int32(x) - case reflect.Int64: - x, err := strconv.ParseInt(prop.Default, 10, 64) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default int64 %q: %v", prop.Default, err) - } - sf.value = x - case reflect.String: - sf.value = prop.Default - case reflect.Uint8: - // []byte (not *uint8) - sf.value = []byte(prop.Default) - case reflect.Uint32: - x, err := strconv.ParseUint(prop.Default, 10, 32) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default uint32 %q: %v", prop.Default, err) - } - sf.value = uint32(x) - case reflect.Uint64: - x, err := strconv.ParseUint(prop.Default, 10, 64) - if err != nil { - return nil, false, fmt.Errorf("proto: bad default uint64 %q: %v", prop.Default, err) - } - sf.value = x - default: - return nil, false, fmt.Errorf("proto: unhandled def kind %v", ft.Elem().Kind()) - } - - return sf, false, nil -} - -// Map fields may have key types of non-float scalars, strings and enums. -// The easiest way to sort them in some deterministic order is to use fmt. -// If this turns out to be inefficient we can always consider other options, -// such as doing a Schwartzian transform. - -func mapKeys(vs []reflect.Value) sort.Interface { - s := mapKeySorter{ - vs: vs, - // default Less function: textual comparison - less: func(a, b reflect.Value) bool { - return fmt.Sprint(a.Interface()) < fmt.Sprint(b.Interface()) - }, - } - - // Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps; - // numeric keys are sorted numerically. - if len(vs) == 0 { - return s - } - switch vs[0].Kind() { - case reflect.Int32, reflect.Int64: - s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() } - case reflect.Uint32, reflect.Uint64: - s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() } - } - - return s -} - -type mapKeySorter struct { - vs []reflect.Value - less func(a, b reflect.Value) bool -} - -func (s mapKeySorter) Len() int { return len(s.vs) } -func (s mapKeySorter) Swap(i, j int) { s.vs[i], s.vs[j] = s.vs[j], s.vs[i] } -func (s mapKeySorter) Less(i, j int) bool { - return s.less(s.vs[i], s.vs[j]) -} - -// isProto3Zero reports whether v is a zero proto3 value. -func isProto3Zero(v reflect.Value) bool { - switch v.Kind() { - case reflect.Bool: - return !v.Bool() - case reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Uint32, reflect.Uint64: - return v.Uint() == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.String: - return v.String() == "" - } - return false -} - -// ProtoPackageIsVersion2 is referenced from generated protocol buffer files -// to assert that that code is compatible with this version of the proto package. -const ProtoPackageIsVersion2 = true - -// ProtoPackageIsVersion1 is referenced from generated protocol buffer files -// to assert that that code is compatible with this version of the proto package. -const ProtoPackageIsVersion1 = true diff --git a/vendor/github.com/golang/protobuf/proto/message_set.go b/vendor/github.com/golang/protobuf/proto/message_set.go deleted file mode 100644 index fd982decd66e4846031a72a785470be20afe99a5..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/message_set.go +++ /dev/null @@ -1,311 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -/* - * Support for message sets. - */ - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "reflect" - "sort" -) - -// errNoMessageTypeID occurs when a protocol buffer does not have a message type ID. -// A message type ID is required for storing a protocol buffer in a message set. -var errNoMessageTypeID = errors.New("proto does not have a message type ID") - -// The first two types (_MessageSet_Item and messageSet) -// model what the protocol compiler produces for the following protocol message: -// message MessageSet { -// repeated group Item = 1 { -// required int32 type_id = 2; -// required string message = 3; -// }; -// } -// That is the MessageSet wire format. We can't use a proto to generate these -// because that would introduce a circular dependency between it and this package. - -type _MessageSet_Item struct { - TypeId *int32 `protobuf:"varint,2,req,name=type_id"` - Message []byte `protobuf:"bytes,3,req,name=message"` -} - -type messageSet struct { - Item []*_MessageSet_Item `protobuf:"group,1,rep"` - XXX_unrecognized []byte - // TODO: caching? -} - -// Make sure messageSet is a Message. -var _ Message = (*messageSet)(nil) - -// messageTypeIder is an interface satisfied by a protocol buffer type -// that may be stored in a MessageSet. -type messageTypeIder interface { - MessageTypeId() int32 -} - -func (ms *messageSet) find(pb Message) *_MessageSet_Item { - mti, ok := pb.(messageTypeIder) - if !ok { - return nil - } - id := mti.MessageTypeId() - for _, item := range ms.Item { - if *item.TypeId == id { - return item - } - } - return nil -} - -func (ms *messageSet) Has(pb Message) bool { - if ms.find(pb) != nil { - return true - } - return false -} - -func (ms *messageSet) Unmarshal(pb Message) error { - if item := ms.find(pb); item != nil { - return Unmarshal(item.Message, pb) - } - if _, ok := pb.(messageTypeIder); !ok { - return errNoMessageTypeID - } - return nil // TODO: return error instead? -} - -func (ms *messageSet) Marshal(pb Message) error { - msg, err := Marshal(pb) - if err != nil { - return err - } - if item := ms.find(pb); item != nil { - // reuse existing item - item.Message = msg - return nil - } - - mti, ok := pb.(messageTypeIder) - if !ok { - return errNoMessageTypeID - } - - mtid := mti.MessageTypeId() - ms.Item = append(ms.Item, &_MessageSet_Item{ - TypeId: &mtid, - Message: msg, - }) - return nil -} - -func (ms *messageSet) Reset() { *ms = messageSet{} } -func (ms *messageSet) String() string { return CompactTextString(ms) } -func (*messageSet) ProtoMessage() {} - -// Support for the message_set_wire_format message option. - -func skipVarint(buf []byte) []byte { - i := 0 - for ; buf[i]&0x80 != 0; i++ { - } - return buf[i+1:] -} - -// MarshalMessageSet encodes the extension map represented by m in the message set wire format. -// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option. -func MarshalMessageSet(exts interface{}) ([]byte, error) { - var m map[int32]Extension - switch exts := exts.(type) { - case *XXX_InternalExtensions: - if err := encodeExtensions(exts); err != nil { - return nil, err - } - m, _ = exts.extensionsRead() - case map[int32]Extension: - if err := encodeExtensionsMap(exts); err != nil { - return nil, err - } - m = exts - default: - return nil, errors.New("proto: not an extension map") - } - - // Sort extension IDs to provide a deterministic encoding. - // See also enc_map in encode.go. - ids := make([]int, 0, len(m)) - for id := range m { - ids = append(ids, int(id)) - } - sort.Ints(ids) - - ms := &messageSet{Item: make([]*_MessageSet_Item, 0, len(m))} - for _, id := range ids { - e := m[int32(id)] - // Remove the wire type and field number varint, as well as the length varint. - msg := skipVarint(skipVarint(e.enc)) - - ms.Item = append(ms.Item, &_MessageSet_Item{ - TypeId: Int32(int32(id)), - Message: msg, - }) - } - return Marshal(ms) -} - -// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format. -// It is called by generated Unmarshal methods on protocol buffer messages with the message_set_wire_format option. -func UnmarshalMessageSet(buf []byte, exts interface{}) error { - var m map[int32]Extension - switch exts := exts.(type) { - case *XXX_InternalExtensions: - m = exts.extensionsWrite() - case map[int32]Extension: - m = exts - default: - return errors.New("proto: not an extension map") - } - - ms := new(messageSet) - if err := Unmarshal(buf, ms); err != nil { - return err - } - for _, item := range ms.Item { - id := *item.TypeId - msg := item.Message - - // Restore wire type and field number varint, plus length varint. - // Be careful to preserve duplicate items. - b := EncodeVarint(uint64(id)<<3 | WireBytes) - if ext, ok := m[id]; ok { - // Existing data; rip off the tag and length varint - // so we join the new data correctly. - // We can assume that ext.enc is set because we are unmarshaling. - o := ext.enc[len(b):] // skip wire type and field number - _, n := DecodeVarint(o) // calculate length of length varint - o = o[n:] // skip length varint - msg = append(o, msg...) // join old data and new data - } - b = append(b, EncodeVarint(uint64(len(msg)))...) - b = append(b, msg...) - - m[id] = Extension{enc: b} - } - return nil -} - -// MarshalMessageSetJSON encodes the extension map represented by m in JSON format. -// It is called by generated MarshalJSON methods on protocol buffer messages with the message_set_wire_format option. -func MarshalMessageSetJSON(exts interface{}) ([]byte, error) { - var m map[int32]Extension - switch exts := exts.(type) { - case *XXX_InternalExtensions: - m, _ = exts.extensionsRead() - case map[int32]Extension: - m = exts - default: - return nil, errors.New("proto: not an extension map") - } - var b bytes.Buffer - b.WriteByte('{') - - // Process the map in key order for deterministic output. - ids := make([]int32, 0, len(m)) - for id := range m { - ids = append(ids, id) - } - sort.Sort(int32Slice(ids)) // int32Slice defined in text.go - - for i, id := range ids { - ext := m[id] - if i > 0 { - b.WriteByte(',') - } - - msd, ok := messageSetMap[id] - if !ok { - // Unknown type; we can't render it, so skip it. - continue - } - fmt.Fprintf(&b, `"[%s]":`, msd.name) - - x := ext.value - if x == nil { - x = reflect.New(msd.t.Elem()).Interface() - if err := Unmarshal(ext.enc, x.(Message)); err != nil { - return nil, err - } - } - d, err := json.Marshal(x) - if err != nil { - return nil, err - } - b.Write(d) - } - b.WriteByte('}') - return b.Bytes(), nil -} - -// UnmarshalMessageSetJSON decodes the extension map encoded in buf in JSON format. -// It is called by generated UnmarshalJSON methods on protocol buffer messages with the message_set_wire_format option. -func UnmarshalMessageSetJSON(buf []byte, exts interface{}) error { - // Common-case fast path. - if len(buf) == 0 || bytes.Equal(buf, []byte("{}")) { - return nil - } - - // This is fairly tricky, and it's not clear that it is needed. - return errors.New("TODO: UnmarshalMessageSetJSON not yet implemented") -} - -// A global registry of types that can be used in a MessageSet. - -var messageSetMap = make(map[int32]messageSetDesc) - -type messageSetDesc struct { - t reflect.Type // pointer to struct - name string -} - -// RegisterMessageSetType is called from the generated code. -func RegisterMessageSetType(m Message, fieldNum int32, name string) { - messageSetMap[fieldNum] = messageSetDesc{ - t: reflect.TypeOf(m), - name: name, - } -} diff --git a/vendor/github.com/golang/protobuf/proto/pointer_reflect.go b/vendor/github.com/golang/protobuf/proto/pointer_reflect.go deleted file mode 100644 index fb512e2e16dce05683722f810c279367bdc68fe9..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/pointer_reflect.go +++ /dev/null @@ -1,484 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2012 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// +build appengine js - -// This file contains an implementation of proto field accesses using package reflect. -// It is slower than the code in pointer_unsafe.go but it avoids package unsafe and can -// be used on App Engine. - -package proto - -import ( - "math" - "reflect" -) - -// A structPointer is a pointer to a struct. -type structPointer struct { - v reflect.Value -} - -// toStructPointer returns a structPointer equivalent to the given reflect value. -// The reflect value must itself be a pointer to a struct. -func toStructPointer(v reflect.Value) structPointer { - return structPointer{v} -} - -// IsNil reports whether p is nil. -func structPointer_IsNil(p structPointer) bool { - return p.v.IsNil() -} - -// Interface returns the struct pointer as an interface value. -func structPointer_Interface(p structPointer, _ reflect.Type) interface{} { - return p.v.Interface() -} - -// A field identifies a field in a struct, accessible from a structPointer. -// In this implementation, a field is identified by the sequence of field indices -// passed to reflect's FieldByIndex. -type field []int - -// toField returns a field equivalent to the given reflect field. -func toField(f *reflect.StructField) field { - return f.Index -} - -// invalidField is an invalid field identifier. -var invalidField = field(nil) - -// IsValid reports whether the field identifier is valid. -func (f field) IsValid() bool { return f != nil } - -// field returns the given field in the struct as a reflect value. -func structPointer_field(p structPointer, f field) reflect.Value { - // Special case: an extension map entry with a value of type T - // passes a *T to the struct-handling code with a zero field, - // expecting that it will be treated as equivalent to *struct{ X T }, - // which has the same memory layout. We have to handle that case - // specially, because reflect will panic if we call FieldByIndex on a - // non-struct. - if f == nil { - return p.v.Elem() - } - - return p.v.Elem().FieldByIndex(f) -} - -// ifield returns the given field in the struct as an interface value. -func structPointer_ifield(p structPointer, f field) interface{} { - return structPointer_field(p, f).Addr().Interface() -} - -// Bytes returns the address of a []byte field in the struct. -func structPointer_Bytes(p structPointer, f field) *[]byte { - return structPointer_ifield(p, f).(*[]byte) -} - -// BytesSlice returns the address of a [][]byte field in the struct. -func structPointer_BytesSlice(p structPointer, f field) *[][]byte { - return structPointer_ifield(p, f).(*[][]byte) -} - -// Bool returns the address of a *bool field in the struct. -func structPointer_Bool(p structPointer, f field) **bool { - return structPointer_ifield(p, f).(**bool) -} - -// BoolVal returns the address of a bool field in the struct. -func structPointer_BoolVal(p structPointer, f field) *bool { - return structPointer_ifield(p, f).(*bool) -} - -// BoolSlice returns the address of a []bool field in the struct. -func structPointer_BoolSlice(p structPointer, f field) *[]bool { - return structPointer_ifield(p, f).(*[]bool) -} - -// String returns the address of a *string field in the struct. -func structPointer_String(p structPointer, f field) **string { - return structPointer_ifield(p, f).(**string) -} - -// StringVal returns the address of a string field in the struct. -func structPointer_StringVal(p structPointer, f field) *string { - return structPointer_ifield(p, f).(*string) -} - -// StringSlice returns the address of a []string field in the struct. -func structPointer_StringSlice(p structPointer, f field) *[]string { - return structPointer_ifield(p, f).(*[]string) -} - -// Extensions returns the address of an extension map field in the struct. -func structPointer_Extensions(p structPointer, f field) *XXX_InternalExtensions { - return structPointer_ifield(p, f).(*XXX_InternalExtensions) -} - -// ExtMap returns the address of an extension map field in the struct. -func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension { - return structPointer_ifield(p, f).(*map[int32]Extension) -} - -// NewAt returns the reflect.Value for a pointer to a field in the struct. -func structPointer_NewAt(p structPointer, f field, typ reflect.Type) reflect.Value { - return structPointer_field(p, f).Addr() -} - -// SetStructPointer writes a *struct field in the struct. -func structPointer_SetStructPointer(p structPointer, f field, q structPointer) { - structPointer_field(p, f).Set(q.v) -} - -// GetStructPointer reads a *struct field in the struct. -func structPointer_GetStructPointer(p structPointer, f field) structPointer { - return structPointer{structPointer_field(p, f)} -} - -// StructPointerSlice the address of a []*struct field in the struct. -func structPointer_StructPointerSlice(p structPointer, f field) structPointerSlice { - return structPointerSlice{structPointer_field(p, f)} -} - -// A structPointerSlice represents the address of a slice of pointers to structs -// (themselves messages or groups). That is, v.Type() is *[]*struct{...}. -type structPointerSlice struct { - v reflect.Value -} - -func (p structPointerSlice) Len() int { return p.v.Len() } -func (p structPointerSlice) Index(i int) structPointer { return structPointer{p.v.Index(i)} } -func (p structPointerSlice) Append(q structPointer) { - p.v.Set(reflect.Append(p.v, q.v)) -} - -var ( - int32Type = reflect.TypeOf(int32(0)) - uint32Type = reflect.TypeOf(uint32(0)) - float32Type = reflect.TypeOf(float32(0)) - int64Type = reflect.TypeOf(int64(0)) - uint64Type = reflect.TypeOf(uint64(0)) - float64Type = reflect.TypeOf(float64(0)) -) - -// A word32 represents a field of type *int32, *uint32, *float32, or *enum. -// That is, v.Type() is *int32, *uint32, *float32, or *enum and v is assignable. -type word32 struct { - v reflect.Value -} - -// IsNil reports whether p is nil. -func word32_IsNil(p word32) bool { - return p.v.IsNil() -} - -// Set sets p to point at a newly allocated word with bits set to x. -func word32_Set(p word32, o *Buffer, x uint32) { - t := p.v.Type().Elem() - switch t { - case int32Type: - if len(o.int32s) == 0 { - o.int32s = make([]int32, uint32PoolSize) - } - o.int32s[0] = int32(x) - p.v.Set(reflect.ValueOf(&o.int32s[0])) - o.int32s = o.int32s[1:] - return - case uint32Type: - if len(o.uint32s) == 0 { - o.uint32s = make([]uint32, uint32PoolSize) - } - o.uint32s[0] = x - p.v.Set(reflect.ValueOf(&o.uint32s[0])) - o.uint32s = o.uint32s[1:] - return - case float32Type: - if len(o.float32s) == 0 { - o.float32s = make([]float32, uint32PoolSize) - } - o.float32s[0] = math.Float32frombits(x) - p.v.Set(reflect.ValueOf(&o.float32s[0])) - o.float32s = o.float32s[1:] - return - } - - // must be enum - p.v.Set(reflect.New(t)) - p.v.Elem().SetInt(int64(int32(x))) -} - -// Get gets the bits pointed at by p, as a uint32. -func word32_Get(p word32) uint32 { - elem := p.v.Elem() - switch elem.Kind() { - case reflect.Int32: - return uint32(elem.Int()) - case reflect.Uint32: - return uint32(elem.Uint()) - case reflect.Float32: - return math.Float32bits(float32(elem.Float())) - } - panic("unreachable") -} - -// Word32 returns a reference to a *int32, *uint32, *float32, or *enum field in the struct. -func structPointer_Word32(p structPointer, f field) word32 { - return word32{structPointer_field(p, f)} -} - -// A word32Val represents a field of type int32, uint32, float32, or enum. -// That is, v.Type() is int32, uint32, float32, or enum and v is assignable. -type word32Val struct { - v reflect.Value -} - -// Set sets *p to x. -func word32Val_Set(p word32Val, x uint32) { - switch p.v.Type() { - case int32Type: - p.v.SetInt(int64(x)) - return - case uint32Type: - p.v.SetUint(uint64(x)) - return - case float32Type: - p.v.SetFloat(float64(math.Float32frombits(x))) - return - } - - // must be enum - p.v.SetInt(int64(int32(x))) -} - -// Get gets the bits pointed at by p, as a uint32. -func word32Val_Get(p word32Val) uint32 { - elem := p.v - switch elem.Kind() { - case reflect.Int32: - return uint32(elem.Int()) - case reflect.Uint32: - return uint32(elem.Uint()) - case reflect.Float32: - return math.Float32bits(float32(elem.Float())) - } - panic("unreachable") -} - -// Word32Val returns a reference to a int32, uint32, float32, or enum field in the struct. -func structPointer_Word32Val(p structPointer, f field) word32Val { - return word32Val{structPointer_field(p, f)} -} - -// A word32Slice is a slice of 32-bit values. -// That is, v.Type() is []int32, []uint32, []float32, or []enum. -type word32Slice struct { - v reflect.Value -} - -func (p word32Slice) Append(x uint32) { - n, m := p.v.Len(), p.v.Cap() - if n < m { - p.v.SetLen(n + 1) - } else { - t := p.v.Type().Elem() - p.v.Set(reflect.Append(p.v, reflect.Zero(t))) - } - elem := p.v.Index(n) - switch elem.Kind() { - case reflect.Int32: - elem.SetInt(int64(int32(x))) - case reflect.Uint32: - elem.SetUint(uint64(x)) - case reflect.Float32: - elem.SetFloat(float64(math.Float32frombits(x))) - } -} - -func (p word32Slice) Len() int { - return p.v.Len() -} - -func (p word32Slice) Index(i int) uint32 { - elem := p.v.Index(i) - switch elem.Kind() { - case reflect.Int32: - return uint32(elem.Int()) - case reflect.Uint32: - return uint32(elem.Uint()) - case reflect.Float32: - return math.Float32bits(float32(elem.Float())) - } - panic("unreachable") -} - -// Word32Slice returns a reference to a []int32, []uint32, []float32, or []enum field in the struct. -func structPointer_Word32Slice(p structPointer, f field) word32Slice { - return word32Slice{structPointer_field(p, f)} -} - -// word64 is like word32 but for 64-bit values. -type word64 struct { - v reflect.Value -} - -func word64_Set(p word64, o *Buffer, x uint64) { - t := p.v.Type().Elem() - switch t { - case int64Type: - if len(o.int64s) == 0 { - o.int64s = make([]int64, uint64PoolSize) - } - o.int64s[0] = int64(x) - p.v.Set(reflect.ValueOf(&o.int64s[0])) - o.int64s = o.int64s[1:] - return - case uint64Type: - if len(o.uint64s) == 0 { - o.uint64s = make([]uint64, uint64PoolSize) - } - o.uint64s[0] = x - p.v.Set(reflect.ValueOf(&o.uint64s[0])) - o.uint64s = o.uint64s[1:] - return - case float64Type: - if len(o.float64s) == 0 { - o.float64s = make([]float64, uint64PoolSize) - } - o.float64s[0] = math.Float64frombits(x) - p.v.Set(reflect.ValueOf(&o.float64s[0])) - o.float64s = o.float64s[1:] - return - } - panic("unreachable") -} - -func word64_IsNil(p word64) bool { - return p.v.IsNil() -} - -func word64_Get(p word64) uint64 { - elem := p.v.Elem() - switch elem.Kind() { - case reflect.Int64: - return uint64(elem.Int()) - case reflect.Uint64: - return elem.Uint() - case reflect.Float64: - return math.Float64bits(elem.Float()) - } - panic("unreachable") -} - -func structPointer_Word64(p structPointer, f field) word64 { - return word64{structPointer_field(p, f)} -} - -// word64Val is like word32Val but for 64-bit values. -type word64Val struct { - v reflect.Value -} - -func word64Val_Set(p word64Val, o *Buffer, x uint64) { - switch p.v.Type() { - case int64Type: - p.v.SetInt(int64(x)) - return - case uint64Type: - p.v.SetUint(x) - return - case float64Type: - p.v.SetFloat(math.Float64frombits(x)) - return - } - panic("unreachable") -} - -func word64Val_Get(p word64Val) uint64 { - elem := p.v - switch elem.Kind() { - case reflect.Int64: - return uint64(elem.Int()) - case reflect.Uint64: - return elem.Uint() - case reflect.Float64: - return math.Float64bits(elem.Float()) - } - panic("unreachable") -} - -func structPointer_Word64Val(p structPointer, f field) word64Val { - return word64Val{structPointer_field(p, f)} -} - -type word64Slice struct { - v reflect.Value -} - -func (p word64Slice) Append(x uint64) { - n, m := p.v.Len(), p.v.Cap() - if n < m { - p.v.SetLen(n + 1) - } else { - t := p.v.Type().Elem() - p.v.Set(reflect.Append(p.v, reflect.Zero(t))) - } - elem := p.v.Index(n) - switch elem.Kind() { - case reflect.Int64: - elem.SetInt(int64(int64(x))) - case reflect.Uint64: - elem.SetUint(uint64(x)) - case reflect.Float64: - elem.SetFloat(float64(math.Float64frombits(x))) - } -} - -func (p word64Slice) Len() int { - return p.v.Len() -} - -func (p word64Slice) Index(i int) uint64 { - elem := p.v.Index(i) - switch elem.Kind() { - case reflect.Int64: - return uint64(elem.Int()) - case reflect.Uint64: - return uint64(elem.Uint()) - case reflect.Float64: - return math.Float64bits(float64(elem.Float())) - } - panic("unreachable") -} - -func structPointer_Word64Slice(p structPointer, f field) word64Slice { - return word64Slice{structPointer_field(p, f)} -} diff --git a/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go b/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go deleted file mode 100644 index 6b5567d47cd396b25370f8c06bad3b851776658f..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go +++ /dev/null @@ -1,270 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2012 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// +build !appengine,!js - -// This file contains the implementation of the proto field accesses using package unsafe. - -package proto - -import ( - "reflect" - "unsafe" -) - -// NOTE: These type_Foo functions would more idiomatically be methods, -// but Go does not allow methods on pointer types, and we must preserve -// some pointer type for the garbage collector. We use these -// funcs with clunky names as our poor approximation to methods. -// -// An alternative would be -// type structPointer struct { p unsafe.Pointer } -// but that does not registerize as well. - -// A structPointer is a pointer to a struct. -type structPointer unsafe.Pointer - -// toStructPointer returns a structPointer equivalent to the given reflect value. -func toStructPointer(v reflect.Value) structPointer { - return structPointer(unsafe.Pointer(v.Pointer())) -} - -// IsNil reports whether p is nil. -func structPointer_IsNil(p structPointer) bool { - return p == nil -} - -// Interface returns the struct pointer, assumed to have element type t, -// as an interface value. -func structPointer_Interface(p structPointer, t reflect.Type) interface{} { - return reflect.NewAt(t, unsafe.Pointer(p)).Interface() -} - -// A field identifies a field in a struct, accessible from a structPointer. -// In this implementation, a field is identified by its byte offset from the start of the struct. -type field uintptr - -// toField returns a field equivalent to the given reflect field. -func toField(f *reflect.StructField) field { - return field(f.Offset) -} - -// invalidField is an invalid field identifier. -const invalidField = ^field(0) - -// IsValid reports whether the field identifier is valid. -func (f field) IsValid() bool { - return f != ^field(0) -} - -// Bytes returns the address of a []byte field in the struct. -func structPointer_Bytes(p structPointer, f field) *[]byte { - return (*[]byte)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// BytesSlice returns the address of a [][]byte field in the struct. -func structPointer_BytesSlice(p structPointer, f field) *[][]byte { - return (*[][]byte)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// Bool returns the address of a *bool field in the struct. -func structPointer_Bool(p structPointer, f field) **bool { - return (**bool)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// BoolVal returns the address of a bool field in the struct. -func structPointer_BoolVal(p structPointer, f field) *bool { - return (*bool)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// BoolSlice returns the address of a []bool field in the struct. -func structPointer_BoolSlice(p structPointer, f field) *[]bool { - return (*[]bool)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// String returns the address of a *string field in the struct. -func structPointer_String(p structPointer, f field) **string { - return (**string)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// StringVal returns the address of a string field in the struct. -func structPointer_StringVal(p structPointer, f field) *string { - return (*string)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// StringSlice returns the address of a []string field in the struct. -func structPointer_StringSlice(p structPointer, f field) *[]string { - return (*[]string)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// ExtMap returns the address of an extension map field in the struct. -func structPointer_Extensions(p structPointer, f field) *XXX_InternalExtensions { - return (*XXX_InternalExtensions)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension { - return (*map[int32]Extension)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// NewAt returns the reflect.Value for a pointer to a field in the struct. -func structPointer_NewAt(p structPointer, f field, typ reflect.Type) reflect.Value { - return reflect.NewAt(typ, unsafe.Pointer(uintptr(p)+uintptr(f))) -} - -// SetStructPointer writes a *struct field in the struct. -func structPointer_SetStructPointer(p structPointer, f field, q structPointer) { - *(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f))) = q -} - -// GetStructPointer reads a *struct field in the struct. -func structPointer_GetStructPointer(p structPointer, f field) structPointer { - return *(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// StructPointerSlice the address of a []*struct field in the struct. -func structPointer_StructPointerSlice(p structPointer, f field) *structPointerSlice { - return (*structPointerSlice)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// A structPointerSlice represents a slice of pointers to structs (themselves submessages or groups). -type structPointerSlice []structPointer - -func (v *structPointerSlice) Len() int { return len(*v) } -func (v *structPointerSlice) Index(i int) structPointer { return (*v)[i] } -func (v *structPointerSlice) Append(p structPointer) { *v = append(*v, p) } - -// A word32 is the address of a "pointer to 32-bit value" field. -type word32 **uint32 - -// IsNil reports whether *v is nil. -func word32_IsNil(p word32) bool { - return *p == nil -} - -// Set sets *v to point at a newly allocated word set to x. -func word32_Set(p word32, o *Buffer, x uint32) { - if len(o.uint32s) == 0 { - o.uint32s = make([]uint32, uint32PoolSize) - } - o.uint32s[0] = x - *p = &o.uint32s[0] - o.uint32s = o.uint32s[1:] -} - -// Get gets the value pointed at by *v. -func word32_Get(p word32) uint32 { - return **p -} - -// Word32 returns the address of a *int32, *uint32, *float32, or *enum field in the struct. -func structPointer_Word32(p structPointer, f field) word32 { - return word32((**uint32)(unsafe.Pointer(uintptr(p) + uintptr(f)))) -} - -// A word32Val is the address of a 32-bit value field. -type word32Val *uint32 - -// Set sets *p to x. -func word32Val_Set(p word32Val, x uint32) { - *p = x -} - -// Get gets the value pointed at by p. -func word32Val_Get(p word32Val) uint32 { - return *p -} - -// Word32Val returns the address of a *int32, *uint32, *float32, or *enum field in the struct. -func structPointer_Word32Val(p structPointer, f field) word32Val { - return word32Val((*uint32)(unsafe.Pointer(uintptr(p) + uintptr(f)))) -} - -// A word32Slice is a slice of 32-bit values. -type word32Slice []uint32 - -func (v *word32Slice) Append(x uint32) { *v = append(*v, x) } -func (v *word32Slice) Len() int { return len(*v) } -func (v *word32Slice) Index(i int) uint32 { return (*v)[i] } - -// Word32Slice returns the address of a []int32, []uint32, []float32, or []enum field in the struct. -func structPointer_Word32Slice(p structPointer, f field) *word32Slice { - return (*word32Slice)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} - -// word64 is like word32 but for 64-bit values. -type word64 **uint64 - -func word64_Set(p word64, o *Buffer, x uint64) { - if len(o.uint64s) == 0 { - o.uint64s = make([]uint64, uint64PoolSize) - } - o.uint64s[0] = x - *p = &o.uint64s[0] - o.uint64s = o.uint64s[1:] -} - -func word64_IsNil(p word64) bool { - return *p == nil -} - -func word64_Get(p word64) uint64 { - return **p -} - -func structPointer_Word64(p structPointer, f field) word64 { - return word64((**uint64)(unsafe.Pointer(uintptr(p) + uintptr(f)))) -} - -// word64Val is like word32Val but for 64-bit values. -type word64Val *uint64 - -func word64Val_Set(p word64Val, o *Buffer, x uint64) { - *p = x -} - -func word64Val_Get(p word64Val) uint64 { - return *p -} - -func structPointer_Word64Val(p structPointer, f field) word64Val { - return word64Val((*uint64)(unsafe.Pointer(uintptr(p) + uintptr(f)))) -} - -// word64Slice is like word32Slice but for 64-bit values. -type word64Slice []uint64 - -func (v *word64Slice) Append(x uint64) { *v = append(*v, x) } -func (v *word64Slice) Len() int { return len(*v) } -func (v *word64Slice) Index(i int) uint64 { return (*v)[i] } - -func structPointer_Word64Slice(p structPointer, f field) *word64Slice { - return (*word64Slice)(unsafe.Pointer(uintptr(p) + uintptr(f))) -} diff --git a/vendor/github.com/golang/protobuf/proto/properties.go b/vendor/github.com/golang/protobuf/proto/properties.go deleted file mode 100644 index ec2289c0058e47e3d20fa2bef7a3979529aa7512..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/properties.go +++ /dev/null @@ -1,872 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -/* - * Routines for encoding data into the wire format for protocol buffers. - */ - -import ( - "fmt" - "log" - "os" - "reflect" - "sort" - "strconv" - "strings" - "sync" -) - -const debug bool = false - -// Constants that identify the encoding of a value on the wire. -const ( - WireVarint = 0 - WireFixed64 = 1 - WireBytes = 2 - WireStartGroup = 3 - WireEndGroup = 4 - WireFixed32 = 5 -) - -const startSize = 10 // initial slice/string sizes - -// Encoders are defined in encode.go -// An encoder outputs the full representation of a field, including its -// tag and encoder type. -type encoder func(p *Buffer, prop *Properties, base structPointer) error - -// A valueEncoder encodes a single integer in a particular encoding. -type valueEncoder func(o *Buffer, x uint64) error - -// Sizers are defined in encode.go -// A sizer returns the encoded size of a field, including its tag and encoder -// type. -type sizer func(prop *Properties, base structPointer) int - -// A valueSizer returns the encoded size of a single integer in a particular -// encoding. -type valueSizer func(x uint64) int - -// Decoders are defined in decode.go -// A decoder creates a value from its wire representation. -// Unrecognized subelements are saved in unrec. -type decoder func(p *Buffer, prop *Properties, base structPointer) error - -// A valueDecoder decodes a single integer in a particular encoding. -type valueDecoder func(o *Buffer) (x uint64, err error) - -// A oneofMarshaler does the marshaling for all oneof fields in a message. -type oneofMarshaler func(Message, *Buffer) error - -// A oneofUnmarshaler does the unmarshaling for a oneof field in a message. -type oneofUnmarshaler func(Message, int, int, *Buffer) (bool, error) - -// A oneofSizer does the sizing for all oneof fields in a message. -type oneofSizer func(Message) int - -// tagMap is an optimization over map[int]int for typical protocol buffer -// use-cases. Encoded protocol buffers are often in tag order with small tag -// numbers. -type tagMap struct { - fastTags []int - slowTags map[int]int -} - -// tagMapFastLimit is the upper bound on the tag number that will be stored in -// the tagMap slice rather than its map. -const tagMapFastLimit = 1024 - -func (p *tagMap) get(t int) (int, bool) { - if t > 0 && t < tagMapFastLimit { - if t >= len(p.fastTags) { - return 0, false - } - fi := p.fastTags[t] - return fi, fi >= 0 - } - fi, ok := p.slowTags[t] - return fi, ok -} - -func (p *tagMap) put(t int, fi int) { - if t > 0 && t < tagMapFastLimit { - for len(p.fastTags) < t+1 { - p.fastTags = append(p.fastTags, -1) - } - p.fastTags[t] = fi - return - } - if p.slowTags == nil { - p.slowTags = make(map[int]int) - } - p.slowTags[t] = fi -} - -// StructProperties represents properties for all the fields of a struct. -// decoderTags and decoderOrigNames should only be used by the decoder. -type StructProperties struct { - Prop []*Properties // properties for each field - reqCount int // required count - decoderTags tagMap // map from proto tag to struct field number - decoderOrigNames map[string]int // map from original name to struct field number - order []int // list of struct field numbers in tag order - unrecField field // field id of the XXX_unrecognized []byte field - extendable bool // is this an extendable proto - - oneofMarshaler oneofMarshaler - oneofUnmarshaler oneofUnmarshaler - oneofSizer oneofSizer - stype reflect.Type - - // OneofTypes contains information about the oneof fields in this message. - // It is keyed by the original name of a field. - OneofTypes map[string]*OneofProperties -} - -// OneofProperties represents information about a specific field in a oneof. -type OneofProperties struct { - Type reflect.Type // pointer to generated struct type for this oneof field - Field int // struct field number of the containing oneof in the message - Prop *Properties -} - -// Implement the sorting interface so we can sort the fields in tag order, as recommended by the spec. -// See encode.go, (*Buffer).enc_struct. - -func (sp *StructProperties) Len() int { return len(sp.order) } -func (sp *StructProperties) Less(i, j int) bool { - return sp.Prop[sp.order[i]].Tag < sp.Prop[sp.order[j]].Tag -} -func (sp *StructProperties) Swap(i, j int) { sp.order[i], sp.order[j] = sp.order[j], sp.order[i] } - -// Properties represents the protocol-specific behavior of a single struct field. -type Properties struct { - Name string // name of the field, for error messages - OrigName string // original name before protocol compiler (always set) - JSONName string // name to use for JSON; determined by protoc - Wire string - WireType int - Tag int - Required bool - Optional bool - Repeated bool - Packed bool // relevant for repeated primitives only - Enum string // set for enum types only - proto3 bool // whether this is known to be a proto3 field; set for []byte only - oneof bool // whether this is a oneof field - - Default string // default value - HasDefault bool // whether an explicit default was provided - def_uint64 uint64 - - enc encoder - valEnc valueEncoder // set for bool and numeric types only - field field - tagcode []byte // encoding of EncodeVarint((Tag<<3)|WireType) - tagbuf [8]byte - stype reflect.Type // set for struct types only - sprop *StructProperties // set for struct types only - isMarshaler bool - isUnmarshaler bool - - mtype reflect.Type // set for map types only - mkeyprop *Properties // set for map types only - mvalprop *Properties // set for map types only - - size sizer - valSize valueSizer // set for bool and numeric types only - - dec decoder - valDec valueDecoder // set for bool and numeric types only - - // If this is a packable field, this will be the decoder for the packed version of the field. - packedDec decoder -} - -// String formats the properties in the protobuf struct field tag style. -func (p *Properties) String() string { - s := p.Wire - s = "," - s += strconv.Itoa(p.Tag) - if p.Required { - s += ",req" - } - if p.Optional { - s += ",opt" - } - if p.Repeated { - s += ",rep" - } - if p.Packed { - s += ",packed" - } - s += ",name=" + p.OrigName - if p.JSONName != p.OrigName { - s += ",json=" + p.JSONName - } - if p.proto3 { - s += ",proto3" - } - if p.oneof { - s += ",oneof" - } - if len(p.Enum) > 0 { - s += ",enum=" + p.Enum - } - if p.HasDefault { - s += ",def=" + p.Default - } - return s -} - -// Parse populates p by parsing a string in the protobuf struct field tag style. -func (p *Properties) Parse(s string) { - // "bytes,49,opt,name=foo,def=hello!" - fields := strings.Split(s, ",") // breaks def=, but handled below. - if len(fields) < 2 { - fmt.Fprintf(os.Stderr, "proto: tag has too few fields: %q\n", s) - return - } - - p.Wire = fields[0] - switch p.Wire { - case "varint": - p.WireType = WireVarint - p.valEnc = (*Buffer).EncodeVarint - p.valDec = (*Buffer).DecodeVarint - p.valSize = sizeVarint - case "fixed32": - p.WireType = WireFixed32 - p.valEnc = (*Buffer).EncodeFixed32 - p.valDec = (*Buffer).DecodeFixed32 - p.valSize = sizeFixed32 - case "fixed64": - p.WireType = WireFixed64 - p.valEnc = (*Buffer).EncodeFixed64 - p.valDec = (*Buffer).DecodeFixed64 - p.valSize = sizeFixed64 - case "zigzag32": - p.WireType = WireVarint - p.valEnc = (*Buffer).EncodeZigzag32 - p.valDec = (*Buffer).DecodeZigzag32 - p.valSize = sizeZigzag32 - case "zigzag64": - p.WireType = WireVarint - p.valEnc = (*Buffer).EncodeZigzag64 - p.valDec = (*Buffer).DecodeZigzag64 - p.valSize = sizeZigzag64 - case "bytes", "group": - p.WireType = WireBytes - // no numeric converter for non-numeric types - default: - fmt.Fprintf(os.Stderr, "proto: tag has unknown wire type: %q\n", s) - return - } - - var err error - p.Tag, err = strconv.Atoi(fields[1]) - if err != nil { - return - } - - for i := 2; i < len(fields); i++ { - f := fields[i] - switch { - case f == "req": - p.Required = true - case f == "opt": - p.Optional = true - case f == "rep": - p.Repeated = true - case f == "packed": - p.Packed = true - case strings.HasPrefix(f, "name="): - p.OrigName = f[5:] - case strings.HasPrefix(f, "json="): - p.JSONName = f[5:] - case strings.HasPrefix(f, "enum="): - p.Enum = f[5:] - case f == "proto3": - p.proto3 = true - case f == "oneof": - p.oneof = true - case strings.HasPrefix(f, "def="): - p.HasDefault = true - p.Default = f[4:] // rest of string - if i+1 < len(fields) { - // Commas aren't escaped, and def is always last. - p.Default += "," + strings.Join(fields[i+1:], ",") - break - } - } - } -} - -func logNoSliceEnc(t1, t2 reflect.Type) { - fmt.Fprintf(os.Stderr, "proto: no slice oenc for %T = []%T\n", t1, t2) -} - -var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem() - -// Initialize the fields for encoding and decoding. -func (p *Properties) setEncAndDec(typ reflect.Type, f *reflect.StructField, lockGetProp bool) { - p.enc = nil - p.dec = nil - p.size = nil - - switch t1 := typ; t1.Kind() { - default: - fmt.Fprintf(os.Stderr, "proto: no coders for %v\n", t1) - - // proto3 scalar types - - case reflect.Bool: - p.enc = (*Buffer).enc_proto3_bool - p.dec = (*Buffer).dec_proto3_bool - p.size = size_proto3_bool - case reflect.Int32: - p.enc = (*Buffer).enc_proto3_int32 - p.dec = (*Buffer).dec_proto3_int32 - p.size = size_proto3_int32 - case reflect.Uint32: - p.enc = (*Buffer).enc_proto3_uint32 - p.dec = (*Buffer).dec_proto3_int32 // can reuse - p.size = size_proto3_uint32 - case reflect.Int64, reflect.Uint64: - p.enc = (*Buffer).enc_proto3_int64 - p.dec = (*Buffer).dec_proto3_int64 - p.size = size_proto3_int64 - case reflect.Float32: - p.enc = (*Buffer).enc_proto3_uint32 // can just treat them as bits - p.dec = (*Buffer).dec_proto3_int32 - p.size = size_proto3_uint32 - case reflect.Float64: - p.enc = (*Buffer).enc_proto3_int64 // can just treat them as bits - p.dec = (*Buffer).dec_proto3_int64 - p.size = size_proto3_int64 - case reflect.String: - p.enc = (*Buffer).enc_proto3_string - p.dec = (*Buffer).dec_proto3_string - p.size = size_proto3_string - - case reflect.Ptr: - switch t2 := t1.Elem(); t2.Kind() { - default: - fmt.Fprintf(os.Stderr, "proto: no encoder function for %v -> %v\n", t1, t2) - break - case reflect.Bool: - p.enc = (*Buffer).enc_bool - p.dec = (*Buffer).dec_bool - p.size = size_bool - case reflect.Int32: - p.enc = (*Buffer).enc_int32 - p.dec = (*Buffer).dec_int32 - p.size = size_int32 - case reflect.Uint32: - p.enc = (*Buffer).enc_uint32 - p.dec = (*Buffer).dec_int32 // can reuse - p.size = size_uint32 - case reflect.Int64, reflect.Uint64: - p.enc = (*Buffer).enc_int64 - p.dec = (*Buffer).dec_int64 - p.size = size_int64 - case reflect.Float32: - p.enc = (*Buffer).enc_uint32 // can just treat them as bits - p.dec = (*Buffer).dec_int32 - p.size = size_uint32 - case reflect.Float64: - p.enc = (*Buffer).enc_int64 // can just treat them as bits - p.dec = (*Buffer).dec_int64 - p.size = size_int64 - case reflect.String: - p.enc = (*Buffer).enc_string - p.dec = (*Buffer).dec_string - p.size = size_string - case reflect.Struct: - p.stype = t1.Elem() - p.isMarshaler = isMarshaler(t1) - p.isUnmarshaler = isUnmarshaler(t1) - if p.Wire == "bytes" { - p.enc = (*Buffer).enc_struct_message - p.dec = (*Buffer).dec_struct_message - p.size = size_struct_message - } else { - p.enc = (*Buffer).enc_struct_group - p.dec = (*Buffer).dec_struct_group - p.size = size_struct_group - } - } - - case reflect.Slice: - switch t2 := t1.Elem(); t2.Kind() { - default: - logNoSliceEnc(t1, t2) - break - case reflect.Bool: - if p.Packed { - p.enc = (*Buffer).enc_slice_packed_bool - p.size = size_slice_packed_bool - } else { - p.enc = (*Buffer).enc_slice_bool - p.size = size_slice_bool - } - p.dec = (*Buffer).dec_slice_bool - p.packedDec = (*Buffer).dec_slice_packed_bool - case reflect.Int32: - if p.Packed { - p.enc = (*Buffer).enc_slice_packed_int32 - p.size = size_slice_packed_int32 - } else { - p.enc = (*Buffer).enc_slice_int32 - p.size = size_slice_int32 - } - p.dec = (*Buffer).dec_slice_int32 - p.packedDec = (*Buffer).dec_slice_packed_int32 - case reflect.Uint32: - if p.Packed { - p.enc = (*Buffer).enc_slice_packed_uint32 - p.size = size_slice_packed_uint32 - } else { - p.enc = (*Buffer).enc_slice_uint32 - p.size = size_slice_uint32 - } - p.dec = (*Buffer).dec_slice_int32 - p.packedDec = (*Buffer).dec_slice_packed_int32 - case reflect.Int64, reflect.Uint64: - if p.Packed { - p.enc = (*Buffer).enc_slice_packed_int64 - p.size = size_slice_packed_int64 - } else { - p.enc = (*Buffer).enc_slice_int64 - p.size = size_slice_int64 - } - p.dec = (*Buffer).dec_slice_int64 - p.packedDec = (*Buffer).dec_slice_packed_int64 - case reflect.Uint8: - p.dec = (*Buffer).dec_slice_byte - if p.proto3 { - p.enc = (*Buffer).enc_proto3_slice_byte - p.size = size_proto3_slice_byte - } else { - p.enc = (*Buffer).enc_slice_byte - p.size = size_slice_byte - } - case reflect.Float32, reflect.Float64: - switch t2.Bits() { - case 32: - // can just treat them as bits - if p.Packed { - p.enc = (*Buffer).enc_slice_packed_uint32 - p.size = size_slice_packed_uint32 - } else { - p.enc = (*Buffer).enc_slice_uint32 - p.size = size_slice_uint32 - } - p.dec = (*Buffer).dec_slice_int32 - p.packedDec = (*Buffer).dec_slice_packed_int32 - case 64: - // can just treat them as bits - if p.Packed { - p.enc = (*Buffer).enc_slice_packed_int64 - p.size = size_slice_packed_int64 - } else { - p.enc = (*Buffer).enc_slice_int64 - p.size = size_slice_int64 - } - p.dec = (*Buffer).dec_slice_int64 - p.packedDec = (*Buffer).dec_slice_packed_int64 - default: - logNoSliceEnc(t1, t2) - break - } - case reflect.String: - p.enc = (*Buffer).enc_slice_string - p.dec = (*Buffer).dec_slice_string - p.size = size_slice_string - case reflect.Ptr: - switch t3 := t2.Elem(); t3.Kind() { - default: - fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T -> %T\n", t1, t2, t3) - break - case reflect.Struct: - p.stype = t2.Elem() - p.isMarshaler = isMarshaler(t2) - p.isUnmarshaler = isUnmarshaler(t2) - if p.Wire == "bytes" { - p.enc = (*Buffer).enc_slice_struct_message - p.dec = (*Buffer).dec_slice_struct_message - p.size = size_slice_struct_message - } else { - p.enc = (*Buffer).enc_slice_struct_group - p.dec = (*Buffer).dec_slice_struct_group - p.size = size_slice_struct_group - } - } - case reflect.Slice: - switch t2.Elem().Kind() { - default: - fmt.Fprintf(os.Stderr, "proto: no slice elem oenc for %T -> %T -> %T\n", t1, t2, t2.Elem()) - break - case reflect.Uint8: - p.enc = (*Buffer).enc_slice_slice_byte - p.dec = (*Buffer).dec_slice_slice_byte - p.size = size_slice_slice_byte - } - } - - case reflect.Map: - p.enc = (*Buffer).enc_new_map - p.dec = (*Buffer).dec_new_map - p.size = size_new_map - - p.mtype = t1 - p.mkeyprop = &Properties{} - p.mkeyprop.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp) - p.mvalprop = &Properties{} - vtype := p.mtype.Elem() - if vtype.Kind() != reflect.Ptr && vtype.Kind() != reflect.Slice { - // The value type is not a message (*T) or bytes ([]byte), - // so we need encoders for the pointer to this type. - vtype = reflect.PtrTo(vtype) - } - p.mvalprop.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp) - } - - // precalculate tag code - wire := p.WireType - if p.Packed { - wire = WireBytes - } - x := uint32(p.Tag)<<3 | uint32(wire) - i := 0 - for i = 0; x > 127; i++ { - p.tagbuf[i] = 0x80 | uint8(x&0x7F) - x >>= 7 - } - p.tagbuf[i] = uint8(x) - p.tagcode = p.tagbuf[0 : i+1] - - if p.stype != nil { - if lockGetProp { - p.sprop = GetProperties(p.stype) - } else { - p.sprop = getPropertiesLocked(p.stype) - } - } -} - -var ( - marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem() - unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem() -) - -// isMarshaler reports whether type t implements Marshaler. -func isMarshaler(t reflect.Type) bool { - // We're checking for (likely) pointer-receiver methods - // so if t is not a pointer, something is very wrong. - // The calls above only invoke isMarshaler on pointer types. - if t.Kind() != reflect.Ptr { - panic("proto: misuse of isMarshaler") - } - return t.Implements(marshalerType) -} - -// isUnmarshaler reports whether type t implements Unmarshaler. -func isUnmarshaler(t reflect.Type) bool { - // We're checking for (likely) pointer-receiver methods - // so if t is not a pointer, something is very wrong. - // The calls above only invoke isUnmarshaler on pointer types. - if t.Kind() != reflect.Ptr { - panic("proto: misuse of isUnmarshaler") - } - return t.Implements(unmarshalerType) -} - -// Init populates the properties from a protocol buffer struct tag. -func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) { - p.init(typ, name, tag, f, true) -} - -func (p *Properties) init(typ reflect.Type, name, tag string, f *reflect.StructField, lockGetProp bool) { - // "bytes,49,opt,def=hello!" - p.Name = name - p.OrigName = name - if f != nil { - p.field = toField(f) - } - if tag == "" { - return - } - p.Parse(tag) - p.setEncAndDec(typ, f, lockGetProp) -} - -var ( - propertiesMu sync.RWMutex - propertiesMap = make(map[reflect.Type]*StructProperties) -) - -// GetProperties returns the list of properties for the type represented by t. -// t must represent a generated struct type of a protocol message. -func GetProperties(t reflect.Type) *StructProperties { - if t.Kind() != reflect.Struct { - panic("proto: type must have kind struct") - } - - // Most calls to GetProperties in a long-running program will be - // retrieving details for types we have seen before. - propertiesMu.RLock() - sprop, ok := propertiesMap[t] - propertiesMu.RUnlock() - if ok { - if collectStats { - stats.Chit++ - } - return sprop - } - - propertiesMu.Lock() - sprop = getPropertiesLocked(t) - propertiesMu.Unlock() - return sprop -} - -// getPropertiesLocked requires that propertiesMu is held. -func getPropertiesLocked(t reflect.Type) *StructProperties { - if prop, ok := propertiesMap[t]; ok { - if collectStats { - stats.Chit++ - } - return prop - } - if collectStats { - stats.Cmiss++ - } - - prop := new(StructProperties) - // in case of recursive protos, fill this in now. - propertiesMap[t] = prop - - // build properties - prop.extendable = reflect.PtrTo(t).Implements(extendableProtoType) || - reflect.PtrTo(t).Implements(extendableProtoV1Type) - prop.unrecField = invalidField - prop.Prop = make([]*Properties, t.NumField()) - prop.order = make([]int, t.NumField()) - - for i := 0; i < t.NumField(); i++ { - f := t.Field(i) - p := new(Properties) - name := f.Name - p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false) - - if f.Name == "XXX_InternalExtensions" { // special case - p.enc = (*Buffer).enc_exts - p.dec = nil // not needed - p.size = size_exts - } else if f.Name == "XXX_extensions" { // special case - p.enc = (*Buffer).enc_map - p.dec = nil // not needed - p.size = size_map - } else if f.Name == "XXX_unrecognized" { // special case - prop.unrecField = toField(&f) - } - oneof := f.Tag.Get("protobuf_oneof") // special case - if oneof != "" { - // Oneof fields don't use the traditional protobuf tag. - p.OrigName = oneof - } - prop.Prop[i] = p - prop.order[i] = i - if debug { - print(i, " ", f.Name, " ", t.String(), " ") - if p.Tag > 0 { - print(p.String()) - } - print("\n") - } - if p.enc == nil && !strings.HasPrefix(f.Name, "XXX_") && oneof == "" { - fmt.Fprintln(os.Stderr, "proto: no encoder for", f.Name, f.Type.String(), "[GetProperties]") - } - } - - // Re-order prop.order. - sort.Sort(prop) - - type oneofMessage interface { - XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{}) - } - if om, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok { - var oots []interface{} - prop.oneofMarshaler, prop.oneofUnmarshaler, prop.oneofSizer, oots = om.XXX_OneofFuncs() - prop.stype = t - - // Interpret oneof metadata. - prop.OneofTypes = make(map[string]*OneofProperties) - for _, oot := range oots { - oop := &OneofProperties{ - Type: reflect.ValueOf(oot).Type(), // *T - Prop: new(Properties), - } - sft := oop.Type.Elem().Field(0) - oop.Prop.Name = sft.Name - oop.Prop.Parse(sft.Tag.Get("protobuf")) - // There will be exactly one interface field that - // this new value is assignable to. - for i := 0; i < t.NumField(); i++ { - f := t.Field(i) - if f.Type.Kind() != reflect.Interface { - continue - } - if !oop.Type.AssignableTo(f.Type) { - continue - } - oop.Field = i - break - } - prop.OneofTypes[oop.Prop.OrigName] = oop - } - } - - // build required counts - // build tags - reqCount := 0 - prop.decoderOrigNames = make(map[string]int) - for i, p := range prop.Prop { - if strings.HasPrefix(p.Name, "XXX_") { - // Internal fields should not appear in tags/origNames maps. - // They are handled specially when encoding and decoding. - continue - } - if p.Required { - reqCount++ - } - prop.decoderTags.put(p.Tag, i) - prop.decoderOrigNames[p.OrigName] = i - } - prop.reqCount = reqCount - - return prop -} - -// Return the Properties object for the x[0]'th field of the structure. -func propByIndex(t reflect.Type, x []int) *Properties { - if len(x) != 1 { - fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t) - return nil - } - prop := GetProperties(t) - return prop.Prop[x[0]] -} - -// Get the address and type of a pointer to a struct from an interface. -func getbase(pb Message) (t reflect.Type, b structPointer, err error) { - if pb == nil { - err = ErrNil - return - } - // get the reflect type of the pointer to the struct. - t = reflect.TypeOf(pb) - // get the address of the struct. - value := reflect.ValueOf(pb) - b = toStructPointer(value) - return -} - -// A global registry of enum types. -// The generated code will register the generated maps by calling RegisterEnum. - -var enumValueMaps = make(map[string]map[string]int32) - -// RegisterEnum is called from the generated code to install the enum descriptor -// maps into the global table to aid parsing text format protocol buffers. -func RegisterEnum(typeName string, unusedNameMap map[int32]string, valueMap map[string]int32) { - if _, ok := enumValueMaps[typeName]; ok { - panic("proto: duplicate enum registered: " + typeName) - } - enumValueMaps[typeName] = valueMap -} - -// EnumValueMap returns the mapping from names to integers of the -// enum type enumType, or a nil if not found. -func EnumValueMap(enumType string) map[string]int32 { - return enumValueMaps[enumType] -} - -// A registry of all linked message types. -// The string is a fully-qualified proto name ("pkg.Message"). -var ( - protoTypes = make(map[string]reflect.Type) - revProtoTypes = make(map[reflect.Type]string) -) - -// RegisterType is called from generated code and maps from the fully qualified -// proto name to the type (pointer to struct) of the protocol buffer. -func RegisterType(x Message, name string) { - if _, ok := protoTypes[name]; ok { - // TODO: Some day, make this a panic. - log.Printf("proto: duplicate proto type registered: %s", name) - return - } - t := reflect.TypeOf(x) - protoTypes[name] = t - revProtoTypes[t] = name -} - -// MessageName returns the fully-qualified proto name for the given message type. -func MessageName(x Message) string { - type xname interface { - XXX_MessageName() string - } - if m, ok := x.(xname); ok { - return m.XXX_MessageName() - } - return revProtoTypes[reflect.TypeOf(x)] -} - -// MessageType returns the message type (pointer to struct) for a named message. -func MessageType(name string) reflect.Type { return protoTypes[name] } - -// A registry of all linked proto files. -var ( - protoFiles = make(map[string][]byte) // file name => fileDescriptor -) - -// RegisterFile is called from generated code and maps from the -// full file name of a .proto file to its compressed FileDescriptorProto. -func RegisterFile(filename string, fileDescriptor []byte) { - protoFiles[filename] = fileDescriptor -} - -// FileDescriptor returns the compressed FileDescriptorProto for a .proto file. -func FileDescriptor(filename string) []byte { return protoFiles[filename] } diff --git a/vendor/github.com/golang/protobuf/proto/text.go b/vendor/github.com/golang/protobuf/proto/text.go deleted file mode 100644 index 965876bf033b64fac26deb2730244625d033fa41..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/text.go +++ /dev/null @@ -1,854 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -// Functions for writing the text protocol buffer format. - -import ( - "bufio" - "bytes" - "encoding" - "errors" - "fmt" - "io" - "log" - "math" - "reflect" - "sort" - "strings" -) - -var ( - newline = []byte("\n") - spaces = []byte(" ") - gtNewline = []byte(">\n") - endBraceNewline = []byte("}\n") - backslashN = []byte{'\\', 'n'} - backslashR = []byte{'\\', 'r'} - backslashT = []byte{'\\', 't'} - backslashDQ = []byte{'\\', '"'} - backslashBS = []byte{'\\', '\\'} - posInf = []byte("inf") - negInf = []byte("-inf") - nan = []byte("nan") -) - -type writer interface { - io.Writer - WriteByte(byte) error -} - -// textWriter is an io.Writer that tracks its indentation level. -type textWriter struct { - ind int - complete bool // if the current position is a complete line - compact bool // whether to write out as a one-liner - w writer -} - -func (w *textWriter) WriteString(s string) (n int, err error) { - if !strings.Contains(s, "\n") { - if !w.compact && w.complete { - w.writeIndent() - } - w.complete = false - return io.WriteString(w.w, s) - } - // WriteString is typically called without newlines, so this - // codepath and its copy are rare. We copy to avoid - // duplicating all of Write's logic here. - return w.Write([]byte(s)) -} - -func (w *textWriter) Write(p []byte) (n int, err error) { - newlines := bytes.Count(p, newline) - if newlines == 0 { - if !w.compact && w.complete { - w.writeIndent() - } - n, err = w.w.Write(p) - w.complete = false - return n, err - } - - frags := bytes.SplitN(p, newline, newlines+1) - if w.compact { - for i, frag := range frags { - if i > 0 { - if err := w.w.WriteByte(' '); err != nil { - return n, err - } - n++ - } - nn, err := w.w.Write(frag) - n += nn - if err != nil { - return n, err - } - } - return n, nil - } - - for i, frag := range frags { - if w.complete { - w.writeIndent() - } - nn, err := w.w.Write(frag) - n += nn - if err != nil { - return n, err - } - if i+1 < len(frags) { - if err := w.w.WriteByte('\n'); err != nil { - return n, err - } - n++ - } - } - w.complete = len(frags[len(frags)-1]) == 0 - return n, nil -} - -func (w *textWriter) WriteByte(c byte) error { - if w.compact && c == '\n' { - c = ' ' - } - if !w.compact && w.complete { - w.writeIndent() - } - err := w.w.WriteByte(c) - w.complete = c == '\n' - return err -} - -func (w *textWriter) indent() { w.ind++ } - -func (w *textWriter) unindent() { - if w.ind == 0 { - log.Print("proto: textWriter unindented too far") - return - } - w.ind-- -} - -func writeName(w *textWriter, props *Properties) error { - if _, err := w.WriteString(props.OrigName); err != nil { - return err - } - if props.Wire != "group" { - return w.WriteByte(':') - } - return nil -} - -// raw is the interface satisfied by RawMessage. -type raw interface { - Bytes() []byte -} - -func requiresQuotes(u string) bool { - // When type URL contains any characters except [0-9A-Za-z./\-]*, it must be quoted. - for _, ch := range u { - switch { - case ch == '.' || ch == '/' || ch == '_': - continue - case '0' <= ch && ch <= '9': - continue - case 'A' <= ch && ch <= 'Z': - continue - case 'a' <= ch && ch <= 'z': - continue - default: - return true - } - } - return false -} - -// isAny reports whether sv is a google.protobuf.Any message -func isAny(sv reflect.Value) bool { - type wkt interface { - XXX_WellKnownType() string - } - t, ok := sv.Addr().Interface().(wkt) - return ok && t.XXX_WellKnownType() == "Any" -} - -// writeProto3Any writes an expanded google.protobuf.Any message. -// -// It returns (false, nil) if sv value can't be unmarshaled (e.g. because -// required messages are not linked in). -// -// It returns (true, error) when sv was written in expanded format or an error -// was encountered. -func (tm *TextMarshaler) writeProto3Any(w *textWriter, sv reflect.Value) (bool, error) { - turl := sv.FieldByName("TypeUrl") - val := sv.FieldByName("Value") - if !turl.IsValid() || !val.IsValid() { - return true, errors.New("proto: invalid google.protobuf.Any message") - } - - b, ok := val.Interface().([]byte) - if !ok { - return true, errors.New("proto: invalid google.protobuf.Any message") - } - - parts := strings.Split(turl.String(), "/") - mt := MessageType(parts[len(parts)-1]) - if mt == nil { - return false, nil - } - m := reflect.New(mt.Elem()) - if err := Unmarshal(b, m.Interface().(Message)); err != nil { - return false, nil - } - w.Write([]byte("[")) - u := turl.String() - if requiresQuotes(u) { - writeString(w, u) - } else { - w.Write([]byte(u)) - } - if w.compact { - w.Write([]byte("]:<")) - } else { - w.Write([]byte("]: <\n")) - w.ind++ - } - if err := tm.writeStruct(w, m.Elem()); err != nil { - return true, err - } - if w.compact { - w.Write([]byte("> ")) - } else { - w.ind-- - w.Write([]byte(">\n")) - } - return true, nil -} - -func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error { - if tm.ExpandAny && isAny(sv) { - if canExpand, err := tm.writeProto3Any(w, sv); canExpand { - return err - } - } - st := sv.Type() - sprops := GetProperties(st) - for i := 0; i < sv.NumField(); i++ { - fv := sv.Field(i) - props := sprops.Prop[i] - name := st.Field(i).Name - - if strings.HasPrefix(name, "XXX_") { - // There are two XXX_ fields: - // XXX_unrecognized []byte - // XXX_extensions map[int32]proto.Extension - // The first is handled here; - // the second is handled at the bottom of this function. - if name == "XXX_unrecognized" && !fv.IsNil() { - if err := writeUnknownStruct(w, fv.Interface().([]byte)); err != nil { - return err - } - } - continue - } - if fv.Kind() == reflect.Ptr && fv.IsNil() { - // Field not filled in. This could be an optional field or - // a required field that wasn't filled in. Either way, there - // isn't anything we can show for it. - continue - } - if fv.Kind() == reflect.Slice && fv.IsNil() { - // Repeated field that is empty, or a bytes field that is unused. - continue - } - - if props.Repeated && fv.Kind() == reflect.Slice { - // Repeated field. - for j := 0; j < fv.Len(); j++ { - if err := writeName(w, props); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte(' '); err != nil { - return err - } - } - v := fv.Index(j) - if v.Kind() == reflect.Ptr && v.IsNil() { - // A nil message in a repeated field is not valid, - // but we can handle that more gracefully than panicking. - if _, err := w.Write([]byte("<nil>\n")); err != nil { - return err - } - continue - } - if err := tm.writeAny(w, v, props); err != nil { - return err - } - if err := w.WriteByte('\n'); err != nil { - return err - } - } - continue - } - if fv.Kind() == reflect.Map { - // Map fields are rendered as a repeated struct with key/value fields. - keys := fv.MapKeys() - sort.Sort(mapKeys(keys)) - for _, key := range keys { - val := fv.MapIndex(key) - if err := writeName(w, props); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte(' '); err != nil { - return err - } - } - // open struct - if err := w.WriteByte('<'); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte('\n'); err != nil { - return err - } - } - w.indent() - // key - if _, err := w.WriteString("key:"); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte(' '); err != nil { - return err - } - } - if err := tm.writeAny(w, key, props.mkeyprop); err != nil { - return err - } - if err := w.WriteByte('\n'); err != nil { - return err - } - // nil values aren't legal, but we can avoid panicking because of them. - if val.Kind() != reflect.Ptr || !val.IsNil() { - // value - if _, err := w.WriteString("value:"); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte(' '); err != nil { - return err - } - } - if err := tm.writeAny(w, val, props.mvalprop); err != nil { - return err - } - if err := w.WriteByte('\n'); err != nil { - return err - } - } - // close struct - w.unindent() - if err := w.WriteByte('>'); err != nil { - return err - } - if err := w.WriteByte('\n'); err != nil { - return err - } - } - continue - } - if props.proto3 && fv.Kind() == reflect.Slice && fv.Len() == 0 { - // empty bytes field - continue - } - if fv.Kind() != reflect.Ptr && fv.Kind() != reflect.Slice { - // proto3 non-repeated scalar field; skip if zero value - if isProto3Zero(fv) { - continue - } - } - - if fv.Kind() == reflect.Interface { - // Check if it is a oneof. - if st.Field(i).Tag.Get("protobuf_oneof") != "" { - // fv is nil, or holds a pointer to generated struct. - // That generated struct has exactly one field, - // which has a protobuf struct tag. - if fv.IsNil() { - continue - } - inner := fv.Elem().Elem() // interface -> *T -> T - tag := inner.Type().Field(0).Tag.Get("protobuf") - props = new(Properties) // Overwrite the outer props var, but not its pointee. - props.Parse(tag) - // Write the value in the oneof, not the oneof itself. - fv = inner.Field(0) - - // Special case to cope with malformed messages gracefully: - // If the value in the oneof is a nil pointer, don't panic - // in writeAny. - if fv.Kind() == reflect.Ptr && fv.IsNil() { - // Use errors.New so writeAny won't render quotes. - msg := errors.New("/* nil */") - fv = reflect.ValueOf(&msg).Elem() - } - } - } - - if err := writeName(w, props); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte(' '); err != nil { - return err - } - } - if b, ok := fv.Interface().(raw); ok { - if err := writeRaw(w, b.Bytes()); err != nil { - return err - } - continue - } - - // Enums have a String method, so writeAny will work fine. - if err := tm.writeAny(w, fv, props); err != nil { - return err - } - - if err := w.WriteByte('\n'); err != nil { - return err - } - } - - // Extensions (the XXX_extensions field). - pv := sv.Addr() - if _, ok := extendable(pv.Interface()); ok { - if err := tm.writeExtensions(w, pv); err != nil { - return err - } - } - - return nil -} - -// writeRaw writes an uninterpreted raw message. -func writeRaw(w *textWriter, b []byte) error { - if err := w.WriteByte('<'); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte('\n'); err != nil { - return err - } - } - w.indent() - if err := writeUnknownStruct(w, b); err != nil { - return err - } - w.unindent() - if err := w.WriteByte('>'); err != nil { - return err - } - return nil -} - -// writeAny writes an arbitrary field. -func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error { - v = reflect.Indirect(v) - - // Floats have special cases. - if v.Kind() == reflect.Float32 || v.Kind() == reflect.Float64 { - x := v.Float() - var b []byte - switch { - case math.IsInf(x, 1): - b = posInf - case math.IsInf(x, -1): - b = negInf - case math.IsNaN(x): - b = nan - } - if b != nil { - _, err := w.Write(b) - return err - } - // Other values are handled below. - } - - // We don't attempt to serialise every possible value type; only those - // that can occur in protocol buffers. - switch v.Kind() { - case reflect.Slice: - // Should only be a []byte; repeated fields are handled in writeStruct. - if err := writeString(w, string(v.Bytes())); err != nil { - return err - } - case reflect.String: - if err := writeString(w, v.String()); err != nil { - return err - } - case reflect.Struct: - // Required/optional group/message. - var bra, ket byte = '<', '>' - if props != nil && props.Wire == "group" { - bra, ket = '{', '}' - } - if err := w.WriteByte(bra); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte('\n'); err != nil { - return err - } - } - w.indent() - if etm, ok := v.Interface().(encoding.TextMarshaler); ok { - text, err := etm.MarshalText() - if err != nil { - return err - } - if _, err = w.Write(text); err != nil { - return err - } - } else if err := tm.writeStruct(w, v); err != nil { - return err - } - w.unindent() - if err := w.WriteByte(ket); err != nil { - return err - } - default: - _, err := fmt.Fprint(w, v.Interface()) - return err - } - return nil -} - -// equivalent to C's isprint. -func isprint(c byte) bool { - return c >= 0x20 && c < 0x7f -} - -// writeString writes a string in the protocol buffer text format. -// It is similar to strconv.Quote except we don't use Go escape sequences, -// we treat the string as a byte sequence, and we use octal escapes. -// These differences are to maintain interoperability with the other -// languages' implementations of the text format. -func writeString(w *textWriter, s string) error { - // use WriteByte here to get any needed indent - if err := w.WriteByte('"'); err != nil { - return err - } - // Loop over the bytes, not the runes. - for i := 0; i < len(s); i++ { - var err error - // Divergence from C++: we don't escape apostrophes. - // There's no need to escape them, and the C++ parser - // copes with a naked apostrophe. - switch c := s[i]; c { - case '\n': - _, err = w.w.Write(backslashN) - case '\r': - _, err = w.w.Write(backslashR) - case '\t': - _, err = w.w.Write(backslashT) - case '"': - _, err = w.w.Write(backslashDQ) - case '\\': - _, err = w.w.Write(backslashBS) - default: - if isprint(c) { - err = w.w.WriteByte(c) - } else { - _, err = fmt.Fprintf(w.w, "\\%03o", c) - } - } - if err != nil { - return err - } - } - return w.WriteByte('"') -} - -func writeUnknownStruct(w *textWriter, data []byte) (err error) { - if !w.compact { - if _, err := fmt.Fprintf(w, "/* %d unknown bytes */\n", len(data)); err != nil { - return err - } - } - b := NewBuffer(data) - for b.index < len(b.buf) { - x, err := b.DecodeVarint() - if err != nil { - _, err := fmt.Fprintf(w, "/* %v */\n", err) - return err - } - wire, tag := x&7, x>>3 - if wire == WireEndGroup { - w.unindent() - if _, err := w.Write(endBraceNewline); err != nil { - return err - } - continue - } - if _, err := fmt.Fprint(w, tag); err != nil { - return err - } - if wire != WireStartGroup { - if err := w.WriteByte(':'); err != nil { - return err - } - } - if !w.compact || wire == WireStartGroup { - if err := w.WriteByte(' '); err != nil { - return err - } - } - switch wire { - case WireBytes: - buf, e := b.DecodeRawBytes(false) - if e == nil { - _, err = fmt.Fprintf(w, "%q", buf) - } else { - _, err = fmt.Fprintf(w, "/* %v */", e) - } - case WireFixed32: - x, err = b.DecodeFixed32() - err = writeUnknownInt(w, x, err) - case WireFixed64: - x, err = b.DecodeFixed64() - err = writeUnknownInt(w, x, err) - case WireStartGroup: - err = w.WriteByte('{') - w.indent() - case WireVarint: - x, err = b.DecodeVarint() - err = writeUnknownInt(w, x, err) - default: - _, err = fmt.Fprintf(w, "/* unknown wire type %d */", wire) - } - if err != nil { - return err - } - if err = w.WriteByte('\n'); err != nil { - return err - } - } - return nil -} - -func writeUnknownInt(w *textWriter, x uint64, err error) error { - if err == nil { - _, err = fmt.Fprint(w, x) - } else { - _, err = fmt.Fprintf(w, "/* %v */", err) - } - return err -} - -type int32Slice []int32 - -func (s int32Slice) Len() int { return len(s) } -func (s int32Slice) Less(i, j int) bool { return s[i] < s[j] } -func (s int32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - -// writeExtensions writes all the extensions in pv. -// pv is assumed to be a pointer to a protocol message struct that is extendable. -func (tm *TextMarshaler) writeExtensions(w *textWriter, pv reflect.Value) error { - emap := extensionMaps[pv.Type().Elem()] - ep, _ := extendable(pv.Interface()) - - // Order the extensions by ID. - // This isn't strictly necessary, but it will give us - // canonical output, which will also make testing easier. - m, mu := ep.extensionsRead() - if m == nil { - return nil - } - mu.Lock() - ids := make([]int32, 0, len(m)) - for id := range m { - ids = append(ids, id) - } - sort.Sort(int32Slice(ids)) - mu.Unlock() - - for _, extNum := range ids { - ext := m[extNum] - var desc *ExtensionDesc - if emap != nil { - desc = emap[extNum] - } - if desc == nil { - // Unknown extension. - if err := writeUnknownStruct(w, ext.enc); err != nil { - return err - } - continue - } - - pb, err := GetExtension(ep, desc) - if err != nil { - return fmt.Errorf("failed getting extension: %v", err) - } - - // Repeated extensions will appear as a slice. - if !desc.repeated() { - if err := tm.writeExtension(w, desc.Name, pb); err != nil { - return err - } - } else { - v := reflect.ValueOf(pb) - for i := 0; i < v.Len(); i++ { - if err := tm.writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil { - return err - } - } - } - } - return nil -} - -func (tm *TextMarshaler) writeExtension(w *textWriter, name string, pb interface{}) error { - if _, err := fmt.Fprintf(w, "[%s]:", name); err != nil { - return err - } - if !w.compact { - if err := w.WriteByte(' '); err != nil { - return err - } - } - if err := tm.writeAny(w, reflect.ValueOf(pb), nil); err != nil { - return err - } - if err := w.WriteByte('\n'); err != nil { - return err - } - return nil -} - -func (w *textWriter) writeIndent() { - if !w.complete { - return - } - remain := w.ind * 2 - for remain > 0 { - n := remain - if n > len(spaces) { - n = len(spaces) - } - w.w.Write(spaces[:n]) - remain -= n - } - w.complete = false -} - -// TextMarshaler is a configurable text format marshaler. -type TextMarshaler struct { - Compact bool // use compact text format (one line). - ExpandAny bool // expand google.protobuf.Any messages of known types -} - -// Marshal writes a given protocol buffer in text format. -// The only errors returned are from w. -func (tm *TextMarshaler) Marshal(w io.Writer, pb Message) error { - val := reflect.ValueOf(pb) - if pb == nil || val.IsNil() { - w.Write([]byte("<nil>")) - return nil - } - var bw *bufio.Writer - ww, ok := w.(writer) - if !ok { - bw = bufio.NewWriter(w) - ww = bw - } - aw := &textWriter{ - w: ww, - complete: true, - compact: tm.Compact, - } - - if etm, ok := pb.(encoding.TextMarshaler); ok { - text, err := etm.MarshalText() - if err != nil { - return err - } - if _, err = aw.Write(text); err != nil { - return err - } - if bw != nil { - return bw.Flush() - } - return nil - } - // Dereference the received pointer so we don't have outer < and >. - v := reflect.Indirect(val) - if err := tm.writeStruct(aw, v); err != nil { - return err - } - if bw != nil { - return bw.Flush() - } - return nil -} - -// Text is the same as Marshal, but returns the string directly. -func (tm *TextMarshaler) Text(pb Message) string { - var buf bytes.Buffer - tm.Marshal(&buf, pb) - return buf.String() -} - -var ( - defaultTextMarshaler = TextMarshaler{} - compactTextMarshaler = TextMarshaler{Compact: true} -) - -// TODO: consider removing some of the Marshal functions below. - -// MarshalText writes a given protocol buffer in text format. -// The only errors returned are from w. -func MarshalText(w io.Writer, pb Message) error { return defaultTextMarshaler.Marshal(w, pb) } - -// MarshalTextString is the same as MarshalText, but returns the string directly. -func MarshalTextString(pb Message) string { return defaultTextMarshaler.Text(pb) } - -// CompactText writes a given protocol buffer in compact text format (one line). -func CompactText(w io.Writer, pb Message) error { return compactTextMarshaler.Marshal(w, pb) } - -// CompactTextString is the same as CompactText, but returns the string directly. -func CompactTextString(pb Message) string { return compactTextMarshaler.Text(pb) } diff --git a/vendor/github.com/golang/protobuf/proto/text_parser.go b/vendor/github.com/golang/protobuf/proto/text_parser.go deleted file mode 100644 index 5e14513f28c9041020ee559c9ec437361720024f..0000000000000000000000000000000000000000 --- a/vendor/github.com/golang/protobuf/proto/text_parser.go +++ /dev/null @@ -1,895 +0,0 @@ -// Go support for Protocol Buffers - Google's data interchange format -// -// Copyright 2010 The Go Authors. All rights reserved. -// https://github.com/golang/protobuf -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package proto - -// Functions for parsing the Text protocol buffer format. -// TODO: message sets. - -import ( - "encoding" - "errors" - "fmt" - "reflect" - "strconv" - "strings" - "unicode/utf8" -) - -// Error string emitted when deserializing Any and fields are already set -const anyRepeatedlyUnpacked = "Any message unpacked multiple times, or %q already set" - -type ParseError struct { - Message string - Line int // 1-based line number - Offset int // 0-based byte offset from start of input -} - -func (p *ParseError) Error() string { - if p.Line == 1 { - // show offset only for first line - return fmt.Sprintf("line 1.%d: %v", p.Offset, p.Message) - } - return fmt.Sprintf("line %d: %v", p.Line, p.Message) -} - -type token struct { - value string - err *ParseError - line int // line number - offset int // byte number from start of input, not start of line - unquoted string // the unquoted version of value, if it was a quoted string -} - -func (t *token) String() string { - if t.err == nil { - return fmt.Sprintf("%q (line=%d, offset=%d)", t.value, t.line, t.offset) - } - return fmt.Sprintf("parse error: %v", t.err) -} - -type textParser struct { - s string // remaining input - done bool // whether the parsing is finished (success or error) - backed bool // whether back() was called - offset, line int - cur token -} - -func newTextParser(s string) *textParser { - p := new(textParser) - p.s = s - p.line = 1 - p.cur.line = 1 - return p -} - -func (p *textParser) errorf(format string, a ...interface{}) *ParseError { - pe := &ParseError{fmt.Sprintf(format, a...), p.cur.line, p.cur.offset} - p.cur.err = pe - p.done = true - return pe -} - -// Numbers and identifiers are matched by [-+._A-Za-z0-9] -func isIdentOrNumberChar(c byte) bool { - switch { - case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z': - return true - case '0' <= c && c <= '9': - return true - } - switch c { - case '-', '+', '.', '_': - return true - } - return false -} - -func isWhitespace(c byte) bool { - switch c { - case ' ', '\t', '\n', '\r': - return true - } - return false -} - -func isQuote(c byte) bool { - switch c { - case '"', '\'': - return true - } - return false -} - -func (p *textParser) skipWhitespace() { - i := 0 - for i < len(p.s) && (isWhitespace(p.s[i]) || p.s[i] == '#') { - if p.s[i] == '#' { - // comment; skip to end of line or input - for i < len(p.s) && p.s[i] != '\n' { - i++ - } - if i == len(p.s) { - break - } - } - if p.s[i] == '\n' { - p.line++ - } - i++ - } - p.offset += i - p.s = p.s[i:len(p.s)] - if len(p.s) == 0 { - p.done = true - } -} - -func (p *textParser) advance() { - // Skip whitespace - p.skipWhitespace() - if p.done { - return - } - - // Start of non-whitespace - p.cur.err = nil - p.cur.offset, p.cur.line = p.offset, p.line - p.cur.unquoted = "" - switch p.s[0] { - case '<', '>', '{', '}', ':', '[', ']', ';', ',', '/': - // Single symbol - p.cur.value, p.s = p.s[0:1], p.s[1:len(p.s)] - case '"', '\'': - // Quoted string - i := 1 - for i < len(p.s) && p.s[i] != p.s[0] && p.s[i] != '\n' { - if p.s[i] == '\\' && i+1 < len(p.s) { - // skip escaped char - i++ - } - i++ - } - if i >= len(p.s) || p.s[i] != p.s[0] { - p.errorf("unmatched quote") - return - } - unq, err := unquoteC(p.s[1:i], rune(p.s[0])) - if err != nil { - p.errorf("invalid quoted string %s: %v", p.s[0:i+1], err) - return - } - p.cur.value, p.s = p.s[0:i+1], p.s[i+1:len(p.s)] - p.cur.unquoted = unq - default: - i := 0 - for i < len(p.s) && isIdentOrNumberChar(p.s[i]) { - i++ - } - if i == 0 { - p.errorf("unexpected byte %#x", p.s[0]) - return - } - p.cur.value, p.s = p.s[0:i], p.s[i:len(p.s)] - } - p.offset += len(p.cur.value) -} - -var ( - errBadUTF8 = errors.New("proto: bad UTF-8") - errBadHex = errors.New("proto: bad hexadecimal") -) - -func unquoteC(s string, quote rune) (string, error) { - // This is based on C++'s tokenizer.cc. - // Despite its name, this is *not* parsing C syntax. - // For instance, "\0" is an invalid quoted string. - - // Avoid allocation in trivial cases. - simple := true - for _, r := range s { - if r == '\\' || r == quote { - simple = false - break - } - } - if simple { - return s, nil - } - - buf := make([]byte, 0, 3*len(s)/2) - for len(s) > 0 { - r, n := utf8.DecodeRuneInString(s) - if r == utf8.RuneError && n == 1 { - return "", errBadUTF8 - } - s = s[n:] - if r != '\\' { - if r < utf8.RuneSelf { - buf = append(buf, byte(r)) - } else { - buf = append(buf, string(r)...) - } - continue - } - - ch, tail, err := unescape(s) - if err != nil { - return "", err - } - buf = append(buf, ch...) - s = tail - } - return string(buf), nil -} - -func unescape(s string) (ch string, tail string, err error) { - r, n := utf8.DecodeRuneInString(s) - if r == utf8.RuneError && n == 1 { - return "", "", errBadUTF8 - } - s = s[n:] - switch r { - case 'a': - return "\a", s, nil - case 'b': - return "\b", s, nil - case 'f': - return "\f", s, nil - case 'n': - return "\n", s, nil - case 'r': - return "\r", s, nil - case 't': - return "\t", s, nil - case 'v': - return "\v", s, nil - case '?': - return "?", s, nil // trigraph workaround - case '\'', '"', '\\': - return string(r), s, nil - case '0', '1', '2', '3', '4', '5', '6', '7', 'x', 'X': - if len(s) < 2 { - return "", "", fmt.Errorf(`\%c requires 2 following digits`, r) - } - base := 8 - ss := s[:2] - s = s[2:] - if r == 'x' || r == 'X' { - base = 16 - } else { - ss = string(r) + ss - } - i, err := strconv.ParseUint(ss, base, 8) - if err != nil { - return "", "", err - } - return string([]byte{byte(i)}), s, nil - case 'u', 'U': - n := 4 - if r == 'U' { - n = 8 - } - if len(s) < n { - return "", "", fmt.Errorf(`\%c requires %d digits`, r, n) - } - - bs := make([]byte, n/2) - for i := 0; i < n; i += 2 { - a, ok1 := unhex(s[i]) - b, ok2 := unhex(s[i+1]) - if !ok1 || !ok2 { - return "", "", errBadHex - } - bs[i/2] = a<<4 | b - } - s = s[n:] - return string(bs), s, nil - } - return "", "", fmt.Errorf(`unknown escape \%c`, r) -} - -// Adapted from src/pkg/strconv/quote.go. -func unhex(b byte) (v byte, ok bool) { - switch { - case '0' <= b && b <= '9': - return b - '0', true - case 'a' <= b && b <= 'f': - return b - 'a' + 10, true - case 'A' <= b && b <= 'F': - return b - 'A' + 10, true - } - return 0, false -} - -// Back off the parser by one token. Can only be done between calls to next(). -// It makes the next advance() a no-op. -func (p *textParser) back() { p.backed = true } - -// Advances the parser and returns the new current token. -func (p *textParser) next() *token { - if p.backed || p.done { - p.backed = false - return &p.cur - } - p.advance() - if p.done { - p.cur.value = "" - } else if len(p.cur.value) > 0 && isQuote(p.cur.value[0]) { - // Look for multiple quoted strings separated by whitespace, - // and concatenate them. - cat := p.cur - for { - p.skipWhitespace() - if p.done || !isQuote(p.s[0]) { - break - } - p.advance() - if p.cur.err != nil { - return &p.cur - } - cat.value += " " + p.cur.value - cat.unquoted += p.cur.unquoted - } - p.done = false // parser may have seen EOF, but we want to return cat - p.cur = cat - } - return &p.cur -} - -func (p *textParser) consumeToken(s string) error { - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value != s { - p.back() - return p.errorf("expected %q, found %q", s, tok.value) - } - return nil -} - -// Return a RequiredNotSetError indicating which required field was not set. -func (p *textParser) missingRequiredFieldError(sv reflect.Value) *RequiredNotSetError { - st := sv.Type() - sprops := GetProperties(st) - for i := 0; i < st.NumField(); i++ { - if !isNil(sv.Field(i)) { - continue - } - - props := sprops.Prop[i] - if props.Required { - return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, props.OrigName)} - } - } - return &RequiredNotSetError{fmt.Sprintf("%v.<unknown field name>", st)} // should not happen -} - -// Returns the index in the struct for the named field, as well as the parsed tag properties. -func structFieldByName(sprops *StructProperties, name string) (int, *Properties, bool) { - i, ok := sprops.decoderOrigNames[name] - if ok { - return i, sprops.Prop[i], true - } - return -1, nil, false -} - -// Consume a ':' from the input stream (if the next token is a colon), -// returning an error if a colon is needed but not present. -func (p *textParser) checkForColon(props *Properties, typ reflect.Type) *ParseError { - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value != ":" { - // Colon is optional when the field is a group or message. - needColon := true - switch props.Wire { - case "group": - needColon = false - case "bytes": - // A "bytes" field is either a message, a string, or a repeated field; - // those three become *T, *string and []T respectively, so we can check for - // this field being a pointer to a non-string. - if typ.Kind() == reflect.Ptr { - // *T or *string - if typ.Elem().Kind() == reflect.String { - break - } - } else if typ.Kind() == reflect.Slice { - // []T or []*T - if typ.Elem().Kind() != reflect.Ptr { - break - } - } else if typ.Kind() == reflect.String { - // The proto3 exception is for a string field, - // which requires a colon. - break - } - needColon = false - } - if needColon { - return p.errorf("expected ':', found %q", tok.value) - } - p.back() - } - return nil -} - -func (p *textParser) readStruct(sv reflect.Value, terminator string) error { - st := sv.Type() - sprops := GetProperties(st) - reqCount := sprops.reqCount - var reqFieldErr error - fieldSet := make(map[string]bool) - // A struct is a sequence of "name: value", terminated by one of - // '>' or '}', or the end of the input. A name may also be - // "[extension]" or "[type/url]". - // - // The whole struct can also be an expanded Any message, like: - // [type/url] < ... struct contents ... > - for { - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value == terminator { - break - } - if tok.value == "[" { - // Looks like an extension or an Any. - // - // TODO: Check whether we need to handle - // namespace rooted names (e.g. ".something.Foo"). - extName, err := p.consumeExtName() - if err != nil { - return err - } - - if s := strings.LastIndex(extName, "/"); s >= 0 { - // If it contains a slash, it's an Any type URL. - messageName := extName[s+1:] - mt := MessageType(messageName) - if mt == nil { - return p.errorf("unrecognized message %q in google.protobuf.Any", messageName) - } - tok = p.next() - if tok.err != nil { - return tok.err - } - // consume an optional colon - if tok.value == ":" { - tok = p.next() - if tok.err != nil { - return tok.err - } - } - var terminator string - switch tok.value { - case "<": - terminator = ">" - case "{": - terminator = "}" - default: - return p.errorf("expected '{' or '<', found %q", tok.value) - } - v := reflect.New(mt.Elem()) - if pe := p.readStruct(v.Elem(), terminator); pe != nil { - return pe - } - b, err := Marshal(v.Interface().(Message)) - if err != nil { - return p.errorf("failed to marshal message of type %q: %v", messageName, err) - } - if fieldSet["type_url"] { - return p.errorf(anyRepeatedlyUnpacked, "type_url") - } - if fieldSet["value"] { - return p.errorf(anyRepeatedlyUnpacked, "value") - } - sv.FieldByName("TypeUrl").SetString(extName) - sv.FieldByName("Value").SetBytes(b) - fieldSet["type_url"] = true - fieldSet["value"] = true - continue - } - - var desc *ExtensionDesc - // This could be faster, but it's functional. - // TODO: Do something smarter than a linear scan. - for _, d := range RegisteredExtensions(reflect.New(st).Interface().(Message)) { - if d.Name == extName { - desc = d - break - } - } - if desc == nil { - return p.errorf("unrecognized extension %q", extName) - } - - props := &Properties{} - props.Parse(desc.Tag) - - typ := reflect.TypeOf(desc.ExtensionType) - if err := p.checkForColon(props, typ); err != nil { - return err - } - - rep := desc.repeated() - - // Read the extension structure, and set it in - // the value we're constructing. - var ext reflect.Value - if !rep { - ext = reflect.New(typ).Elem() - } else { - ext = reflect.New(typ.Elem()).Elem() - } - if err := p.readAny(ext, props); err != nil { - if _, ok := err.(*RequiredNotSetError); !ok { - return err - } - reqFieldErr = err - } - ep := sv.Addr().Interface().(Message) - if !rep { - SetExtension(ep, desc, ext.Interface()) - } else { - old, err := GetExtension(ep, desc) - var sl reflect.Value - if err == nil { - sl = reflect.ValueOf(old) // existing slice - } else { - sl = reflect.MakeSlice(typ, 0, 1) - } - sl = reflect.Append(sl, ext) - SetExtension(ep, desc, sl.Interface()) - } - if err := p.consumeOptionalSeparator(); err != nil { - return err - } - continue - } - - // This is a normal, non-extension field. - name := tok.value - var dst reflect.Value - fi, props, ok := structFieldByName(sprops, name) - if ok { - dst = sv.Field(fi) - } else if oop, ok := sprops.OneofTypes[name]; ok { - // It is a oneof. - props = oop.Prop - nv := reflect.New(oop.Type.Elem()) - dst = nv.Elem().Field(0) - field := sv.Field(oop.Field) - if !field.IsNil() { - return p.errorf("field '%s' would overwrite already parsed oneof '%s'", name, sv.Type().Field(oop.Field).Name) - } - field.Set(nv) - } - if !dst.IsValid() { - return p.errorf("unknown field name %q in %v", name, st) - } - - if dst.Kind() == reflect.Map { - // Consume any colon. - if err := p.checkForColon(props, dst.Type()); err != nil { - return err - } - - // Construct the map if it doesn't already exist. - if dst.IsNil() { - dst.Set(reflect.MakeMap(dst.Type())) - } - key := reflect.New(dst.Type().Key()).Elem() - val := reflect.New(dst.Type().Elem()).Elem() - - // The map entry should be this sequence of tokens: - // < key : KEY value : VALUE > - // However, implementations may omit key or value, and technically - // we should support them in any order. See b/28924776 for a time - // this went wrong. - - tok := p.next() - var terminator string - switch tok.value { - case "<": - terminator = ">" - case "{": - terminator = "}" - default: - return p.errorf("expected '{' or '<', found %q", tok.value) - } - for { - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value == terminator { - break - } - switch tok.value { - case "key": - if err := p.consumeToken(":"); err != nil { - return err - } - if err := p.readAny(key, props.mkeyprop); err != nil { - return err - } - if err := p.consumeOptionalSeparator(); err != nil { - return err - } - case "value": - if err := p.checkForColon(props.mvalprop, dst.Type().Elem()); err != nil { - return err - } - if err := p.readAny(val, props.mvalprop); err != nil { - return err - } - if err := p.consumeOptionalSeparator(); err != nil { - return err - } - default: - p.back() - return p.errorf(`expected "key", "value", or %q, found %q`, terminator, tok.value) - } - } - - dst.SetMapIndex(key, val) - continue - } - - // Check that it's not already set if it's not a repeated field. - if !props.Repeated && fieldSet[name] { - return p.errorf("non-repeated field %q was repeated", name) - } - - if err := p.checkForColon(props, dst.Type()); err != nil { - return err - } - - // Parse into the field. - fieldSet[name] = true - if err := p.readAny(dst, props); err != nil { - if _, ok := err.(*RequiredNotSetError); !ok { - return err - } - reqFieldErr = err - } - if props.Required { - reqCount-- - } - - if err := p.consumeOptionalSeparator(); err != nil { - return err - } - - } - - if reqCount > 0 { - return p.missingRequiredFieldError(sv) - } - return reqFieldErr -} - -// consumeExtName consumes extension name or expanded Any type URL and the -// following ']'. It returns the name or URL consumed. -func (p *textParser) consumeExtName() (string, error) { - tok := p.next() - if tok.err != nil { - return "", tok.err - } - - // If extension name or type url is quoted, it's a single token. - if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] { - name, err := unquoteC(tok.value[1:len(tok.value)-1], rune(tok.value[0])) - if err != nil { - return "", err - } - return name, p.consumeToken("]") - } - - // Consume everything up to "]" - var parts []string - for tok.value != "]" { - parts = append(parts, tok.value) - tok = p.next() - if tok.err != nil { - return "", p.errorf("unrecognized type_url or extension name: %s", tok.err) - } - } - return strings.Join(parts, ""), nil -} - -// consumeOptionalSeparator consumes an optional semicolon or comma. -// It is used in readStruct to provide backward compatibility. -func (p *textParser) consumeOptionalSeparator() error { - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value != ";" && tok.value != "," { - p.back() - } - return nil -} - -func (p *textParser) readAny(v reflect.Value, props *Properties) error { - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value == "" { - return p.errorf("unexpected EOF") - } - - switch fv := v; fv.Kind() { - case reflect.Slice: - at := v.Type() - if at.Elem().Kind() == reflect.Uint8 { - // Special case for []byte - if tok.value[0] != '"' && tok.value[0] != '\'' { - // Deliberately written out here, as the error after - // this switch statement would write "invalid []byte: ...", - // which is not as user-friendly. - return p.errorf("invalid string: %v", tok.value) - } - bytes := []byte(tok.unquoted) - fv.Set(reflect.ValueOf(bytes)) - return nil - } - // Repeated field. - if tok.value == "[" { - // Repeated field with list notation, like [1,2,3]. - for { - fv.Set(reflect.Append(fv, reflect.New(at.Elem()).Elem())) - err := p.readAny(fv.Index(fv.Len()-1), props) - if err != nil { - return err - } - tok := p.next() - if tok.err != nil { - return tok.err - } - if tok.value == "]" { - break - } - if tok.value != "," { - return p.errorf("Expected ']' or ',' found %q", tok.value) - } - } - return nil - } - // One value of the repeated field. - p.back() - fv.Set(reflect.Append(fv, reflect.New(at.Elem()).Elem())) - return p.readAny(fv.Index(fv.Len()-1), props) - case reflect.Bool: - // true/1/t/True or false/f/0/False. - switch tok.value { - case "true", "1", "t", "True": - fv.SetBool(true) - return nil - case "false", "0", "f", "False": - fv.SetBool(false) - return nil - } - case reflect.Float32, reflect.Float64: - v := tok.value - // Ignore 'f' for compatibility with output generated by C++, but don't - // remove 'f' when the value is "-inf" or "inf". - if strings.HasSuffix(v, "f") && tok.value != "-inf" && tok.value != "inf" { - v = v[:len(v)-1] - } - if f, err := strconv.ParseFloat(v, fv.Type().Bits()); err == nil { - fv.SetFloat(f) - return nil - } - case reflect.Int32: - if x, err := strconv.ParseInt(tok.value, 0, 32); err == nil { - fv.SetInt(x) - return nil - } - - if len(props.Enum) == 0 { - break - } - m, ok := enumValueMaps[props.Enum] - if !ok { - break - } - x, ok := m[tok.value] - if !ok { - break - } - fv.SetInt(int64(x)) - return nil - case reflect.Int64: - if x, err := strconv.ParseInt(tok.value, 0, 64); err == nil { - fv.SetInt(x) - return nil - } - - case reflect.Ptr: - // A basic field (indirected through pointer), or a repeated message/group - p.back() - fv.Set(reflect.New(fv.Type().Elem())) - return p.readAny(fv.Elem(), props) - case reflect.String: - if tok.value[0] == '"' || tok.value[0] == '\'' { - fv.SetString(tok.unquoted) - return nil - } - case reflect.Struct: - var terminator string - switch tok.value { - case "{": - terminator = "}" - case "<": - terminator = ">" - default: - return p.errorf("expected '{' or '<', found %q", tok.value) - } - // TODO: Handle nested messages which implement encoding.TextUnmarshaler. - return p.readStruct(fv, terminator) - case reflect.Uint32: - if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil { - fv.SetUint(x) - return nil - } - case reflect.Uint64: - if x, err := strconv.ParseUint(tok.value, 0, 64); err == nil { - fv.SetUint(x) - return nil - } - } - return p.errorf("invalid %v: %v", v.Type(), tok.value) -} - -// UnmarshalText reads a protocol buffer in Text format. UnmarshalText resets pb -// before starting to unmarshal, so any existing data in pb is always removed. -// If a required field is not set and no other error occurs, -// UnmarshalText returns *RequiredNotSetError. -func UnmarshalText(s string, pb Message) error { - if um, ok := pb.(encoding.TextUnmarshaler); ok { - err := um.UnmarshalText([]byte(s)) - return err - } - pb.Reset() - v := reflect.ValueOf(pb) - if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil { - return pe - } - return nil -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/COMPARE-jsonnet.sh b/vendor/github.com/strickyak/jsonnet_cgo/COMPARE-jsonnet.sh deleted file mode 100644 index f33e7ae36607e34ef75f9b061f5ece651d09e83e..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/COMPARE-jsonnet.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -# To help me keep up-to-date with jsonnet, -# this will compare our copies of jsonnet files -# with the ones in a jsonnet directory. -# See "Usage:" a few lines below. - -case "$#/$1" in - 0/ ) - set ../../google/jsonnet/ - ;; - 1/*/jsonnet/ ) - : ok - ;; - * ) - echo >&2 ' -Usage: - sh $0 ?/path/to/jsonnet/? - -This command takes one argument, the jsonnet repository directory, -ending in /jsonnet/. The default is ../../google/jsonnet/. -' - exit 13 - ;; -esac - -J="$1" -test -d "$J" - -for x in \ - ast.h \ - desugarer.cpp \ - desugarer.h \ - formatter.cpp \ - formatter.h \ - json.h \ - lexer.cpp \ - lexer.h \ - libjsonnet.cpp \ - libjsonnet.h \ - md5.cpp \ - md5.h \ - parser.cpp \ - parser.h \ - pass.cpp \ - pass.h \ - state.h \ - static_analysis.cpp \ - static_analysis.h \ - static_error.h \ - std.jsonnet.h \ - string_utils.cpp \ - string_utils.h \ - unicode.h \ - vm.cpp \ - vm.h \ - # -do - ok=false - for subdir in core cpp third_party/md5 include - do - if cmp "$J/$subdir/$x" "./$x" 2>/dev/null - then - ok=true - break - fi - done - - if $ok - then - echo "ok: $x" - else - echo "******** NOT OK: $x" - fi -done diff --git a/vendor/github.com/strickyak/jsonnet_cgo/LICENSE b/vendor/github.com/strickyak/jsonnet_cgo/LICENSE deleted file mode 100644 index adea0b8660b0e64ecfb6905fc4380bb387ca7875..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Strick Yak - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/LICENSE.jsonnet b/vendor/github.com/strickyak/jsonnet_cgo/LICENSE.jsonnet deleted file mode 100644 index d645695673349e3947e8e5ae42332d0ac3164cd7..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/LICENSE.jsonnet +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/strickyak/jsonnet_cgo/LICENSE.md5 b/vendor/github.com/strickyak/jsonnet_cgo/LICENSE.md5 deleted file mode 100644 index e1ec4b8defc5999e6ac6113cff6edbd11a004028..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/LICENSE.md5 +++ /dev/null @@ -1,29 +0,0 @@ -MD5 -Converted to C++ class by Frank Thilo (thilo@unix-ag.org) -for bzflag (http://www.bzflag.org) - -based on: - -md5.h and md5.c -reference implementation of RFC 1321 - -Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All -rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD5 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD5 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this -documentation and/or software. diff --git a/vendor/github.com/strickyak/jsonnet_cgo/README.md b/vendor/github.com/strickyak/jsonnet_cgo/README.md deleted file mode 100644 index 7633a565cc458efae11caddd2935229701b8d039..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/README.md +++ /dev/null @@ -1,25 +0,0 @@ -jsonnet_cgo -=========== - -Simple golang cgo wrapper around JSonnet VM. - -Everything in libjsonnet.h is covered except the multi-file evaluators. - -See jsonnet_test.go for how to use it. - -Quick example: - - vm := jsonnet.Make() - vm.ExtVar("color", "purple") - - x, err := vm.EvaluateSnippet(`Test_Demo`, `"dark " + std.extVar("color")`) - - if err != nil { - panic(err) - } - if x != "\"dark purple\"\n" { - panic("fail: we got " + x) - } - - vm.Destroy() - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/ast.h b/vendor/github.com/strickyak/jsonnet_cgo/ast.h deleted file mode 100644 index 499821404df3493cf400ebe000285076d0bd0efb..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/ast.h +++ /dev/null @@ -1,898 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_AST_H -#define JSONNET_AST_H - -#include <cstdlib> -#include <cassert> - -#include <iostream> -#include <string> -#include <map> -#include <vector> - -#include "lexer.h" -#include "unicode.h" - -enum ASTType { - AST_APPLY, - AST_ARRAY, - AST_ARRAY_COMPREHENSION, - AST_ARRAY_COMPREHENSION_SIMPLE, - AST_ASSERT, - AST_BINARY, - AST_BUILTIN_FUNCTION, - AST_CONDITIONAL, - AST_DESUGARED_OBJECT, - AST_DOLLAR, - AST_ERROR, - AST_FUNCTION, - AST_IMPORT, - AST_IMPORTSTR, - AST_INDEX, - AST_IN_SUPER, - AST_LITERAL_BOOLEAN, - AST_LITERAL_NULL, - AST_LITERAL_NUMBER, - AST_LITERAL_STRING, - AST_LOCAL, - AST_OBJECT, - AST_OBJECT_COMPREHENSION, - AST_OBJECT_COMPREHENSION_SIMPLE, - AST_PARENS, - AST_SELF, - AST_SUPER_INDEX, - AST_UNARY, - AST_VAR -}; - -/** Represents a variable / parameter / field name. */ -struct Identifier { - UString name; - Identifier(const UString &name) - : name(name) - { } -}; - -static inline std::ostream &operator<<(std::ostream &o, const Identifier *id) -{ - o << encode_utf8(id->name); - return o; -} - -typedef std::vector<const Identifier *> Identifiers; - - -/** All AST nodes are subtypes of this class. - */ -struct AST { - LocationRange location; - ASTType type; - Fodder openFodder; - Identifiers freeVariables; - AST(const LocationRange &location, ASTType type, const Fodder &open_fodder) - : location(location), type(type), openFodder(open_fodder) - { - } - virtual ~AST(void) - { - } -}; - -typedef std::vector<AST*> ASTs; - -/** Either an arg in a function apply, or a param in a closure / other function definition. - * - * They happen to have exactly the same structure. - * - * In the case of an arg, the id is optional and the expr is required. Presence of the id indicates - * that this is a named rather than positional argument. - * - * In the case of a param, the id is required and if expr is given, it is a default argument to be - * used when no argument is bound to the param. - */ -struct ArgParam { - Fodder idFodder; // Empty if no id. - const Identifier *id; // nullptr if there isn't one - Fodder eqFodder; // Empty if no id or no expr. - AST *expr; // nullptr if there wasn't one. - Fodder commaFodder; // Before the comma (if there is a comma). - // Only has id - ArgParam (const Fodder &id_fodder, const Identifier *id, const Fodder &comma_fodder) - : idFodder(id_fodder), id(id), expr(nullptr), commaFodder(comma_fodder) - { } - // Only has expr - ArgParam (AST *expr, const Fodder &comma_fodder) - : id(nullptr), expr(expr), commaFodder(comma_fodder) - { } - // Has both id and expr - ArgParam (const Fodder &id_fodder, const Identifier *id, const Fodder &eq_fodder, - AST *expr, const Fodder &comma_fodder) - : idFodder(id_fodder), id(id), eqFodder(eq_fodder), expr(expr), commaFodder(comma_fodder) - { } -}; - -typedef std::vector<ArgParam> ArgParams; - -/** Used in Object & Array Comprehensions. */ -struct ComprehensionSpec { - enum Kind { - FOR, - IF - }; - Kind kind; - Fodder openFodder; - Fodder varFodder; // {} when kind != SPEC_FOR. - const Identifier *var; // Null when kind != SPEC_FOR. - Fodder inFodder; // {} when kind != SPEC_FOR. - AST *expr; - ComprehensionSpec(Kind kind, const Fodder &open_fodder, const Fodder &var_fodder, - const Identifier *var, const Fodder &in_fodder, AST *expr) - : kind(kind), openFodder(open_fodder), varFodder(var_fodder), var(var), inFodder(in_fodder), - expr(expr) - { } -}; - - -/** Represents function calls. */ -struct Apply : public AST { - AST *target; - Fodder fodderL; - ArgParams args; - bool trailingComma; - Fodder fodderR; - Fodder tailstrictFodder; - bool tailstrict; - Apply(const LocationRange &lr, const Fodder &open_fodder, AST *target, const Fodder &fodder_l, - const ArgParams &args, bool trailing_comma, const Fodder &fodder_r, - const Fodder &tailstrict_fodder, bool tailstrict) - : AST(lr, AST_APPLY, open_fodder), target(target), fodderL(fodder_l), args(args), - trailingComma(trailing_comma), fodderR(fodder_r), tailstrictFodder(tailstrict_fodder), - tailstrict(tailstrict) - { } -}; - -/** Represents e { }. Desugared to e + { }. */ -struct ApplyBrace : public AST { - AST *left; - AST *right; // This is always an object or object comprehension. - ApplyBrace(const LocationRange &lr, const Fodder &open_fodder, AST *left, AST *right) - : AST(lr, AST_BINARY, open_fodder), left(left), right(right) - { } -}; - -/** Represents array constructors [1, 2, 3]. */ -struct Array : public AST { - struct Element { - AST *expr; - Fodder commaFodder; - Element(AST *expr, const Fodder &comma_fodder) - : expr(expr), commaFodder(comma_fodder) - { } - }; - typedef std::vector<Element> Elements; - Elements elements; - bool trailingComma; - Fodder closeFodder; - Array(const LocationRange &lr, const Fodder &open_fodder, const Elements &elements, - bool trailing_comma, const Fodder &close_fodder) - : AST(lr, AST_ARRAY, open_fodder), elements(elements), trailingComma(trailing_comma), - closeFodder(close_fodder) - { } -}; - -/** Represents array comprehensions (which are like Python list comprehensions). */ -struct ArrayComprehension : public AST { - AST* body; - Fodder commaFodder; - bool trailingComma; - std::vector<ComprehensionSpec> specs; - Fodder closeFodder; - ArrayComprehension(const LocationRange &lr, const Fodder &open_fodder, AST *body, - const Fodder &comma_fodder, bool trailing_comma, - const std::vector<ComprehensionSpec> &specs, const Fodder &close_fodder) - : AST(lr, AST_ARRAY_COMPREHENSION, open_fodder), body(body), commaFodder(comma_fodder), - trailingComma(trailing_comma), specs(specs), closeFodder(close_fodder) - { - assert(specs.size() > 0); - } -}; - -/** Represents an assert expression (not an object-level assert). - * - * After parsing, message can be nullptr indicating that no message was specified. This AST is - * elimiated by desugaring. - */ -struct Assert : public AST { - AST *cond; - Fodder colonFodder; - AST *message; - Fodder semicolonFodder; - AST *rest; - Assert(const LocationRange &lr, const Fodder &open_fodder, AST *cond, - const Fodder &colon_fodder, AST *message, const Fodder &semicolon_fodder, AST *rest) - : AST(lr, AST_ASSERT, open_fodder), cond(cond), colonFodder(colon_fodder), - message(message), semicolonFodder(semicolon_fodder), rest(rest) - { } -}; - -enum BinaryOp { - BOP_MULT, - BOP_DIV, - BOP_PERCENT, - - BOP_PLUS, - BOP_MINUS, - - BOP_SHIFT_L, - BOP_SHIFT_R, - - BOP_GREATER, - BOP_GREATER_EQ, - BOP_LESS, - BOP_LESS_EQ, - BOP_IN, - - BOP_MANIFEST_EQUAL, - BOP_MANIFEST_UNEQUAL, - - BOP_BITWISE_AND, - BOP_BITWISE_XOR, - BOP_BITWISE_OR, - - BOP_AND, - BOP_OR -}; - -static inline std::string bop_string (BinaryOp bop) -{ - switch (bop) { - case BOP_MULT: return "*"; - case BOP_DIV: return "/"; - case BOP_PERCENT: return "%"; - - case BOP_PLUS: return "+"; - case BOP_MINUS: return "-"; - - case BOP_SHIFT_L: return "<<"; - case BOP_SHIFT_R: return ">>"; - - case BOP_GREATER: return ">"; - case BOP_GREATER_EQ: return ">="; - case BOP_LESS: return "<"; - case BOP_LESS_EQ: return "<="; - case BOP_IN: return "in"; - - case BOP_MANIFEST_EQUAL: return "=="; - case BOP_MANIFEST_UNEQUAL: return "!="; - - case BOP_BITWISE_AND: return "&"; - case BOP_BITWISE_XOR: return "^"; - case BOP_BITWISE_OR: return "|"; - - case BOP_AND: return "&&"; - case BOP_OR: return "||"; - - default: - std::cerr << "INTERNAL ERROR: Unrecognised binary operator: " << bop << std::endl; - std::abort(); - } -} - -/** Represents binary operators. */ -struct Binary : public AST { - AST *left; - Fodder opFodder; - BinaryOp op; - AST *right; - Binary(const LocationRange &lr, const Fodder &open_fodder, AST *left, const Fodder &op_fodder, - BinaryOp op, AST *right) - : AST(lr, AST_BINARY, open_fodder), left(left), opFodder(op_fodder), op(op), right(right) - { } -}; - -/** Represents built-in functions. - * - * There is no parse rule to build this AST. Instead, it is used to build the std object in the - * interpreter. - */ -struct BuiltinFunction : public AST { - std::string name; - Identifiers params; - BuiltinFunction(const LocationRange &lr, const std::string &name, - const Identifiers ¶ms) - : AST(lr, AST_BUILTIN_FUNCTION, Fodder{}), name(name), params(params) - { } -}; - -/** Represents if then else. - * - * After parsing, branchFalse can be nullptr indicating that no else branch was specified. The - * desugarer fills this in with a LiteralNull. - */ -struct Conditional : public AST { - AST *cond; - Fodder thenFodder; - AST *branchTrue; - Fodder elseFodder; - AST *branchFalse; - Conditional(const LocationRange &lr, const Fodder &open_fodder, AST *cond, - const Fodder &then_fodder, AST *branch_true, const Fodder &else_fodder, - AST *branch_false) - : AST(lr, AST_CONDITIONAL, open_fodder), cond(cond), thenFodder(then_fodder), - branchTrue(branch_true), elseFodder(else_fodder), branchFalse(branch_false) - { } -}; - -/** Represents the $ keyword. */ -struct Dollar : public AST { - Dollar(const LocationRange &lr, const Fodder &open_fodder) - : AST(lr, AST_DOLLAR, open_fodder) - { } -}; - -/** Represents error e. */ -struct Error : public AST { - AST *expr; - Error(const LocationRange &lr, const Fodder &open_fodder, AST *expr) - : AST(lr, AST_ERROR, open_fodder), expr(expr) - { } -}; - -/** Represents closures. */ -struct Function : public AST { - Fodder parenLeftFodder; - ArgParams params; - bool trailingComma; - Fodder parenRightFodder; - AST *body; - Function(const LocationRange &lr, const Fodder &open_fodder, const Fodder &paren_left_fodder, - const ArgParams ¶ms, bool trailing_comma, const Fodder &paren_right_fodder, - AST *body) - : AST(lr, AST_FUNCTION, open_fodder), parenLeftFodder(paren_left_fodder), - params(params), trailingComma(trailing_comma), parenRightFodder(paren_right_fodder), - body(body) - { } -}; - -struct LiteralString; - -/** Represents import "file". */ -struct Import : public AST { - LiteralString *file; - Import(const LocationRange &lr, const Fodder &open_fodder, LiteralString *file) - : AST(lr, AST_IMPORT, open_fodder), file(file) - { } -}; - -/** Represents importstr "file". */ -struct Importstr : public AST { - LiteralString *file; - Importstr(const LocationRange &lr, const Fodder &open_fodder, LiteralString *file) - : AST(lr, AST_IMPORTSTR, open_fodder), file(file) - { } -}; - -/** Represents both e[e] and the syntax sugar e.f. - * - * One of index and id will be nullptr before desugaring. After desugaring id will be nullptr. - */ -struct Index : public AST { - AST *target; - Fodder dotFodder; // When index is being used, this is the fodder before the [. - bool isSlice; - AST *index; - Fodder endColonFodder; // When end is being used, this is the fodder before the :. - AST *end; - Fodder stepColonFodder; // When step is being used, this is the fodder before the :. - AST *step; - Fodder idFodder; // When index is being used, this is the fodder before the ]. - const Identifier *id; - // Use this constructor for e.f - Index(const LocationRange &lr, const Fodder &open_fodder, AST *target, const Fodder &dot_fodder, - const Fodder &id_fodder, const Identifier *id) - : AST(lr, AST_INDEX, open_fodder), target(target), dotFodder(dot_fodder), isSlice(false), - index(nullptr), end(nullptr), step(nullptr), idFodder(id_fodder), id(id) - { } - // Use this constructor for e[x:y:z] with nullptr for index, end or step if not present. - Index(const LocationRange &lr, const Fodder &open_fodder, AST *target, const Fodder &dot_fodder, - bool is_slice, AST *index, const Fodder &end_colon_fodder, AST *end, - const Fodder &step_colon_fodder, AST *step, const Fodder &id_fodder) - : AST(lr, AST_INDEX, open_fodder), target(target), dotFodder(dot_fodder), isSlice(is_slice), - index(index), endColonFodder(end_colon_fodder), end(end), - stepColonFodder(step_colon_fodder), step(step), idFodder(id_fodder), id(nullptr) - { } -}; - -/** Represents local x = e; e. After desugaring, functionSugar is false. */ -struct Local : public AST { - struct Bind { - Fodder varFodder; - const Identifier *var; - Fodder opFodder; - AST *body; - bool functionSugar; - Fodder parenLeftFodder; - ArgParams params; // If functionSugar == true - bool trailingComma; - Fodder parenRightFodder; - Fodder closeFodder; - Bind(const Fodder &var_fodder, const Identifier *var, const Fodder &op_fodder, AST *body, - bool function_sugar, const Fodder &paren_left_fodder, const ArgParams ¶ms, - bool trailing_comma, const Fodder &paren_right_fodder, const Fodder &close_fodder) - : varFodder(var_fodder), var(var), opFodder(op_fodder), body(body), - functionSugar(function_sugar), parenLeftFodder(paren_left_fodder), params(params), - trailingComma(trailing_comma), parenRightFodder(paren_right_fodder), - closeFodder(close_fodder) - { } - }; - typedef std::vector<Bind> Binds; - Binds binds; - AST *body; - Local(const LocationRange &lr, const Fodder &open_fodder, const Binds &binds, AST *body) - : AST(lr, AST_LOCAL, open_fodder), binds(binds), body(body) - { } -}; - -/** Represents true and false. */ -struct LiteralBoolean : public AST { - bool value; - LiteralBoolean(const LocationRange &lr, const Fodder &open_fodder, bool value) - : AST(lr, AST_LITERAL_BOOLEAN, open_fodder), value(value) - { } -}; - -/** Represents the null keyword. */ -struct LiteralNull : public AST { - LiteralNull(const LocationRange &lr, const Fodder &open_fodder) - : AST(lr, AST_LITERAL_NULL, open_fodder) - { } -}; - -/** Represents JSON numbers. */ -struct LiteralNumber : public AST { - double value; - std::string originalString; - LiteralNumber(const LocationRange &lr, const Fodder &open_fodder, const std::string &str) - : AST(lr, AST_LITERAL_NUMBER, open_fodder), value(strtod(str.c_str(), nullptr)), - originalString(str) - { } -}; - -/** Represents JSON strings. */ -struct LiteralString : public AST { - UString value; - enum TokenKind { SINGLE, DOUBLE, BLOCK, VERBATIM_SINGLE, VERBATIM_DOUBLE }; - TokenKind tokenKind; - std::string blockIndent; // Only contains ' ' and '\t'. - std::string blockTermIndent; // Only contains ' ' and '\t'. - LiteralString(const LocationRange &lr, const Fodder &open_fodder, const UString &value, - TokenKind token_kind, const std::string &block_indent, - const std::string &block_term_indent) - : AST(lr, AST_LITERAL_STRING, open_fodder), value(value), tokenKind(token_kind), - blockIndent(block_indent), blockTermIndent(block_term_indent) - { } -}; - - -struct ObjectField { - // Depending on the kind of Jsonnet field, the fields of this C++ class are used for storing - // different parts of the AST. - enum Kind { - - // <fodder1> 'assert' <expr2> - // [ <opFodder> : <expr3> ] - // <commaFodder> - ASSERT, - - // <fodder1> id - // [ <fodderL> '(' <params> <fodderR> ')' ] - // <opFodder> [+]:[:[:]] <expr2> - // <commaFodder> - FIELD_ID, - - // <fodder1> '[' <expr1> <fodder2> ']' - // [ <fodderL> '(' <params> <fodderR> ')' ] - // <opFodder> [+]:[:[:]] <expr2> - // <commaFodder> - FIELD_EXPR, - - // <expr1> - // <fodderL> '(' <params> <fodderR> ')' - // <opFodder> [+]:[:[:]] <expr2> - // <commaFodder> - FIELD_STR, - - // <fodder1> 'local' <fodder2> id - // [ <fodderL> '(' <params> <fodderR> ')' ] - // [ <opFodder> = <expr2> ] - // <commaFodder> - LOCAL, - }; - - // NOTE TO SELF: sort out fodder1-4, then modify desugarer (maybe) parser and unparser. - - enum Hide { - HIDDEN, // f:: e - INHERIT, // f: e - VISIBLE, // f::: e - }; - enum Kind kind; - Fodder fodder1, fodder2, fodderL, fodderR; - enum Hide hide; // (ignore if kind != FIELD_something - bool superSugar; // +: (ignore if kind != FIELD_something) - bool methodSugar; // f(x, y, z): ... (ignore if kind == ASSERT) - AST *expr1; // Not in scope of the object - const Identifier *id; - ArgParams params; // If methodSugar == true then holds the params. - bool trailingComma; // If methodSugar == true then remembers the trailing comma. - Fodder opFodder; // Before the : or = - AST *expr2, *expr3; // In scope of the object (can see self). - Fodder commaFodder; // If this field is followed by a comma, this is its fodder. - - ObjectField( - enum Kind kind, const Fodder &fodder1, const Fodder &fodder2, const Fodder &fodder_l, - const Fodder &fodder_r, enum Hide hide, bool super_sugar, bool method_sugar, AST *expr1, - const Identifier *id, const ArgParams ¶ms, bool trailing_comma, const Fodder &op_fodder, - AST *expr2, AST *expr3, const Fodder &comma_fodder) - : kind(kind), fodder1(fodder1), fodder2(fodder2), fodderL(fodder_l), fodderR(fodder_r), - hide(hide), superSugar(super_sugar), methodSugar(method_sugar), expr1(expr1), id(id), - params(params), trailingComma(trailing_comma), opFodder(op_fodder), expr2(expr2), - expr3(expr3), commaFodder(comma_fodder) - { - // Enforce what is written in comments above. - assert(kind != ASSERT || (hide == VISIBLE && !superSugar && !methodSugar)); - assert(kind != LOCAL || (hide == VISIBLE && !superSugar)); - assert(kind != FIELD_ID || (id != nullptr && expr1 == nullptr)); - assert(kind == FIELD_ID || kind == LOCAL || id == nullptr); - assert(methodSugar || (params.size() == 0 && !trailingComma)); - assert(kind == ASSERT || expr3 == nullptr); - } - // For when we don't know if it's a function or not. - static ObjectField Local( - const Fodder &fodder1, const Fodder &fodder2, const Fodder &fodder_l, - const Fodder &fodder_r, bool method_sugar, const Identifier *id, const ArgParams ¶ms, - bool trailing_comma, const Fodder &op_fodder, AST *body, const Fodder &comma_fodder) - { - return ObjectField( - LOCAL, fodder1, fodder2, fodder_l, fodder_r, VISIBLE, false, method_sugar, nullptr, id, - params, trailing_comma, op_fodder, body, nullptr, comma_fodder); - } - static ObjectField Local( - const Fodder &fodder1, const Fodder &fodder2, const Identifier *id, - const Fodder &op_fodder, AST *body, const Fodder &comma_fodder) - { - return ObjectField( - LOCAL, fodder1, fodder2, Fodder{}, Fodder{}, VISIBLE, false, false, nullptr, id, - ArgParams{}, false, op_fodder, body, nullptr, comma_fodder); - } - static ObjectField LocalMethod( - const Fodder &fodder1, const Fodder &fodder2, const Fodder &fodder_l, - const Fodder &fodder_r, const Identifier *id, const ArgParams ¶ms, bool trailing_comma, - const Fodder &op_fodder, AST *body, const Fodder &comma_fodder) - { - return ObjectField( - LOCAL, fodder1, fodder2, fodder_l, fodder_r, VISIBLE, false, true, nullptr, id, params, - trailing_comma, op_fodder, body, nullptr, comma_fodder); - } - static ObjectField Assert(const Fodder &fodder1, AST *body, const Fodder &op_fodder, AST *msg, - const Fodder &comma_fodder) - { - return ObjectField( - ASSERT, fodder1, Fodder{}, Fodder{}, Fodder{}, VISIBLE, false, false, nullptr, nullptr, - ArgParams{}, false, op_fodder, body, msg, comma_fodder); - } -}; -typedef std::vector<ObjectField> ObjectFields; - -/** Represents object constructors { f: e ... }. - * - * The trailing comma is only allowed if fields.size() > 0. Converted to DesugaredObject during - * desugaring. - */ -struct Object : public AST { - ObjectFields fields; - bool trailingComma; - Fodder closeFodder; - Object(const LocationRange &lr, const Fodder &open_fodder, const ObjectFields &fields, - bool trailing_comma, const Fodder &close_fodder) - : AST(lr, AST_OBJECT, open_fodder), fields(fields), trailingComma(trailing_comma), - closeFodder(close_fodder) - { - assert(fields.size() > 0 || !trailing_comma); - if (fields.size() > 0) - assert(trailing_comma || fields[fields.size() - 1].commaFodder.size() == 0); - } -}; - -/** Represents object constructors { f: e ... } after desugaring. - * - * The assertions either return true or raise an error. - */ -struct DesugaredObject : public AST { - struct Field { - enum ObjectField::Hide hide; - AST *name; - AST *body; - Field(enum ObjectField::Hide hide, AST *name, AST *body) - : hide(hide), name(name), body(body) - { } - }; - typedef std::vector<Field> Fields; - ASTs asserts; - Fields fields; - DesugaredObject(const LocationRange &lr, const ASTs &asserts, const Fields &fields) - : AST(lr, AST_DESUGARED_OBJECT, Fodder{}), asserts(asserts), fields(fields) - { } -}; - - -/** Represents object comprehension { [e]: e for x in e for.. if... }. */ -struct ObjectComprehension : public AST { - ObjectFields fields; - bool trailingComma; - std::vector<ComprehensionSpec> specs; - Fodder closeFodder; - ObjectComprehension(const LocationRange &lr, const Fodder &open_fodder, - const ObjectFields &fields, bool trailing_comma, - const std::vector<ComprehensionSpec> &specs, const Fodder &close_fodder) - - : AST(lr, AST_OBJECT_COMPREHENSION, open_fodder), fields(fields), - trailingComma(trailing_comma), specs(specs), closeFodder(close_fodder) - { } -}; - -/** Represents post-desugaring object comprehension { [e]: e for x in e }. */ -struct ObjectComprehensionSimple : public AST { - AST *field; - AST *value; - const Identifier *id; - AST *array; - ObjectComprehensionSimple(const LocationRange &lr, AST *field, AST *value, - const Identifier *id, AST *array) - : AST(lr, AST_OBJECT_COMPREHENSION_SIMPLE, Fodder{}), field(field), value(value), id(id), - array(array) - { } -}; - -/** Represents (e), which is desugared. */ -struct Parens : public AST { - AST *expr; - Fodder closeFodder; - Parens(const LocationRange &lr, const Fodder &open_fodder, AST *expr, - const Fodder &close_fodder) - : AST(lr, AST_PARENS, open_fodder), expr(expr), closeFodder(close_fodder) - { } -}; - -/** Represents the self keyword. */ -struct Self : public AST { - Self(const LocationRange &lr, const Fodder &open_fodder) - : AST(lr, AST_SELF, open_fodder) - { } -}; - -/** Represents the super[e] and super.f constructs. - * - * Either index or identifier will be set before desugaring. After desugaring, id will be - * nullptr. - */ -struct SuperIndex : public AST { - Fodder dotFodder; - AST *index; - Fodder idFodder; - const Identifier *id; - SuperIndex(const LocationRange &lr, const Fodder &open_fodder, const Fodder &dot_fodder, - AST *index, const Fodder &id_fodder, const Identifier *id) - : AST(lr, AST_SUPER_INDEX, open_fodder), dotFodder(dot_fodder), index(index), - idFodder(id_fodder), id(id) - { } -}; - -/** Represents the e in super construct. - */ -struct InSuper : public AST { - AST *element; - Fodder inFodder; - Fodder superFodder; - InSuper(const LocationRange &lr, const Fodder &open_fodder, - AST *element, const Fodder &in_fodder, const Fodder &super_fodder) - : AST(lr, AST_IN_SUPER, open_fodder), element(element), - inFodder(in_fodder), superFodder(super_fodder) - { } -}; - -enum UnaryOp { - UOP_NOT, - UOP_BITWISE_NOT, - UOP_PLUS, - UOP_MINUS -}; - -static inline std::string uop_string (UnaryOp uop) -{ - switch (uop) { - case UOP_PLUS: return "+"; - case UOP_MINUS: return "-"; - case UOP_BITWISE_NOT: return "~"; - case UOP_NOT: return "!"; - - default: - std::cerr << "INTERNAL ERROR: Unrecognised unary operator: " << uop << std::endl; - std::abort(); - } -} - -/** Represents unary operators. */ -struct Unary : public AST { - UnaryOp op; - AST *expr; - Unary(const LocationRange &lr, const Fodder &open_fodder, UnaryOp op, AST *expr) - : AST(lr, AST_UNARY, open_fodder), op(op), expr(expr) - { } -}; - -/** Represents variables. */ -struct Var : public AST { - const Identifier *id; - Var(const LocationRange &lr, const Fodder &open_fodder, const Identifier *id) - : AST(lr, AST_VAR, open_fodder), id(id) - { } -}; - - -/** Allocates ASTs on demand, frees them in its destructor. - */ -class Allocator { - std::map<UString, const Identifier*> internedIdentifiers; - ASTs allocated; - public: - template <class T, class... Args> T* make(Args&&... args) - { - auto r = new T(std::forward<Args>(args)...); - allocated.push_back(r); - return r; - } - - template <class T> T *clone(T * ast) { - auto r = new T(*ast); - allocated.push_back(r); - return r; - } - /** Returns interned identifiers. - * - * The location used in the Identifier AST is that of the first one parsed. - */ - const Identifier *makeIdentifier(const UString &name) - { - auto it = internedIdentifiers.find(name); - if (it != internedIdentifiers.end()) { - return it->second; - } - auto r = new Identifier(name); - internedIdentifiers[name] = r; - return r; - } - ~Allocator() - { - for (auto x : allocated) { - delete x; - } - allocated.clear(); - for (auto x : internedIdentifiers) { - delete x.second; - } - internedIdentifiers.clear(); - } -}; - -namespace { - -// Precedences used by various compilation units are defined here. -const int APPLY_PRECEDENCE = 2; // Function calls and indexing. -const int UNARY_PRECEDENCE = 4; // Logical and bitwise negation, unary + - -const int BEFORE_ELSE_PRECEDENCE = 15; // True branch of an if. -const int MAX_PRECEDENCE = 16; // Local, If, Import, Function, Error - -/** These are the binary operator precedences, unary precedence is given by - * UNARY_PRECEDENCE. - */ -std::map<BinaryOp, int> build_precedence_map(void) -{ - std::map<BinaryOp, int> r; - - r[BOP_MULT] = 5; - r[BOP_DIV] = 5; - r[BOP_PERCENT] = 5; - - r[BOP_PLUS] = 6; - r[BOP_MINUS] = 6; - - r[BOP_SHIFT_L] = 7; - r[BOP_SHIFT_R] = 7; - - r[BOP_GREATER] = 8; - r[BOP_GREATER_EQ] = 8; - r[BOP_LESS] = 8; - r[BOP_LESS_EQ] = 8; - r[BOP_IN] = 8; - - r[BOP_MANIFEST_EQUAL] = 9; - r[BOP_MANIFEST_UNEQUAL] = 9; - - r[BOP_BITWISE_AND] = 10; - - r[BOP_BITWISE_XOR] = 11; - - r[BOP_BITWISE_OR] = 12; - - r[BOP_AND] = 13; - - r[BOP_OR] = 14; - - return r; -} - -std::map<std::string, UnaryOp> build_unary_map(void) -{ - std::map<std::string, UnaryOp> r; - r["!"] = UOP_NOT; - r["~"] = UOP_BITWISE_NOT; - r["+"] = UOP_PLUS; - r["-"] = UOP_MINUS; - return r; -} - -std::map<std::string, BinaryOp> build_binary_map(void) -{ - std::map<std::string, BinaryOp> r; - - r["*"] = BOP_MULT; - r["/"] = BOP_DIV; - r["%"] = BOP_PERCENT; - - r["+"] = BOP_PLUS; - r["-"] = BOP_MINUS; - - r["<<"] = BOP_SHIFT_L; - r[">>"] = BOP_SHIFT_R; - - r[">"] = BOP_GREATER; - r[">="] = BOP_GREATER_EQ; - r["<"] = BOP_LESS; - r["<="] = BOP_LESS_EQ; - r["in"] = BOP_IN; - - r["=="] = BOP_MANIFEST_EQUAL; - r["!="] = BOP_MANIFEST_UNEQUAL; - - r["&"] = BOP_BITWISE_AND; - r["^"] = BOP_BITWISE_XOR; - r["|"] = BOP_BITWISE_OR; - - r["&&"] = BOP_AND; - r["||"] = BOP_OR; - return r; -} - -auto precedence_map = build_precedence_map(); -auto unary_map = build_unary_map(); -auto binary_map = build_binary_map(); - -} // namespace - -#endif // JSONNET_AST_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/bridge.c b/vendor/github.com/strickyak/jsonnet_cgo/bridge.c deleted file mode 100644 index b5d801bfbcda922facab2b8c0d0c83d1da2d07b4..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/bridge.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <memory.h> -#include <stdio.h> -#include <string.h> -#include <libjsonnet.h> -#include "_cgo_export.h" - -char* CallImport_cgo(void *ctx, const char *base, const char *rel, char **found_here, int *success) { - struct JsonnetVm* vm = ctx; - return go_call_import(vm, (char*)base, (char*)rel, found_here, success); -} - -struct JsonnetJsonValue* CallNative_cgo(void* ctx, const struct JsonnetJsonValue* const* argv, int* success) { - GoUintptr key = (GoUintptr)ctx; - return go_call_native(key, (struct JsonnetJsonValue**)argv, success); -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/desugarer.cpp b/vendor/github.com/strickyak/jsonnet_cgo/desugarer.cpp deleted file mode 100644 index 26b766c082991d46ee4c4b14b912babc41b8ce5f..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/desugarer.cpp +++ /dev/null @@ -1,934 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <cassert> - -#include "ast.h" -#include "desugarer.h" -#include "lexer.h" -#include "parser.h" -#include "pass.h" -#include "string_utils.h" - -static const Fodder EF; // Empty fodder. - -static const LocationRange E; // Empty. - -struct BuiltinDecl { - UString name; - std::vector<UString> params; -}; - -static unsigned long max_builtin = 26; -BuiltinDecl jsonnet_builtin_decl(unsigned long builtin) -{ - switch (builtin) { - case 0: return {U"makeArray", {U"sz", U"func"}}; - case 1: return {U"pow", {U"x", U"n"}}; - case 2: return {U"floor", {U"x"}}; - case 3: return {U"ceil", {U"x"}}; - case 4: return {U"sqrt", {U"x"}}; - case 5: return {U"sin", {U"x"}}; - case 6: return {U"cos", {U"x"}}; - case 7: return {U"tan", {U"x"}}; - case 8: return {U"asin", {U"x"}}; - case 9: return {U"acos", {U"x"}}; - case 10: return {U"atan", {U"x"}}; - case 11: return {U"type", {U"x"}}; - case 12: return {U"filter", {U"func", U"arr"}}; - case 13: return {U"objectHasEx", {U"obj", U"f", U"inc_hidden"}}; - case 14: return {U"length", {U"x"}}; - case 15: return {U"objectFieldsEx", {U"obj", U"inc_hidden"}}; - case 16: return {U"codepoint", {U"str"}}; - case 17: return {U"char", {U"n"}}; - case 18: return {U"log", {U"n"}}; - case 19: return {U"exp", {U"n"}}; - case 20: return {U"mantissa", {U"n"}}; - case 21: return {U"exponent", {U"n"}}; - case 22: return {U"modulo", {U"a", U"b"}}; - case 23: return {U"extVar", {U"x"}}; - case 24: return {U"primitiveEquals", {U"a", U"b"}}; - case 25: return {U"native", {U"name"}}; - case 26: return {U"md5", {U"str"}}; - default: - std::cerr << "INTERNAL ERROR: Unrecognized builtin function: " << builtin << std::endl; - std::abort(); - } - // Quiet, compiler. - return BuiltinDecl(); -} - -static constexpr char STD_CODE[] = { - #include "std.jsonnet.h" -}; - -/** Desugar Jsonnet expressions to reduce the number of constructs the rest of the implementation - * needs to understand. - * - * Desugaring should happen immediately after parsing, i.e. before static analysis and execution. - * Temporary variables introduced here should be prefixed with $ to ensure they do not clash with - * variables used in user code. - */ -class Desugarer { - - Allocator *alloc; - - template <class T, class... Args> T* make(Args&&... args) - { - return alloc->make<T>(std::forward<Args>(args)...); - } - - AST *clone(AST *ast) - { return clone_ast(*alloc, ast); } - - const Identifier *id(const UString &s) - { return alloc->makeIdentifier(s); } - - LiteralString *str(const UString &s) - { return make<LiteralString>(E, EF, s, LiteralString::DOUBLE, "", ""); } - - LiteralString *str(const LocationRange &loc, const UString &s) - { return make<LiteralString>(loc, EF, s, LiteralString::DOUBLE, "", ""); } - - LiteralNull *null(void) - { return make<LiteralNull>(E, EF); } - - Var *var(const Identifier *ident) - { return make<Var>(E, EF, ident); } - - Var *std(void) - { return var(id(U"std")); } - - - Local::Bind bind(const Identifier *id, AST *body) - { - return Local::Bind(EF, id, EF, body, false, EF, ArgParams{}, false, EF, EF); - } - - Local::Binds singleBind(const Identifier *id, AST *body) - { - return {bind(id, body)}; - } - - Array *singleton(AST *body) - { - return make<Array>(body->location, EF, Array::Elements{Array::Element(body, EF)}, - false, EF); - } - - Apply *stdFunc(const UString &name, AST *v) - { - return make<Apply>( - v->location, - EF, - make<Index>(E, EF, std(), EF, false, str(name), EF, nullptr, EF, nullptr, EF), - EF, - ArgParams{{v, EF}}, - false, // trailingComma - EF, - EF, - true // tailstrict - ); - } - - Apply *stdFunc(const LocationRange &loc, const UString &name, AST *a, AST *b) - { - return make<Apply>( - loc, - EF, - make<Index>(E, EF, std(), EF, false, str(name), EF, nullptr, EF, nullptr, EF), - EF, - ArgParams{{a, EF}, {b, EF}}, - false, // trailingComma - EF, - EF, - true // tailstrict - ); - } - - Apply *length(AST *v) - { - return stdFunc(U"length", v); - } - - Apply *type(AST *v) - { - return stdFunc(U"type", v); - } - - Apply *primitiveEquals(const LocationRange &loc, AST *a, AST *b) - { - return stdFunc(loc, U"primitiveEquals", a, b); - } - - Apply *equals(const LocationRange &loc, AST *a, AST *b) - { - return stdFunc(loc, U"equals", a, b); - } - - Error *error(AST *msg) - { - return make<Error>(msg->location, EF, msg); - } - - Error *error(const LocationRange &loc, const UString &msg) - { - return error(str(loc, msg)); - } - - public: - Desugarer(Allocator *alloc) - : alloc(alloc) - { } - - void desugarParams(ArgParams ¶ms, unsigned obj_level) - { - for (auto ¶m : params) { - if (param.expr) { - // Default arg. - desugar(param.expr, obj_level); - } - } - } - - // For all occurrences, records the identifier that will replace super[e] - // If self occurs, also map the self identifier to nullptr. - typedef std::vector<std::pair<const Identifier *, AST *>> SuperVars; - - SuperVars desugarFields(AST *ast, ObjectFields &fields, unsigned obj_level) - { - // Desugar children - for (auto &field : fields) { - if (field.expr1 != nullptr) desugar(field.expr1, obj_level); - desugar(field.expr2, obj_level + 1); - if (field.expr3 != nullptr) desugar(field.expr3, obj_level + 1); - desugarParams(field.params, obj_level + 1); - } - - // Simplify asserts - for (auto &field : fields) { - if (field.kind != ObjectField::ASSERT) continue; - AST *msg = field.expr3; - field.expr3 = nullptr; - if (msg == nullptr) { - // The location is what appears in the stacktrace. - msg = str(field.expr2->location, U"Object assertion failed."); - } - - // if expr2 then true else error msg - field.expr2 = make<Conditional>( - field.expr2->location, - EF, - field.expr2, - EF, - make<LiteralBoolean>(E, EF, true), - EF, - error(msg)); - } - - // Remove methods - for (auto &field : fields) { - if (!field.methodSugar) continue; - field.expr2 = make<Function>( - field.expr2->location, EF, field.fodderL, field.params, field.trailingComma, - field.fodderR, field.expr2); - field.methodSugar = false; - field.params.clear(); - } - - - // Remove object-level locals - auto copy = fields; - fields.clear(); - Local::Binds binds; - for (auto &local : copy) { - if (local.kind != ObjectField::LOCAL) continue; - binds.push_back(bind(local.id, local.expr2)); - } - for (auto &field : copy) { - if (field.kind == ObjectField::LOCAL) continue; - if (!binds.empty()) - field.expr2 = make<Local>(field.expr2->location, EF, binds, field.expr2); - fields.push_back(field); - } - - // Change all to FIELD_EXPR - for (auto &field : fields) { - switch (field.kind) { - case ObjectField::ASSERT: - // Nothing to do. - break; - - case ObjectField::FIELD_ID: - field.expr1 = str(field.id->name); - field.kind = ObjectField::FIELD_EXPR; - break; - - case ObjectField::FIELD_EXPR: - // Nothing to do. - break; - - case ObjectField::FIELD_STR: - // Just set the flag. - field.kind = ObjectField::FIELD_EXPR; - break; - - case ObjectField::LOCAL: - std::cerr << "Locals should be removed by now." << std::endl; - abort(); - } - } - - /** Replaces all occurrences of self, super[f] and e in super with variables. - * - * Returns all variables and original expressions via super_vars. - */ - class SubstituteSelfSuper : public CompilerPass { - Desugarer *desugarer; - SuperVars &superVars; - unsigned &counter; - const Identifier *newSelf; - public: - SubstituteSelfSuper(Desugarer *desugarer, SuperVars &super_vars, unsigned &counter) - : CompilerPass(*desugarer->alloc), desugarer(desugarer), superVars(super_vars), - counter(counter), newSelf(nullptr) - { - } - void visitExpr(AST *&expr) - { - if (dynamic_cast<Self*>(expr)) { - if (newSelf == nullptr) { - newSelf = desugarer->id(U"$outer_self"); - superVars.emplace_back(newSelf, nullptr); - } - expr = alloc.make<Var>(expr->location, expr->openFodder, newSelf); - } else if (auto *super_index = dynamic_cast<SuperIndex*>(expr)) { - UStringStream ss; - ss << U"$outer_super_index" << (counter++); - const Identifier *super_var = desugarer->id(ss.str()); - AST *index = super_index->index; - // Desugaring of expr should already have occurred. - assert(index != nullptr); - // Re-use super_index since we're replacing it here. - superVars.emplace_back(super_var, super_index); - expr = alloc.make<Var>(expr->location, expr->openFodder, super_var); - } else if (auto *in_super = dynamic_cast<InSuper*>(expr)) { - UStringStream ss; - ss << U"$outer_in_super" << (counter++); - const Identifier *in_super_var = desugarer->id(ss.str()); - // Re-use in_super since we're replacing it here. - superVars.emplace_back(in_super_var, in_super); - expr = alloc.make<Var>(expr->location, expr->openFodder, in_super_var); - } - CompilerPass::visitExpr(expr); - } - }; - - SuperVars super_vars; - unsigned counter = 0; - - // Remove +: - for (auto &field : fields) { - if (!field.superSugar) continue; - // We have to bind self/super from expr1 outside the class, as we copy the expression - // into the field body. - // Clone it so that we maintain the AST as a tree. - AST *index = clone(field.expr1); - // This will remove self/super. - SubstituteSelfSuper(this, super_vars, counter).expr(index); - field.expr2 = make<Conditional>( - ast->location, - EF, - make<InSuper>(ast->location, EF, index, EF, EF), - EF, - make<Binary>( - ast->location, - EF, - make<SuperIndex>(ast->location, EF, EF, clone(index), EF, nullptr), - EF, - BOP_PLUS, - field.expr2), - EF, - clone(field.expr2)); - field.superSugar = false; - } - - return super_vars; - } - - void desugar(AST *&ast_, unsigned obj_level) - { - if (auto *ast = dynamic_cast<Apply*>(ast_)) { - desugar(ast->target, obj_level); - for (ArgParam &arg : ast->args) - desugar(arg.expr, obj_level); - - } else if (auto *ast = dynamic_cast<ApplyBrace*>(ast_)) { - desugar(ast->left, obj_level); - desugar(ast->right, obj_level); - ast_ = make<Binary>(ast->location, ast->openFodder, - ast->left, EF, BOP_PLUS, ast->right); - - } else if (auto *ast = dynamic_cast<Array*>(ast_)) { - for (auto &el : ast->elements) - desugar(el.expr, obj_level); - - } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) { - for (ComprehensionSpec &spec : ast->specs) - desugar(spec.expr, obj_level); - desugar(ast->body, obj_level + 1); - - int n = ast->specs.size(); - AST *zero = make<LiteralNumber>(E, EF, "0.0"); - AST *one = make<LiteralNumber>(E, EF, "1.0"); - auto *_r = id(U"$r"); - auto *_l = id(U"$l"); - std::vector<const Identifier*> _i(n); - for (int i = 0; i < n ; ++i) { - UStringStream ss; - ss << U"$i_" << i; - _i[i] = id(ss.str()); - } - std::vector<const Identifier*> _aux(n); - for (int i = 0; i < n ; ++i) { - UStringStream ss; - ss << U"$aux_" << i; - _aux[i] = id(ss.str()); - } - - // Build it from the inside out. We keep wrapping 'in' with more ASTs. - assert(ast->specs[0].kind == ComprehensionSpec::FOR); - - int last_for = n - 1; - while (ast->specs[last_for].kind != ComprehensionSpec::FOR) - last_for--; - // $aux_{last_for}($i_{last_for} + 1, $r + [body]) - AST *in = make<Apply>( - ast->body->location, - EF, - var(_aux[last_for]), - EF, - ArgParams { - { make<Binary>(E, EF, var(_i[last_for]), EF, BOP_PLUS, one), EF}, - { make<Binary>(E, EF, var(_r), EF, BOP_PLUS, singleton(ast->body)), EF} - }, - false, // trailingComma - EF, - EF, - true // tailstrict - ); - for (int i = n - 1; i >= 0 ; --i) { - const ComprehensionSpec &spec = ast->specs[i]; - AST *out; - if (i > 0) { - int prev_for = i - 1; - while (ast->specs[prev_for].kind != ComprehensionSpec::FOR) - prev_for--; - - // aux_{prev_for}($i_{prev_for} + 1, $r) - out = make<Apply>( // False branch. - E, - EF, - var(_aux[prev_for]), - EF, - ArgParams { - { make<Binary>(E, EF, var(_i[prev_for]), EF, BOP_PLUS, one), EF, }, - { var(_r), EF, } - }, - false, // trailingComma - EF, - EF, - true // tailstrict - ); - } else { - out = var(_r); - } - switch (spec.kind) { - case ComprehensionSpec::IF: { - /* - if [[[...cond...]]] then - [[[...in...]]] - else - [[[...out...]]] - */ - in = make<Conditional>( - ast->location, - EF, - spec.expr, - EF, - in, // True branch. - EF, - out); // False branch. - } break; - case ComprehensionSpec::FOR: { - /* - local $l = [[[...array...]]] - aux_{i}(i_{i}, r) = - if i_{i} >= std.length($l) then - [[[...out...]]] - else - local [[[...var...]]] = $l[i_{i}]; - [[[...in...]]]; - if std.type($l) == "array" then - aux_{i}(0, $r) tailstrict - else - error "In comprehension, can only iterate over array.."; - */ - in = make<Local>( - ast->location, - EF, - Local::Binds { - bind(_l, spec.expr), // Need to check expr is an array - bind(_aux[i], make<Function>( - ast->location, - EF, - EF, - ArgParams{{EF, _i[i], EF}, {EF, _r, EF}}, - false, // trailingComma - EF, - make<Conditional>( - ast->location, - EF, - make<Binary>( - E, EF, var(_i[i]), EF, BOP_GREATER_EQ, length(var(_l))), - EF, - out, - EF, - make<Local>( - ast->location, - EF, - singleBind( - spec.var, - make<Index>(E, EF, var(_l), EF, false, var(_i[i]), - EF, nullptr, EF, nullptr, EF) - ), - in) - ) - ))}, - make<Conditional>( - ast->location, - EF, - equals(ast->location, type(var(_l)), str(U"array")), - EF, - make<Apply>( - E, - EF, - var(_aux[i]), - EF, - ArgParams { - {zero, EF}, - { - i == 0 - ? make<Array>(E, EF, Array::Elements{}, false, EF) - : static_cast<AST*>(var(_r)), - EF, - } - }, - false, // trailingComma - EF, - EF, - true), // tailstrict - EF, - error(ast->location, - U"In comprehension, can only iterate over array."))); - } break; - } - } - - ast_ = in; - - } else if (auto *ast = dynamic_cast<Assert*>(ast_)) { - desugar(ast->cond, obj_level); - if (ast->message == nullptr) { - ast->message = str(U"Assertion failed."); - } - desugar(ast->message, obj_level); - desugar(ast->rest, obj_level); - - // if cond then rest else error msg - AST *branch_false = make<Error>(ast->location, EF, ast->message); - ast_ = make<Conditional>(ast->location, ast->openFodder, - ast->cond, EF, ast->rest, EF, branch_false); - - } else if (auto *ast = dynamic_cast<Binary*>(ast_)) { - desugar(ast->left, obj_level); - desugar(ast->right, obj_level); - - bool invert = false; - - switch (ast->op) { - case BOP_PERCENT: { - AST *f_mod = make<Index>(E, EF, std(), EF, false, str(U"mod"), EF, - nullptr, EF, nullptr, EF); - ArgParams args = {{ast->left, EF}, {ast->right, EF}}; - ast_ = make<Apply>(ast->location, ast->openFodder, f_mod, EF, args, - false, EF, EF, false); - } break; - - case BOP_MANIFEST_UNEQUAL: - invert = true; - case BOP_MANIFEST_EQUAL: { - ast_ = equals(ast->location, ast->left, ast->right); - if (invert) - ast_ = make<Unary>(ast->location, ast->openFodder, UOP_NOT, ast_); - } - break; - - default:; - // Otherwise don't change it. - } - - } else if (dynamic_cast<const BuiltinFunction*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) { - desugar(ast->cond, obj_level); - desugar(ast->branchTrue, obj_level); - if (ast->branchFalse == nullptr) - ast->branchFalse = null(); - desugar(ast->branchFalse, obj_level); - - } else if (auto *ast = dynamic_cast<Dollar*>(ast_)) { - if (obj_level == 0) { - throw StaticError(ast->location, "No top-level object found."); - } - ast_ = var(id(U"$")); - - } else if (auto *ast = dynamic_cast<Error*>(ast_)) { - desugar(ast->expr, obj_level); - - } else if (auto *ast = dynamic_cast<Function*>(ast_)) { - desugar(ast->body, obj_level); - desugarParams(ast->params, obj_level); - - } else if (dynamic_cast<const Import*>(ast_)) { - // Nothing to do. - - } else if (dynamic_cast<const Importstr*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<InSuper*>(ast_)) { - desugar(ast->element, obj_level); - - } else if (auto *ast = dynamic_cast<Index*>(ast_)) { - desugar(ast->target, obj_level); - if (ast->isSlice) { - if (ast->index == nullptr) - ast->index = null(); - desugar(ast->index, obj_level); - - if (ast->end == nullptr) - ast->end = null(); - desugar(ast->end, obj_level); - - if (ast->step == nullptr) - ast->step = null(); - desugar(ast->step, obj_level); - - ast_ = make<Apply>( - ast->location, - EF, - make<Index>( - E, EF, std(), EF, false, str(U"slice"), EF, nullptr, EF, nullptr, EF), - EF, - ArgParams{ - {ast->target, EF}, - {ast->index, EF}, - {ast->end, EF}, - {ast->step, EF}, - }, - false, // trailing comma - EF, - EF, - false // tailstrict - ); - } else { - if (ast->id != nullptr) { - assert(ast->index == nullptr); - ast->index = str(ast->id->name); - ast->id = nullptr; - } - desugar(ast->index, obj_level); - } - - } else if (auto *ast = dynamic_cast<Local*>(ast_)) { - for (auto &bind: ast->binds) - desugar(bind.body, obj_level); - desugar(ast->body, obj_level); - - for (auto &bind: ast->binds) { - if (bind.functionSugar) { - desugarParams(bind.params, obj_level); - bind.body = make<Function>( - ast->location, ast->openFodder, bind.parenLeftFodder, bind.params, false, - bind.parenRightFodder, bind.body); - bind.functionSugar = false; - bind.params.clear(); - } - } - - } else if (dynamic_cast<const LiteralBoolean*>(ast_)) { - // Nothing to do. - - } else if (dynamic_cast<const LiteralNumber*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<LiteralString*>(ast_)) { - if ((ast->tokenKind != LiteralString::BLOCK) && - (ast->tokenKind != LiteralString::VERBATIM_DOUBLE) && - (ast->tokenKind != LiteralString::VERBATIM_SINGLE)) { - ast->value = jsonnet_string_unescape(ast->location, ast->value); - } - ast->tokenKind = LiteralString::DOUBLE; - ast->blockIndent.clear(); - - } else if (dynamic_cast<const LiteralNull*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<DesugaredObject*>(ast_)) { - for (auto &field : ast->fields) { - desugar(field.name, obj_level); - desugar(field.body, obj_level + 1); - } - for (AST *assert : ast->asserts) { - desugar(assert, obj_level + 1); - } - - } else if (auto *ast = dynamic_cast<Object*>(ast_)) { - // Hidden variable to allow outer/top binding. - if (obj_level == 0) { - const Identifier *hidden_var = id(U"$"); - auto *body = make<Self>(E, EF); - ast->fields.push_back(ObjectField::Local(EF, EF, hidden_var, EF, body, EF)); - } - - SuperVars svs = desugarFields(ast, ast->fields, obj_level); - - DesugaredObject::Fields new_fields; - ASTs new_asserts; - for (const ObjectField &field : ast->fields) { - if (field.kind == ObjectField::ASSERT) { - new_asserts.push_back(field.expr2); - } else if (field.kind == ObjectField::FIELD_EXPR) { - new_fields.emplace_back(field.hide, field.expr1, field.expr2); - } else { - std::cerr << "INTERNAL ERROR: field should have been desugared: " - << field.kind << std::endl; - } - } - ast_ = make<DesugaredObject>(ast->location, new_asserts, new_fields); - if (svs.size() > 0) { - Local::Binds binds; - for (const auto &pair : svs) { - if (pair.second == nullptr) { - // Self binding - binds.push_back(bind(pair.first, make<Self>(E, EF))); - } else { - // Super binding - binds.push_back(bind(pair.first, pair.second)); - } - } - ast_ = make<Local>(ast->location, EF, binds, ast_); - } - - } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) { - // Hidden variable to allow outer/top binding. - if (obj_level == 0) { - const Identifier *hidden_var = id(U"$"); - auto *body = make<Self>(E, EF); - ast->fields.push_back(ObjectField::Local(EF, EF, hidden_var, EF, body, EF)); - } - - SuperVars svs = desugarFields(ast, ast->fields, obj_level); - - for (ComprehensionSpec &spec : ast->specs) - desugar(spec.expr, obj_level); - - AST *field = ast->fields.front().expr1; - AST *value = ast->fields.front().expr2; - - /* { - [arr[0]]: local x = arr[1], y = arr[2], z = arr[3]; val_expr - for arr in [ [key_expr, x, y, z] for ... ] - } - */ - auto *_arr = id(U"$arr"); - AST *zero = make<LiteralNumber>(E, EF, "0.0"); - int counter = 1; - Local::Binds binds; - Array::Elements arr_e {Array::Element(field, EF)}; - for (ComprehensionSpec &spec : ast->specs) { - if (spec.kind == ComprehensionSpec::FOR) { - std::stringstream num; - num << counter++; - binds.push_back(bind( - spec.var, - make<Index>(E, EF, var(_arr), EF, false, - make<LiteralNumber>(E, EF, num.str()), EF, nullptr, EF, nullptr, - EF))); - arr_e.emplace_back(var(spec.var), EF); - } - } - AST *arr = make<ArrayComprehension>( - ast->location, - EF, - make<Array>(ast->location, EF, arr_e, false, EF), - EF, - false, - ast->specs, - EF); - desugar(arr, obj_level); - ast_ = make<ObjectComprehensionSimple>( - ast->location, - make<Index>(E, EF, var(_arr), EF, false, zero, EF, nullptr, EF, nullptr, EF), - make<Local>( - ast->location, - EF, - binds, - value), - _arr, - arr); - - } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { - desugar(ast->field, obj_level); - desugar(ast->value, obj_level + 1); - desugar(ast->array, obj_level); - - } else if (auto *ast = dynamic_cast<Parens*>(ast_)) { - // Strip parens. - desugar(ast->expr, obj_level); - ast_ = ast->expr; - - } else if (dynamic_cast<const Self*>(ast_)) { - // Nothing to do. - - } else if (auto * ast = dynamic_cast<SuperIndex*>(ast_)) { - if (ast->id != nullptr) { - assert(ast->index == nullptr); - ast->index = str(ast->id->name); - ast->id = nullptr; - } - desugar(ast->index, obj_level); - - } else if (auto *ast = dynamic_cast<Unary*>(ast_)) { - desugar(ast->expr, obj_level); - - } else if (dynamic_cast<const Var*>(ast_)) { - // Nothing to do. - - } else { - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; - std::abort(); - - } - } - - void desugarFile(AST *&ast, std::map<std::string, VmExt> *tlas) - { - desugar(ast, 0); - - // Now, implement the std library by wrapping in a local construct. - Tokens tokens = jsonnet_lex("std.jsonnet", STD_CODE); - AST *std_ast = jsonnet_parse(alloc, tokens); - desugar(std_ast, 0); - auto *std_obj = dynamic_cast<DesugaredObject*>(std_ast); - if (std_obj == nullptr) { - std::cerr << "INTERNAL ERROR: std.jsonnet not an object." << std::endl; - std::abort(); - } - - // Bind 'std' builtins that are implemented natively. - DesugaredObject::Fields &fields = std_obj->fields; - for (unsigned long c=0 ; c <= max_builtin ; ++c) { - const auto &decl = jsonnet_builtin_decl(c); - Identifiers params; - for (const auto &p : decl.params) - params.push_back(id(p)); - fields.emplace_back( - ObjectField::HIDDEN, - str(decl.name), - make<BuiltinFunction>(E, encode_utf8(decl.name), params)); - } - fields.emplace_back( - ObjectField::HIDDEN, - str(U"thisFile"), - str(decode_utf8(ast->location.file))); - - std::vector<std::string> empty; - auto line_end_blank = Fodder{{FodderElement::LINE_END, 1, 0, empty}}; - auto line_end = Fodder{{FodderElement::LINE_END, 0, 0, empty}}; - - // local body = ast; - // if std.type(body) == "function") then - // body(tlas...) - // else - // body - if (tlas != nullptr) { - LocationRange tla_loc("Top-level function"); - ArgParams args; - for (const auto &pair : *tlas) - { - AST *expr; - if (pair.second.isCode) { - // Now, implement the std library by wrapping in a local construct. - Tokens tokens = jsonnet_lex("tla:" + pair.first, pair.second.data.c_str()); - expr = jsonnet_parse(alloc, tokens); - desugar(expr, 0); - } else { - expr = str(decode_utf8(pair.second.data)); - } - // Add them as named arguments, so order does not matter. - args.emplace_back(EF, id(decode_utf8(pair.first)), EF, expr, EF); - } - const Identifier *body = id(U"top_level"); - ast = make<Local>( - ast->location, - line_end_blank, - singleBind(body, ast), - make<Conditional>( - E, - line_end, - primitiveEquals(E, type(var(body)), str(U"function")), - EF, - make<Apply>( - tla_loc, - EF, - make<Var>(E, line_end, body), - EF, - args, - false, // trailing comma - EF, - EF, - false // tailstrict - ), - line_end, - make<Var>(E, line_end, body))); - } - - // local std = (std.jsonnet stuff); ast - ast = make<Local>( - ast->location, - EF, - singleBind(id(U"std"), std_obj), - ast); - } -}; - -void jsonnet_desugar(Allocator *alloc, AST *&ast, std::map<std::string, VmExt> *tlas) -{ - Desugarer desugarer(alloc); - desugarer.desugarFile(ast, tlas); -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/desugarer.h b/vendor/github.com/strickyak/jsonnet_cgo/desugarer.h deleted file mode 100644 index 6e33ee61eb1cb01db359ba3dfb7fda347389d70e..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/desugarer.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_DESUGARING_H -#define JSONNET_DESUGARING_H - -#include <map> -#include <string> - -#include "ast.h" -#include "vm.h" - -/** Translate the AST to remove syntax sugar. - * \param alloc Allocator for making new identifiers / ASTs. - * \param ast The AST to change. - * \param tla the top level arguments. If null then do not try to process - * top-level functions. - */ -void jsonnet_desugar(Allocator *alloc, AST *&ast, std::map<std::string, VmExt> *tla); - -#endif diff --git a/vendor/github.com/strickyak/jsonnet_cgo/formatter.cpp b/vendor/github.com/strickyak/jsonnet_cgo/formatter.cpp deleted file mode 100644 index 2d58a52486c075db7f442bf7e300ca6d4029c20d..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/formatter.cpp +++ /dev/null @@ -1,1764 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <typeinfo> - -#include "formatter.h" -#include "lexer.h" -#include "pass.h" -#include "string_utils.h" -#include "unicode.h" - -static std::string unparse_id(const Identifier *id) -{ - return encode_utf8(id->name); -} - -/** If left recursive, return the left hand side, else return nullptr. */ -static AST *left_recursive(AST *ast_) -{ - if (auto *ast = dynamic_cast<Apply*>(ast_)) - return ast->target; - if (auto *ast = dynamic_cast<ApplyBrace*>(ast_)) - return ast->left; - if (auto *ast = dynamic_cast<Binary*>(ast_)) - return ast->left; - if (auto *ast = dynamic_cast<Index*>(ast_)) - return ast->target; - if (auto *ast = dynamic_cast<InSuper*>(ast_)) - return ast->element; - return nullptr; -} -static const AST *left_recursive(const AST *ast_) -{ - return left_recursive(const_cast<AST*>(ast_)); -} - -/** Pretty-print fodder. - * - * \param fodder The fodder to print - * \param space_before Whether a space should be printed before any other output. - * \param separate_token If the last fodder was an interstitial, whether a space should follow it. - */ -void fodder_fill(std::ostream &o, const Fodder &fodder, bool space_before, bool separate_token) -{ - unsigned last_indent = 0; - for (const auto &fod : fodder) { - switch (fod.kind) { - case FodderElement::LINE_END: - if (fod.comment.size() > 0) - o << " " << fod.comment[0]; - o << '\n'; - o << std::string(fod.blanks, '\n'); - o << std::string(fod.indent, ' '); - last_indent = fod.indent; - space_before = false; - break; - - case FodderElement::INTERSTITIAL: - if (space_before) - o << ' '; - o << fod.comment[0]; - space_before = true; - break; - - case FodderElement::PARAGRAPH: { - bool first = true; - for (const std::string &l : fod.comment) { - // Do not indent empty lines (note: first line is never empty). - if (l.length() > 0) { - // First line is already indented by previous fod. - if (!first) - o << std::string(last_indent, ' '); - o << l; - } - o << '\n'; - first = false; - } - o << std::string(fod.blanks, '\n'); - o << std::string(fod.indent, ' '); - last_indent = fod.indent; - space_before = false; - } break; - } - } - if (separate_token && space_before) - o << ' '; -} - -/** A model of fodder_fill that just keeps track of the column counter. */ -static void fodder_count(unsigned &column, const Fodder &fodder, bool space_before, - bool separate_token) -{ - for (const auto &fod : fodder) { - switch (fod.kind) { - case FodderElement::PARAGRAPH: - case FodderElement::LINE_END: - column = fod.indent; - space_before = false; - break; - - case FodderElement::INTERSTITIAL: - if (space_before) - column++; - column += fod.comment[0].length(); - space_before = true; - break; - } - } - if (separate_token && space_before) - column++; -} - -class Unparser { - public: - - private: - std::ostream &o; - FmtOpts opts; - - public: - Unparser(std::ostream &o, const FmtOpts &opts) - : o(o), opts(opts) - { } - - void unparseSpecs(const std::vector<ComprehensionSpec> &specs) - { - for (const auto &spec : specs) { - fill(spec.openFodder, true, true); - switch (spec.kind) { - case ComprehensionSpec::FOR: - o << "for"; - fill(spec.varFodder, true, true); - o << unparse_id(spec.var); - fill(spec.inFodder, true, true); - o << "in"; - unparse(spec.expr, true); - break; - case ComprehensionSpec::IF: - o << "if"; - unparse(spec.expr, true); - break; - } - } - } - - void fill(const Fodder &fodder, bool space_before, bool separate_token) - { - fodder_fill(o, fodder, space_before, separate_token); - } - - void unparseParams(const Fodder &fodder_l, const ArgParams ¶ms, bool trailing_comma, - const Fodder &fodder_r) - { - fill(fodder_l, false, false); - o << "("; - bool first = true; - for (const auto ¶m : params) { - if (!first) o << ","; - fill(param.idFodder, !first, true); - o << unparse_id(param.id); - if (param.expr != nullptr) { - // default arg, no spacing: x=e - fill(param.eqFodder, false, false); - o << "="; - unparse(param.expr, false); - } - fill(param.commaFodder, false, false); - first = false; - } - if (trailing_comma) - o << ","; - fill(fodder_r, false, false); - o << ")"; - } - - void unparseFieldParams(const ObjectField &field) - { - if (field.methodSugar) { - unparseParams(field.fodderL, field.params, field.trailingComma, field.fodderR); - } - } - - void unparseFields(const ObjectFields &fields, bool space_before) - { - bool first = true; - for (const auto &field : fields) { - - if (!first) o << ','; - - switch (field.kind) { - case ObjectField::LOCAL: { - fill(field.fodder1, !first || space_before, true); - o << "local"; - fill(field.fodder2, true, true); - o << unparse_id(field.id); - unparseFieldParams(field); - fill(field.opFodder, true, true); - o << "="; - unparse(field.expr2, true); - } break; - - case ObjectField::FIELD_ID: - case ObjectField::FIELD_STR: - case ObjectField::FIELD_EXPR: { - - - if (field.kind == ObjectField::FIELD_ID) { - fill(field.fodder1, !first || space_before, true); - o << unparse_id(field.id); - - } else if (field.kind == ObjectField::FIELD_STR) { - unparse(field.expr1, !first || space_before); - - } else if (field.kind == ObjectField::FIELD_EXPR) { - fill(field.fodder1, !first || space_before, true); - o << "["; - unparse(field.expr1, false); - fill(field.fodder2, false, false); - o << "]"; - } - unparseFieldParams(field); - - fill(field.opFodder, false, false); - - if (field.superSugar) o << "+"; - switch (field.hide) { - case ObjectField::INHERIT: o << ":"; break; - case ObjectField::HIDDEN: o << "::"; break; - case ObjectField::VISIBLE: o << ":::"; break; - } - unparse(field.expr2, true); - - } break; - - case ObjectField::ASSERT: { - fill(field.fodder1, !first || space_before, true); - o << "assert"; - unparse(field.expr2, true); - if (field.expr3 != nullptr) { - fill(field.opFodder, true, true); - o << ":"; - unparse(field.expr3, true); - } - } break; - } - - first = false; - fill(field.commaFodder, false, false); - } - } - - /** Unparse the given AST. - * - * \param ast_ The AST to be unparsed. - * - * \param precedence The precedence of the enclosing AST. If this is greater than the current - * precedence, parens are not needed. - */ - void unparse(const AST *ast_, bool space_before) - { - bool separate_token = !left_recursive(ast_); - - fill(ast_->openFodder, space_before, separate_token); - - if (auto *ast = dynamic_cast<const Apply*>(ast_)) { - unparse(ast->target, space_before); - fill(ast->fodderL, false, false); - o << "("; - bool first = true; - for (const auto &arg : ast->args) { - if (!first) o << ','; - bool space = !first; - if (arg.id != nullptr) { - fill(arg.idFodder, space, true); - o << unparse_id(arg.id); - space = false; - o << "="; - } - unparse(arg.expr, space); - fill(arg.commaFodder, false, false); - first = false; - } - if (ast->trailingComma) o << ","; - fill(ast->fodderR, false, false); - o << ")"; - if (ast->tailstrict) { - fill(ast->tailstrictFodder, true, true); - o << "tailstrict"; - } - - } else if (auto *ast = dynamic_cast<const ApplyBrace*>(ast_)) { - unparse(ast->left, space_before); - unparse(ast->right, true); - - } else if (auto *ast = dynamic_cast<const Array*>(ast_)) { - o << "["; - bool first = true; - for (const auto &element : ast->elements) { - if (!first) o << ','; - unparse(element.expr, !first || opts.padArrays); - fill(element.commaFodder, false, false); - first = false; - } - if (ast->trailingComma) o << ","; - fill(ast->closeFodder, ast->elements.size() > 0, opts.padArrays); - o << "]"; - - } else if (auto *ast = dynamic_cast<const ArrayComprehension*>(ast_)) { - o << "["; - unparse(ast->body, opts.padArrays); - fill(ast->commaFodder, false, false); - if (ast->trailingComma) o << ","; - unparseSpecs(ast->specs); - fill(ast->closeFodder, true, opts.padArrays); - o << "]"; - - } else if (auto *ast = dynamic_cast<const Assert*>(ast_)) { - o << "assert"; - unparse(ast->cond, true); - if (ast->message != nullptr) { - fill(ast->colonFodder, true, true); - o << ":"; - unparse(ast->message, true); - } - fill(ast->semicolonFodder, false, false); - o << ";"; - unparse(ast->rest, true); - - } else if (auto *ast = dynamic_cast<const Binary*>(ast_)) { - unparse(ast->left, space_before); - fill(ast->opFodder, true, true); - o << bop_string(ast->op); - // The - 1 is for left associativity. - unparse(ast->right, true); - - } else if (auto *ast = dynamic_cast<const BuiltinFunction*>(ast_)) { - o << "/* builtin " << ast->name << " */ null"; - - } else if (auto *ast = dynamic_cast<const Conditional*>(ast_)) { - o << "if"; - unparse(ast->cond, true); - fill(ast->thenFodder, true, true); - o << "then"; - if (ast->branchFalse != nullptr) { - unparse(ast->branchTrue, true); - fill(ast->elseFodder, true, true); - o << "else"; - unparse(ast->branchFalse, true); - } else { - unparse(ast->branchTrue, true); - } - - } else if (dynamic_cast<const Dollar*>(ast_)) { - o << "$"; - - } else if (auto *ast = dynamic_cast<const Error*>(ast_)) { - o << "error"; - unparse(ast->expr, true); - - } else if (auto *ast = dynamic_cast<const Function*>(ast_)) { - o << "function"; - unparseParams(ast->parenLeftFodder, ast->params, ast->trailingComma, - ast->parenRightFodder); - unparse(ast->body, true); - - } else if (auto *ast = dynamic_cast<const Import*>(ast_)) { - o << "import"; - unparse(ast->file, true); - - } else if (auto *ast = dynamic_cast<const Importstr*>(ast_)) { - o << "importstr"; - unparse(ast->file, true); - - } else if (auto *ast = dynamic_cast<const InSuper*>(ast_)) { - unparse(ast->element, true); - fill(ast->inFodder, true, true); - o << "in"; - fill(ast->superFodder, true, true); - o << "super"; - - } else if (auto *ast = dynamic_cast<const Index*>(ast_)) { - unparse(ast->target, space_before); - fill(ast->dotFodder, false, false); - if (ast->id != nullptr) { - o << "."; - fill(ast->idFodder, false, false); - o << unparse_id(ast->id); - } else { - o << "["; - if (ast->isSlice) { - if (ast->index != nullptr) { - unparse(ast->index, false); - } - fill(ast->endColonFodder, false, false); - o << ":"; - if (ast->end != nullptr) { - unparse(ast->end, false); - } - if (ast->step != nullptr || ast->stepColonFodder.size() > 0) { - fill(ast->stepColonFodder, false, false); - o << ":"; - if (ast->step != nullptr) { - unparse(ast->step, false); - } - } - } else { - unparse(ast->index, false); - } - fill(ast->idFodder, false, false); - o << "]"; - } - - } else if (auto *ast = dynamic_cast<const Local*>(ast_)) { - o << "local"; - assert(ast->binds.size() > 0); - bool first = true; - for (const auto &bind : ast->binds) { - if (!first) - o << ","; - first = false; - fill(bind.varFodder, true, true); - o << unparse_id(bind.var); - if (bind.functionSugar) { - unparseParams(bind.parenLeftFodder, bind.params, bind.trailingComma, - bind.parenRightFodder); - } - fill(bind.opFodder, true, true); - o << "="; - unparse(bind.body, true); - fill(bind.closeFodder, false, false); - } - o << ";"; - unparse(ast->body, true); - - } else if (auto *ast = dynamic_cast<const LiteralBoolean*>(ast_)) { - o << (ast->value ? "true" : "false"); - - } else if (auto *ast = dynamic_cast<const LiteralNumber*>(ast_)) { - o << ast->originalString; - - } else if (auto *ast = dynamic_cast<const LiteralString*>(ast_)) { - if (ast->tokenKind == LiteralString::DOUBLE) { - o << "\""; - o << encode_utf8(ast->value); - o << "\""; - } else if (ast->tokenKind == LiteralString::SINGLE) { - o << "'"; - o << encode_utf8(ast->value); - o << "'"; - } else if (ast->tokenKind == LiteralString::BLOCK) { - o << "|||\n"; - if (ast->value.c_str()[0] != U'\n') - o << ast->blockIndent; - for (const char32_t *cp = ast->value.c_str() ; *cp != U'\0' ; ++cp) { - std::string utf8; - encode_utf8(*cp, utf8); - o << utf8; - if (*cp == U'\n' && *(cp + 1) != U'\n' && *(cp + 1) != U'\0') { - o << ast->blockIndent; - } - } - o << ast->blockTermIndent << "|||"; - } else if (ast->tokenKind == LiteralString::VERBATIM_DOUBLE) { - o << "@\""; - for (const char32_t *cp = ast->value.c_str() ; *cp != U'\0' ; ++cp) { - if (*cp == U'"') { - o << "\"\""; - } else { - std::string utf8; - encode_utf8(*cp, utf8); - o << utf8; - } - } - o << "\""; - } else if (ast->tokenKind == LiteralString::VERBATIM_SINGLE) { - o << "@'"; - for (const char32_t *cp = ast->value.c_str() ; *cp != U'\0' ; ++cp) { - if (*cp == U'\'') { - o << "''"; - } else { - std::string utf8; - encode_utf8(*cp, utf8); - o << utf8; - } - } - o << "'"; - } - - } else if (dynamic_cast<const LiteralNull*>(ast_)) { - o << "null"; - - } else if (auto *ast = dynamic_cast<const Object*>(ast_)) { - o << "{"; - unparseFields(ast->fields, opts.padObjects); - if (ast->trailingComma) o << ","; - fill(ast->closeFodder, ast->fields.size() > 0, opts.padObjects); - o << "}"; - - } else if (auto *ast = dynamic_cast<const DesugaredObject*>(ast_)) { - o << "{"; - for (AST *assert : ast->asserts) { - o << "assert"; - unparse(assert, true); - o << ","; - } - for (auto &field : ast->fields) { - o << "["; - unparse(field.name, false); - o << "]"; - switch (field.hide) { - case ObjectField::INHERIT: o << ":"; break; - case ObjectField::HIDDEN: o << "::"; break; - case ObjectField::VISIBLE: o << ":::"; break; - } - unparse(field.body, true); - o << ","; - } - o << "}"; - - } else if (auto *ast = dynamic_cast<const ObjectComprehension*>(ast_)) { - o << "{"; - unparseFields(ast->fields, opts.padObjects); - if (ast->trailingComma) o << ","; - unparseSpecs(ast->specs); - fill(ast->closeFodder, true, opts.padObjects); - o << "}"; - - } else if (auto *ast = dynamic_cast<const ObjectComprehensionSimple*>(ast_)) { - o << "{["; - unparse(ast->field, false); - o << "]:"; - unparse(ast->value, true); - o << " for " << unparse_id(ast->id) << " in"; - unparse(ast->array, true); - o << "}"; - - } else if (auto *ast = dynamic_cast<const Parens*>(ast_)) { - o << "("; - unparse(ast->expr, false); - fill(ast->closeFodder, false, false); - o << ")"; - - } else if (dynamic_cast<const Self*>(ast_)) { - o << "self"; - - } else if (auto *ast = dynamic_cast<const SuperIndex*>(ast_)) { - o << "super"; - fill(ast->dotFodder, false, false); - if (ast->id != nullptr) { - o << "."; - fill(ast->idFodder, false, false); - o << unparse_id(ast->id); - } else { - o << "["; - unparse(ast->index, false); - fill(ast->idFodder, false, false); - o << "]"; - } - - } else if (auto *ast = dynamic_cast<const Unary*>(ast_)) { - o << uop_string(ast->op); - if (dynamic_cast<const Dollar*>(left_recursive(ast->expr))) { - unparse(ast->expr, true); - } else { - unparse(ast->expr, false); - } - - } else if (auto *ast = dynamic_cast<const Var*>(ast_)) { - o << encode_utf8(ast->id->name); - - } else { - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; - std::abort(); - - } - } -}; - - -/******************************************************************************** - * The rest of this file contains transformations on the ASTs before unparsing. * - ********************************************************************************/ - -/** As a + b but preserves constraints. - * - * Namely, a LINE_END is not allowed to follow a PARAGRAPH or a LINE_END. - */ -static Fodder concat_fodder(const Fodder &a, const Fodder &b) -{ - if (a.size() == 0) return b; - if (b.size() == 0) return a; - Fodder r = a; - // Add the first element of b somehow. - if (r[a.size() - 1].kind != FodderElement::INTERSTITIAL && - b[0].kind == FodderElement::LINE_END) { - if (b[0].comment.size() > 0) { - // The line end had a comment, so create a single line paragraph for it. - r.emplace_back(FodderElement::PARAGRAPH, b[0].blanks, b[0].indent, b[0].comment); - } else { - // Merge it into the previous line end. - r[r.size() - 1].indent = b[0].indent; - r[r.size() - 1].blanks += b[0].blanks; - } - } else { - r.push_back(b[0]); - } - // Add the rest of b. - for (unsigned i = 1; i < b.size() ; ++i) { - r.push_back(b[i]); - } - return r; -} - -/** Move b to the front of a. */ -static void fodder_move_front(Fodder &a, Fodder &b) -{ - a = concat_fodder(b, a); - b.clear(); -} - -/** A generic Pass that does nothing but can be extended to easily define real passes. - */ -class FmtPass : public CompilerPass { - protected: - FmtOpts opts; - - public: - FmtPass(Allocator &alloc, const FmtOpts &opts) - : CompilerPass(alloc), opts(opts) { } -}; - - -class EnforceStringStyle : public FmtPass { - using FmtPass::visit; - public: - EnforceStringStyle(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - void visit(LiteralString *lit) - { - if (lit->tokenKind == LiteralString::BLOCK) return; - if (lit->tokenKind == LiteralString::VERBATIM_DOUBLE) return; - if (lit->tokenKind == LiteralString::VERBATIM_SINGLE) return; - UString canonical = jsonnet_string_unescape(lit->location, lit->value); - unsigned num_single = 0, num_double = 0; - for (char32_t c : canonical) { - if (c == '\'') num_single++; - if (c == '"') num_double++; - } - if (num_single > 0 && num_double > 0) return; // Don't change it. - bool use_single = opts.stringStyle == 's'; - if (num_single > 0) - use_single = false; - if (num_double > 0) - use_single = true; - - // Change it. - lit->value = jsonnet_string_escape(canonical, use_single); - lit->tokenKind = use_single ? LiteralString::SINGLE : LiteralString::DOUBLE; - } -}; - -class EnforceCommentStyle : public FmtPass { - public: - bool firstFodder; - EnforceCommentStyle(Allocator &alloc, const FmtOpts &opts) - : FmtPass(alloc, opts), firstFodder(true) - { } - /** Change the comment to match the given style, but don't break she-bang. - * - * If preserve_hash is true, do not touch a comment that starts with #!. - */ - void fixComment(std::string &s, bool preserve_hash) - { - if (opts.commentStyle == 'h' && s[0] == '/') { - s = "#" + s.substr(2); - } - if (opts.commentStyle == 's' && s[0] == '#') { - if (preserve_hash && s[1] == '!') return; - s = "//" + s.substr(1); - } - } - void fodder(Fodder &fodder) - { - for (auto &f : fodder) { - switch (f.kind) { - case FodderElement::LINE_END: - case FodderElement::PARAGRAPH: - if (f.comment.size() == 1) { - fixComment(f.comment[0], firstFodder); - } - break; - - case FodderElement::INTERSTITIAL: - break; - } - firstFodder = false; - } - } -}; - -class EnforceMaximumBlankLines : public FmtPass { - public: - EnforceMaximumBlankLines(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - void fodderElement(FodderElement &f) - { - if (f.kind != FodderElement::INTERSTITIAL) - if (f.blanks > 2) f.blanks = 2; - } -}; - -class StripComments : public FmtPass { - public: - StripComments(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - void fodder(Fodder &fodder) - { - Fodder copy = fodder; - fodder.clear(); - for (auto &f : copy) { - if (f.kind == FodderElement::LINE_END) - fodder.push_back(f); - } - } -}; - -class StripEverything : public FmtPass { - public: - StripEverything(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - void fodder(Fodder &fodder) { fodder.clear(); } -}; - -class StripAllButComments : public FmtPass { - public: - StripAllButComments(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - Fodder comments; - void fodder(Fodder &fodder) - { - for (auto &f : fodder) { - if (f.kind == FodderElement::PARAGRAPH) { - comments.emplace_back(FodderElement::PARAGRAPH, 0, 0, f.comment); - } else if (f.kind == FodderElement::INTERSTITIAL) { - comments.push_back(f); - comments.emplace_back(FodderElement::LINE_END, 0, 0, std::vector<std::string>{}); - } - } - fodder.clear(); - } - virtual void file(AST *&body, Fodder &final_fodder) - { - expr(body); - fodder(final_fodder); - body = alloc.make<LiteralNull>(body->location, comments); - final_fodder.clear(); - } -}; - -/** These cases are infix so we descend on the left to find the fodder. */ -static Fodder &open_fodder(AST *ast_) -{ - AST *left = left_recursive(ast_); - return left != nullptr ? open_fodder(left) : ast_->openFodder; -} - -/** Strip blank lines from the top of the file. */ -void remove_initial_newlines(AST *ast) -{ - Fodder &f = open_fodder(ast); - while (f.size() > 0 && f[0].kind == FodderElement::LINE_END) - f.erase(f.begin()); -} - -bool contains_newline(const Fodder &fodder) -{ - for (const auto &f : fodder) { - if (f.kind != FodderElement::INTERSTITIAL) - return true; - } - return false; -} - -/* Commas should appear at the end of an object/array only if the closing token is on a new line. */ -class FixTrailingCommas : public FmtPass { - using FmtPass::visit; - public: - FixTrailingCommas(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - Fodder comments; - - // Generalized fix that works across a range of ASTs. - void fix_comma(Fodder &last_comma_fodder, bool &trailing_comma, Fodder &close_fodder) - { - bool need_comma = contains_newline(close_fodder) || contains_newline(last_comma_fodder); - if (trailing_comma) { - if (!need_comma) { - // Remove it but keep fodder. - trailing_comma = false; - fodder_move_front(close_fodder, last_comma_fodder); - } else if (contains_newline(last_comma_fodder)) { - // The comma is needed but currently is separated by a newline. - fodder_move_front(close_fodder, last_comma_fodder); - } - } else { - if (need_comma) { - // There was no comma, but there was a newline before the ] so add a comma. - trailing_comma = true; - } - } - } - - void remove_comma(Fodder &last_comma_fodder, bool &trailing_comma, Fodder &close_fodder) - { - if (trailing_comma) { - // Remove it but keep fodder. - trailing_comma = false; - close_fodder = concat_fodder(last_comma_fodder, close_fodder); - last_comma_fodder.clear(); - } - } - - void visit(Array *expr) - { - if (expr->elements.size() == 0) { - // No comma present and none can be added. - return; - } - - fix_comma(expr->elements.back().commaFodder, expr->trailingComma, expr->closeFodder); - FmtPass::visit(expr); - } - - void visit(ArrayComprehension *expr) - { - remove_comma(expr->commaFodder, expr->trailingComma, expr->specs[0].openFodder); - FmtPass::visit(expr); - } - - void visit(Object *expr) - { - if (expr->fields.size() == 0) { - // No comma present and none can be added. - return; - } - - fix_comma(expr->fields.back().commaFodder, expr->trailingComma, expr->closeFodder); - FmtPass::visit(expr); - } - - void visit(ObjectComprehension *expr) - { - remove_comma(expr->fields.back().commaFodder, expr->trailingComma, expr->closeFodder); - FmtPass::visit(expr); - } - -}; - - -/* Remove nested parens. */ -class FixParens : public FmtPass { - using FmtPass::visit; - public: - FixParens(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - void visit(Parens *expr) - { - if (auto *body = dynamic_cast<Parens*>(expr->expr)) { - // Deal with fodder. - expr->expr = body->expr; - fodder_move_front(open_fodder(body->expr), body->openFodder); - fodder_move_front(expr->closeFodder, body->closeFodder); - } - FmtPass::visit(expr); - } -}; - - - -/* Ensure ApplyBrace syntax sugar is used in the case of A + { }. */ -class FixPlusObject : public FmtPass { - using FmtPass::visit; - public: - FixPlusObject(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - void visitExpr(AST *&expr) - { - if (auto *bin_op = dynamic_cast<Binary*>(expr)) { - // Could relax this to allow more ASTs on the LHS but this seems OK for now. - if (dynamic_cast<Var*>(bin_op->left) - || dynamic_cast<Index*>(bin_op->left)) { - if (AST *rhs = dynamic_cast<Object*>(bin_op->right)) { - if (bin_op->op == BOP_PLUS) { - fodder_move_front(rhs->openFodder, bin_op->opFodder); - expr = alloc.make<ApplyBrace>(bin_op->location, bin_op->openFodder, - bin_op->left, rhs); - } - } - } - } - FmtPass::visitExpr(expr); - } -}; - - - -/* Remove final colon in slices. */ -class NoRedundantSliceColon : public FmtPass { - using FmtPass::visit; - public: - NoRedundantSliceColon(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - - void visit(Index *expr) - { - if (expr->isSlice) { - if (expr->step == nullptr) { - if (expr->stepColonFodder.size() > 0) { - fodder_move_front(expr->idFodder, expr->stepColonFodder); - } - } - } - FmtPass::visit(expr); - } -}; - -/* Ensure syntax sugar is used where possible. */ -class PrettyFieldNames : public FmtPass { - using FmtPass::visit; - public: - PrettyFieldNames(Allocator &alloc, const FmtOpts &opts) : FmtPass(alloc, opts) { } - - bool isIdentifier(const UString &str) { - bool first = true; - for (char32_t c : str) { - if (!first && c >= '0' && c <= '9') - continue; - first = false; - if ((c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || (c == '_')) - continue; - return false; - } - // Filter out keywords. - if (lex_get_keyword_kind(encode_utf8(str)) != Token::IDENTIFIER) - return false; - return true; - } - - void visit(Index *expr) - { - if (!expr->isSlice && expr->index != nullptr) { - // Maybe we can use an id instead. - if (auto *lit = dynamic_cast<LiteralString*>(expr->index)) { - if (isIdentifier(lit->value)) { - expr->id = alloc.makeIdentifier(lit->value); - expr->idFodder = lit->openFodder; - expr->index = nullptr; - } - } - } - FmtPass::visit(expr); - } - - void visit(Object *expr) - { - for (auto &field : expr->fields) { - // First try ["foo"] -> "foo". - if (field.kind == ObjectField::FIELD_EXPR) { - if (auto *field_expr = dynamic_cast<LiteralString*>(field.expr1)) { - field.kind = ObjectField::FIELD_STR; - fodder_move_front(field_expr->openFodder, field.fodder1); - if (field.methodSugar) { - fodder_move_front(field.fodderL, field.fodder2); - } else { - fodder_move_front(field.opFodder, field.fodder2); - } - } - } - // Then try "foo" -> foo. - if (field.kind == ObjectField::FIELD_STR) { - if (auto *lit = dynamic_cast<LiteralString*>(field.expr1)) { - if (isIdentifier(lit->value)) { - field.kind = ObjectField::FIELD_ID; - field.id = alloc.makeIdentifier(lit->value); - field.fodder1 = lit->openFodder; - field.expr1 = nullptr; - } - } - } - } - FmtPass::visit(expr); - } -}; - -class FixIndentation { - - FmtOpts opts; - unsigned column; - - public: - FixIndentation(const FmtOpts &opts) : opts(opts), column(0) { } - - /* Set the indentation on the fodder elements, adjust column counter as if it was printed. - * \param fodder The fodder to pretend to print. - * \param space_before Whether a space should be printed before any other output. - * \param separate_token If the last fodder was an interstitial, whether a space should follow - * it. - * \param all_but_last_indent New indentation value for all but final fodder element. - * \param last_indent New indentation value for but final fodder element. - */ - void fill(Fodder &fodder, bool space_before, bool separate_token, - unsigned all_but_last_indent, unsigned last_indent) - { - setIndents(fodder, all_but_last_indent, last_indent); - fodder_count(column, fodder, space_before, separate_token); - } - - void fill(Fodder &fodder, bool space_before, bool separate_token, unsigned indent) - { - fill(fodder, space_before, separate_token, indent, indent); - } - - /* This struct is the representation of the indentation level. The field lineUp is what is - * generally used to indent after a new line. The field base is used to help derive a new - * Indent struct when the indentation level increases. lineUp is generally > base. - * - * In the following case (where spaces are replaced with underscores): - * ____foobar(1, - * ___________2) - * - * At the AST representing the 2, the indent has base == 4 and lineUp == 11. - */ - struct Indent { - unsigned base; - unsigned lineUp; - Indent(unsigned base, unsigned line_up) : base(base), lineUp(line_up) { } - }; - - /** Calculate the indentation of sub-expressions. - * - * If the first sub-expression is on the same line as the current node, then subsequent - * ones will be lined up, otherwise subsequent ones will be on the next line indented - * by 'indent'. - */ - Indent newIndent(const Fodder &first_fodder, const Indent &old, unsigned line_up) - { - if (first_fodder.size() == 0 || first_fodder[0].kind == FodderElement::INTERSTITIAL) { - return Indent(old.base, line_up); - } else { - // Reset - return Indent(old.base + opts.indent, old.base + opts.indent); - } - } - - /** Calculate the indentation of sub-expressions. - * - * If the first sub-expression is on the same line as the current node, then subsequent - * ones will be lined up and further indentations in their subexpressions will be based from - * this column. - */ - Indent newIndentStrong(const Fodder &first_fodder, const Indent &old, unsigned line_up) - { - if (first_fodder.size() == 0 || first_fodder[0].kind == FodderElement::INTERSTITIAL) { - return Indent(line_up, line_up); - } else { - // Reset - return Indent(old.base + opts.indent, old.base + opts.indent); - } - } - - /** Calculate the indentation of sub-expressions. - * - * If the first sub-expression is on the same line as the current node, then subsequent - * ones will be lined up, otherwise subseqeuent ones will be on the next line with no - * additional indent. - */ - Indent align(const Fodder &first_fodder, const Indent &old, unsigned line_up) - { - if (first_fodder.size() == 0 || first_fodder[0].kind == FodderElement::INTERSTITIAL) { - return Indent(old.base, line_up); - } else { - // Reset - return old; - } - } - - /** Calculate the indentation of sub-expressions. - * - * If the first sub-expression is on the same line as the current node, then subsequent - * ones will be lined up and further indentations in their subexpresssions will be based from - * this column. Otherwise, subseqeuent ones will be on the next line with no - * additional indent. - */ - Indent alignStrong(const Fodder &first_fodder, const Indent &old, unsigned line_up) - { - if (first_fodder.size() == 0 || first_fodder[0].kind == FodderElement::INTERSTITIAL) { - return Indent(line_up, line_up); - } else { - // Reset - return old; - } - } - - /* Set indentation values within the fodder elements. - * - * The last one gets a special indentation value, all the others are set to the same thing. - */ - void setIndents(Fodder &fodder, unsigned all_but_last_indent, unsigned last_indent) - { - // First count how many there are. - unsigned count = 0; - for (const auto &f : fodder) { - if (f.kind != FodderElement::INTERSTITIAL) - count++; - } - // Now set the indents. - unsigned i = 0; - for (auto &f : fodder) { - if (f.kind != FodderElement::INTERSTITIAL) { - if (i + 1 < count) { - f.indent = all_but_last_indent; - } else { - assert(i == count - 1); - f.indent = last_indent; - } - i++; - } - } - } - - /** Indent comprehension specs. - * \param indent The indentation level. - */ - void specs(std::vector<ComprehensionSpec> &specs, const Indent &indent) - { - for (auto &spec : specs) { - fill(spec.openFodder, true, true, indent.lineUp); - switch (spec.kind) { - case ComprehensionSpec::FOR: { - column += 3; // for - fill(spec.varFodder, true, true, indent.lineUp); - column += spec.var->name.length(); - fill(spec.inFodder, true, true, indent.lineUp); - column += 2; // in - Indent new_indent = newIndent(open_fodder(spec.expr), indent, column); - expr(spec.expr, new_indent, true); - } - break; - - case ComprehensionSpec::IF: { - column += 2; // if - Indent new_indent = newIndent(open_fodder(spec.expr), indent, column); - expr(spec.expr, new_indent, true); - } - break; - } - } - } - - void params(Fodder &fodder_l, ArgParams ¶ms, bool trailing_comma, Fodder &fodder_r, - const Indent &indent) - { - fill(fodder_l, false, false, indent.lineUp, indent.lineUp); - column++; // ( - const Fodder &first_inside = params.size() == 0 ? fodder_r : params[0].idFodder; - - Indent new_indent = newIndent(first_inside, indent, column); - bool first = true; - for (auto ¶m : params) { - if (!first) column++; // ',' - fill(param.idFodder, !first, true, new_indent.lineUp); - column += param.id->name.length(); - if (param.expr != nullptr) { - // default arg, no spacing: x=e - fill(param.eqFodder, false, false, new_indent.lineUp); - column++; - expr(param.expr, new_indent, false); - } - fill(param.commaFodder, false, false, new_indent.lineUp); - first = false; - } - if (trailing_comma) - column++; - fill(fodder_r, false, false, new_indent.lineUp, indent.lineUp); - column++; // ) - } - - void fieldParams(ObjectField &field, const Indent &indent) - { - if (field.methodSugar) { - params(field.fodderL, field.params, field.trailingComma, field.fodderR, indent); - } - } - - /** Indent fields within an object. - * - * \params fields - * \param indent Indent of the first field. - * \param space_before - */ - void fields(ObjectFields &fields, const Indent &indent, bool space_before) - { - unsigned new_indent = indent.lineUp; - bool first = true; - for (auto &field : fields) { - if (!first) column++; // ',' - - switch (field.kind) { - case ObjectField::LOCAL: { - - fill(field.fodder1, !first || space_before, true, indent.lineUp); - column += 5; // local - fill(field.fodder2, true, true, indent.lineUp); - column += field.id->name.length(); - fieldParams(field, indent); - fill(field.opFodder, true, true, indent.lineUp); - column++; // = - Indent new_indent2 = newIndent(open_fodder(field.expr2), indent, column); - expr(field.expr2, new_indent2, true); - } break; - - case ObjectField::FIELD_ID: - case ObjectField::FIELD_STR: - case ObjectField::FIELD_EXPR: { - - if (field.kind == ObjectField::FIELD_ID) { - fill(field.fodder1, !first || space_before, true, new_indent); - column += field.id->name.length(); - - } else if (field.kind == ObjectField::FIELD_STR) { - expr(field.expr1, indent, !first || space_before); - - } else if (field.kind == ObjectField::FIELD_EXPR) { - fill(field.fodder1, !first || space_before, true, new_indent); - column++; // [ - expr(field.expr1, indent, false); - fill(field.fodder2, false, false, new_indent); - column++; // ] - } - - fieldParams(field, indent); - - fill(field.opFodder, false, false, new_indent); - - if (field.superSugar) column++; - switch (field.hide) { - case ObjectField::INHERIT: column+=1; break; - case ObjectField::HIDDEN: column+=2; break; - case ObjectField::VISIBLE: column+=3; break; - } - Indent new_indent2 = newIndent(open_fodder(field.expr2), indent, column); - expr(field.expr2, new_indent2, true); - - } break; - - case ObjectField::ASSERT: { - - fill(field.fodder1, !first || space_before, true, new_indent); - column += 6; // assert - // + 1 for the space after the assert - Indent new_indent2 = newIndent(open_fodder(field.expr2), indent, column + 1); - expr(field.expr2, indent, true); - if (field.expr3 != nullptr) { - fill(field.opFodder, true, true, new_indent2.lineUp); - column++; // ":" - expr(field.expr3, new_indent2, true); - } - } break; - } - - first = false; - fill(field.commaFodder, false, false, new_indent); - } - } - - /** Does the given fodder contain at least one new line? */ - bool hasNewLines(const Fodder &fodder) - { - for (const auto &f : fodder) { - if (f.kind != FodderElement::INTERSTITIAL) - return true; - } - return false; - } - - /** Get the first fodder from an ArgParam. */ - const Fodder &argParamFirstFodder(const ArgParam &ap) - { - if (ap.id != nullptr) return ap.idFodder; - return open_fodder(ap.expr); - } - - /** Reindent an expression. - * - * \param ast_ The ast to reindent. - * \param indent Beginning of the line. - * \param space_before As defined in the pretty-printer. - */ - void expr(AST *ast_, const Indent &indent, bool space_before) - { - fill(ast_->openFodder, space_before, !left_recursive(ast_), indent.lineUp); - - if (auto *ast = dynamic_cast<Apply*>(ast_)) { - const Fodder &init_fodder = open_fodder(ast->target); - Indent new_indent = align(init_fodder, indent, - column + (space_before ? 1 : 0)); - expr(ast->target, new_indent, space_before); - fill(ast->fodderL, false, false, new_indent.lineUp); - column++; // ( - const Fodder &first_fodder = ast->args.size() == 0 - ? ast->fodderR : argParamFirstFodder(ast->args[0]); - bool strong_indent = false; - // Need to use strong indent if any of the - // arguments (except the first) are preceded by newlines. - bool first = true; - for (auto &arg : ast->args) { - if (first) { - // Skip first element. - first = false; - continue; - } - if (hasNewLines(argParamFirstFodder(arg))) - strong_indent = true; - } - - Indent arg_indent = strong_indent - ? newIndentStrong(first_fodder, indent, column) - : newIndent(first_fodder, indent, column); - first = true; - for (auto &arg : ast->args) { - if (!first) column++; // "," - - bool space = !first; - if (arg.id != nullptr) { - fill(arg.idFodder, space, false, arg_indent.lineUp); - column += arg.id->name.length(); - space = false; - column++; // "=" - } - expr(arg.expr, arg_indent, space); - fill(arg.commaFodder, false, false, arg_indent.lineUp); - first = false; - } - if (ast->trailingComma) column++; // "," - fill(ast->fodderR, false, false, arg_indent.lineUp, indent.base); - column++; // ) - if (ast->tailstrict) { - fill(ast->tailstrictFodder, true, true, indent.base); - column += 10; // tailstrict - } - - } else if (auto *ast = dynamic_cast<ApplyBrace*>(ast_)) { - const Fodder &init_fodder = open_fodder(ast->left); - Indent new_indent = align(init_fodder, indent, - column + (space_before ? 1 : 0)); - expr(ast->left, new_indent, space_before); - expr(ast->right, new_indent, true); - - } else if (auto *ast = dynamic_cast<Array*>(ast_)) { - column++; // '[' - // First fodder element exists and is a newline - const Fodder &first_fodder = ast->elements.size() > 0 - ? open_fodder(ast->elements[0].expr) - : ast->closeFodder; - unsigned new_column = column + (opts.padArrays ? 1 : 0); - bool strong_indent = false; - // Need to use strong indent if there are not newlines before any of the sub-expressions - bool first = true; - for (auto &el : ast->elements) { - if (first) { - first = false; - continue; - } - if (hasNewLines(open_fodder(el.expr))) - strong_indent = true; - } - - Indent new_indent = strong_indent - ? newIndentStrong(first_fodder, indent, new_column) - : newIndent(first_fodder, indent, new_column); - - first = true; - for (auto &element : ast->elements) { - if (!first) column++; - expr(element.expr, new_indent, !first || opts.padArrays); - fill(element.commaFodder, false, false, new_indent.lineUp, new_indent.lineUp); - first = false; - } - if (ast->trailingComma) column++; - - // Handle penultimate newlines from expr.close_fodder if there are any. - fill(ast->closeFodder, ast->elements.size() > 0, opts.padArrays, new_indent.lineUp, - indent.base); - column++; // ']' - - } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) { - column++; // [ - Indent new_indent = newIndent(open_fodder(ast->body), indent, - column + (opts.padArrays ? 1 : 0)); - expr(ast->body, new_indent, opts.padArrays); - fill(ast->commaFodder, false, false, new_indent.lineUp); - if (ast->trailingComma) column++; // ',' - specs(ast->specs, new_indent); - fill(ast->closeFodder, true, opts.padArrays, new_indent.lineUp, indent.base); - column++; // ] - - } else if (auto *ast = dynamic_cast<Assert*>(ast_)) { - column += 6; // assert - // + 1 for the space after the assert - Indent new_indent = newIndent(open_fodder(ast->cond), indent, column + 1); - expr(ast->cond, new_indent, true); - if (ast->message != nullptr) { - fill(ast->colonFodder, true, true, new_indent.lineUp); - column++; // ":" - expr(ast->message, new_indent, true); - } - fill(ast->semicolonFodder, false, false, new_indent.lineUp); - column++; // ";" - expr(ast->rest, indent, true); - - } else if (auto *ast = dynamic_cast<Binary*>(ast_)) { - const Fodder &first_fodder = open_fodder(ast->left); - - // Need to use strong indent in the case of - /* - A - + B - or - A + - B - */ - bool strong_indent = hasNewLines(ast->opFodder) || hasNewLines(open_fodder(ast->right)); - - unsigned inner_column = column + (space_before ? 1 : 0); - Indent new_indent = strong_indent - ? alignStrong(first_fodder, indent, inner_column) - : align(first_fodder, indent, inner_column); - expr(ast->left, new_indent, space_before); - fill(ast->opFodder, true, true, new_indent.lineUp); - column += bop_string(ast->op).length(); - // Don't calculate a new indent for here, because we like being able to do: - // true && - // true && - // true - expr(ast->right, new_indent, true); - - } else if (auto *ast = dynamic_cast<BuiltinFunction*>(ast_)) { - column += 11; // "/* builtin " - column += ast->name.length(); - column += 8; // " */ null" - - } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) { - column += 2; // if - Indent cond_indent = newIndent(open_fodder(ast->cond), indent, column + 1); - expr(ast->cond, cond_indent, true); - fill(ast->thenFodder, true, true, indent.base); - column += 4; // then - Indent true_indent = newIndent(open_fodder(ast->branchTrue), indent, column + 1); - expr(ast->branchTrue, true_indent, true); - if (ast->branchFalse != nullptr) { - fill(ast->elseFodder, true, true, indent.base); - column += 4; // else - Indent false_indent = newIndent(open_fodder(ast->branchFalse), indent, column + 1); - expr(ast->branchFalse, false_indent, true); - } - - } else if (dynamic_cast<Dollar*>(ast_)) { - column++; // $ - - } else if (auto *ast = dynamic_cast<Error*>(ast_)) { - column += 5; // error - Indent new_indent = newIndent(open_fodder(ast->expr), indent, column + 1); - expr(ast->expr, new_indent, true); - - } else if (auto *ast = dynamic_cast<Function*>(ast_)) { - column += 8; // function - params(ast->parenLeftFodder, ast->params, ast->trailingComma, - ast->parenRightFodder, indent); - Indent new_indent = newIndent(open_fodder(ast->body), indent, column + 1); - expr(ast->body, new_indent, true); - - } else if (auto *ast = dynamic_cast<Import*>(ast_)) { - column += 6; // import - Indent new_indent = newIndent(open_fodder(ast->file), indent, column + 1); - expr(ast->file, new_indent, true); - - } else if (auto *ast = dynamic_cast<Importstr*>(ast_)) { - column += 9; // importstr - Indent new_indent = newIndent(open_fodder(ast->file), indent, column + 1); - expr(ast->file, new_indent, true); - - } else if (auto *ast = dynamic_cast<InSuper*>(ast_)) { - expr(ast->element, indent, space_before); - fill(ast->inFodder, true, true, indent.lineUp); - column += 2; // in - fill(ast->superFodder, true, true, indent.lineUp); - column += 5; // super - - } else if (auto *ast = dynamic_cast<Index*>(ast_)) { - expr(ast->target, indent, space_before); - fill(ast->dotFodder, false, false, indent.lineUp); - if (ast->id != nullptr) { - Indent new_indent = newIndent(ast->idFodder, indent, column); - column++; // "." - fill(ast->idFodder, false, false, new_indent.lineUp); - column += ast->id->name.length(); - } else { - column++; // "[" - if (ast->isSlice) { - Indent new_indent(0, 0); - if (ast->index != nullptr) { - new_indent = newIndent(open_fodder(ast->index), indent, column); - expr(ast->index, new_indent, false); - } - if (ast->end != nullptr) { - new_indent = newIndent(ast->endColonFodder, indent, column); - fill(ast->endColonFodder, false, false, new_indent.lineUp); - column++; // ":" - expr(ast->end, new_indent, false); - } - if (ast->step != nullptr) { - if (ast->end == nullptr) { - new_indent = newIndent(ast->endColonFodder, indent, column); - fill(ast->endColonFodder, false, false, new_indent.lineUp); - column++; // ":" - } - fill(ast->stepColonFodder, false, false, new_indent.lineUp); - column++; // ":" - expr(ast->step, new_indent, false); - } - if (ast->index == nullptr && ast->end == nullptr && ast->step == nullptr) { - new_indent = newIndent(ast->endColonFodder, indent, column); - fill(ast->endColonFodder, false, false, new_indent.lineUp); - column++; // ":" - } - } else { - Indent new_indent = newIndent(open_fodder(ast->index), indent, column); - expr(ast->index, new_indent, false); - fill(ast->idFodder, false, false, new_indent.lineUp, indent.base); - } - column++; // "]" - } - - } else if (auto *ast = dynamic_cast<Local*>(ast_)) { - column += 5; // local - assert(ast->binds.size() > 0); - bool first = true; - Indent new_indent = newIndent(ast->binds[0].varFodder, indent, column + 1); - for (auto &bind : ast->binds) { - if (!first) - column++; // ',' - first = false; - fill(bind.varFodder, true, true, new_indent.lineUp); - column += bind.var->name.length(); - if (bind.functionSugar) { - params(bind.parenLeftFodder, bind.params, bind.trailingComma, - bind.parenRightFodder, new_indent); - } - fill(bind.opFodder, true, true, new_indent.lineUp); - column++; // '=' - Indent new_indent2 = newIndent(open_fodder(bind.body), new_indent, column + 1); - expr(bind.body, new_indent2, true); - fill(bind.closeFodder, false, false, new_indent2.lineUp, indent.base); - } - column++; // ';' - expr(ast->body, indent, true); - - } else if (auto *ast = dynamic_cast<LiteralBoolean*>(ast_)) { - column += (ast->value ? 4 : 5); - - } else if (auto *ast = dynamic_cast<LiteralNumber*>(ast_)) { - column += ast->originalString.length(); - - } else if (auto *ast = dynamic_cast<LiteralString*>(ast_)) { - if (ast->tokenKind == LiteralString::DOUBLE) { - column += 2 + ast->value.length(); // Include quotes - } else if (ast->tokenKind == LiteralString::SINGLE) { - column += 2 + ast->value.length(); // Include quotes - } else if (ast->tokenKind == LiteralString::BLOCK) { - ast->blockIndent = std::string(indent.base + opts.indent, ' '); - ast->blockTermIndent = std::string(indent.base, ' '); - column = indent.base; // blockTermIndent - column += 3; // "|||" - } else if (ast->tokenKind == LiteralString::VERBATIM_SINGLE) { - column += 3; // Include @, start and end quotes - for (const char32_t *cp = ast->value.c_str() ; *cp != U'\0' ; ++cp) { - if (*cp == U'\'') { - column += 2; - } else { - column += 1; - } - } - } else if (ast->tokenKind == LiteralString::VERBATIM_DOUBLE) { - column += 3; // Include @, start and end quotes - for (const char32_t *cp = ast->value.c_str() ; *cp != U'\0' ; ++cp) { - if (*cp == U'"') { - column += 2; - } else { - column += 1; - } - } - } - - } else if (dynamic_cast<LiteralNull*>(ast_)) { - column += 4; // null - - } else if (auto *ast = dynamic_cast<Object*>(ast_)) { - column++; // '{' - const Fodder &first_fodder = ast->fields.size() == 0 - ? ast->closeFodder - : ast->fields[0].kind == ObjectField::FIELD_STR - ? open_fodder(ast->fields[0].expr1) - : ast->fields[0].fodder1; - Indent new_indent = newIndent(first_fodder, indent, - column + (opts.padObjects ? 1 : 0)); - - fields(ast->fields, new_indent, opts.padObjects); - if (ast->trailingComma) column++; - fill(ast->closeFodder, ast->fields.size() > 0, opts.padObjects, - new_indent.lineUp, indent.base); - column++; // '}' - - } else if (auto *ast = dynamic_cast<DesugaredObject*>(ast_)) { - // No fodder but need to recurse and maintain column counter. - column++; // '{' - for (AST *assert : ast->asserts) { - column += 6; // assert - expr(assert, indent, true); - column++; // ',' - } - for (auto &field : ast->fields) { - column++; // '[' - expr(field.name, indent, false); - column++; // ']' - switch (field.hide) { - case ObjectField::INHERIT: column += 1; break; - case ObjectField::HIDDEN: column += 2; break; - case ObjectField::VISIBLE: column += 3; break; - } - expr(field.body, indent, true); - } - column++; // '}' - - } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) { - column++; // '{' - unsigned start_column = column; - const Fodder &first_fodder = ast->fields.size() == 0 - ? ast->closeFodder - : ast->fields[0].kind == ObjectField::FIELD_STR - ? open_fodder(ast->fields[0].expr1) - : ast->fields[0].fodder1; - Indent new_indent = newIndent(first_fodder, indent, - start_column + (opts.padObjects ? 1 : 0)); - - fields(ast->fields, new_indent, opts.padObjects); - if (ast->trailingComma) column++; // ',' - specs(ast->specs, new_indent); - fill(ast->closeFodder, true, opts.padObjects, new_indent.lineUp, indent.base); - column++; // '}' - - } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { - column++; // '{' - column++; // '[' - expr(ast->field, indent, false); - column++; // ']' - column++; // ':' - expr(ast->value, indent, true); - column += 5; // " for " - column += ast->id->name.length(); - column += 3; // " in" - expr(ast->array, indent, true); - column++; // '}' - - } else if (auto *ast = dynamic_cast<Parens*>(ast_)) { - column++; // ( - Indent new_indent = newIndentStrong(open_fodder(ast->expr), indent, column); - expr(ast->expr, new_indent, false); - fill(ast->closeFodder, false, false, new_indent.lineUp, indent.base); - column++; // ) - - } else if (dynamic_cast<const Self*>(ast_)) { - column += 4; // self - - } else if (auto *ast = dynamic_cast<SuperIndex*>(ast_)) { - column += 5; // super - fill(ast->dotFodder, false, false, indent.lineUp); - if (ast->id != nullptr) { - column++; // "."; - Indent new_indent = newIndent(ast->idFodder, indent, column); - fill(ast->idFodder, false, false, new_indent.lineUp); - column += ast->id->name.length(); - } else { - column++; // "["; - Indent new_indent = newIndent(open_fodder(ast->index), indent, column); - expr(ast->index, new_indent, false); - fill(ast->idFodder, false, false, new_indent.lineUp, indent.base); - column++; // "]"; - } - - } else if (auto *ast = dynamic_cast<Unary*>(ast_)) { - column += uop_string(ast->op).length(); - Indent new_indent = newIndent(open_fodder(ast->expr), indent, column); - expr(ast->expr, new_indent, false); - - } else if (auto *ast = dynamic_cast<Var*>(ast_)) { - column += ast->id->name.length(); - - } else { - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; - std::abort(); - - } - } - virtual void file(AST *body, Fodder &final_fodder) - { - expr(body, Indent(0, 0), false); - setIndents(final_fodder, 0, 0); - } -}; - - - -// TODO(dcunnin): Add pass to alphabeticize top level imports. - - -std::string jsonnet_fmt(AST *ast, Fodder &final_fodder, const FmtOpts &opts) -{ - Allocator alloc; - - // Passes to enforce style on the AST. - remove_initial_newlines(ast); - if (opts.maxBlankLines > 0) - EnforceMaximumBlankLines(alloc, opts).file(ast, final_fodder); - FixTrailingCommas(alloc, opts).file(ast, final_fodder); - FixParens(alloc, opts).file(ast, final_fodder); - FixPlusObject(alloc, opts).file(ast, final_fodder); - NoRedundantSliceColon(alloc, opts).file(ast, final_fodder); - if (opts.stripComments) - StripComments(alloc, opts).file(ast, final_fodder); - else if (opts.stripAllButComments) - StripAllButComments(alloc, opts).file(ast, final_fodder); - else if (opts.stripEverything) - StripEverything(alloc, opts).file(ast, final_fodder); - if (opts.prettyFieldNames) - PrettyFieldNames(alloc, opts).file(ast, final_fodder); - if (opts.stringStyle != 'l') - EnforceStringStyle(alloc, opts).file(ast, final_fodder); - if (opts.commentStyle != 'l') - EnforceCommentStyle(alloc, opts).file(ast, final_fodder); - if (opts.indent > 0) - FixIndentation(opts).file(ast, final_fodder); - - std::stringstream ss; - Unparser unparser(ss, opts); - unparser.unparse(ast, false); - unparser.fill(final_fodder, true, false); - return ss.str(); -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/formatter.h b/vendor/github.com/strickyak/jsonnet_cgo/formatter.h deleted file mode 100644 index a3a610b923751a5cdd43bbf6e5bd1cdc52023602..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/formatter.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_FORMATTER_H -#define JSONNET_FORMATTER_H - -#include "ast.h" - -struct FmtOpts { - char stringStyle; - char commentStyle; - unsigned indent; - unsigned maxBlankLines; - bool padArrays; - bool padObjects; - bool stripComments; - bool stripAllButComments; - bool stripEverything; - bool prettyFieldNames; - FmtOpts(void) - : stringStyle('l'), - commentStyle('l'), - indent(0), - maxBlankLines(2), - padArrays(false), - padObjects(true), - stripComments(false), - stripAllButComments(false), - stripEverything(false), - prettyFieldNames(true) - { } -}; - -/** The inverse of jsonnet_parse. - */ -std::string jsonnet_fmt(AST *ast, Fodder &final_fodder, const FmtOpts &opts); - -#endif // JSONNET_PARSER_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/json.h b/vendor/github.com/strickyak/jsonnet_cgo/json.h deleted file mode 100644 index d1c546308eab6987cac9a3922f33bd83b2dc6ce1..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/json.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_JSON_H -#define JSONNET_JSON_H - -#include <vector> -#include <memory> -#include <string> - -#include <libjsonnet.h> - -struct JsonnetJsonValue { - enum Kind { - ARRAY, - BOOL, - NULL_KIND, - NUMBER, - OBJECT, - STRING, - }; - Kind kind; - std::string string; - double number; // Also used for bool (0.0 and 1.0) - std::vector<std::unique_ptr<JsonnetJsonValue>> elements; - std::map<std::string, std::unique_ptr<JsonnetJsonValue>> fields; -}; - -#endif diff --git a/vendor/github.com/strickyak/jsonnet_cgo/jsonnet.go b/vendor/github.com/strickyak/jsonnet_cgo/jsonnet.go deleted file mode 100644 index 63c6280098bfb03ebdc2014499b5984594418e61..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/jsonnet.go +++ /dev/null @@ -1,493 +0,0 @@ -/* -jsonnet is a simple Go wrapper for the JSonnet VM. - -See http://jsonnet.org/ -*/ -package jsonnet - -// By Henry Strickland <@yak.net:strick> -// Made self-contained by Marko Mikulicic <mkm@bitnami.com> - -/* -#include <memory.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <libjsonnet.h> - -char *CallImport_cgo(void *ctx, const char *base, const char *rel, char **found_here, int *success); -struct JsonnetJsonValue *CallNative_cgo(void *ctx, const struct JsonnetJsonValue *const *argv, int *success); - -#cgo CXXFLAGS: -std=c++0x -O3 -*/ -import "C" - -import ( - "errors" - "fmt" - "reflect" - "runtime" - "sync" - "unsafe" -) - -type ImportCallback func(base, rel string) (result string, path string, err error) - -type NativeCallback func(args ...*JsonValue) (result *JsonValue, err error) - -type nativeFunc struct { - vm *VM - argc int - callback NativeCallback -} - -// Global registry of native functions. Cgo pointer rules don't allow -// us to pass go pointers directly (may not be stable), so pass uintptr -// keys into this indirect map instead. -var nativeFuncsMu sync.Mutex -var nativeFuncsIdx uintptr -var nativeFuncs = make(map[uintptr]*nativeFunc) - -func registerFunc(vm *VM, arity int, callback NativeCallback) uintptr { - f := nativeFunc{vm: vm, argc: arity, callback: callback} - - nativeFuncsMu.Lock() - defer nativeFuncsMu.Unlock() - - nativeFuncsIdx++ - for nativeFuncs[nativeFuncsIdx] != nil { - nativeFuncsIdx++ - } - - nativeFuncs[nativeFuncsIdx] = &f - return nativeFuncsIdx -} - -func getFunc(key uintptr) *nativeFunc { - nativeFuncsMu.Lock() - defer nativeFuncsMu.Unlock() - - return nativeFuncs[key] -} - -func unregisterFuncs(vm *VM) { - nativeFuncsMu.Lock() - defer nativeFuncsMu.Unlock() - - // This is inefficient if there are many - // simultaneously-existing VMs... - for idx, f := range nativeFuncs { - if f.vm == vm { - delete(nativeFuncs, idx) - } - } -} - -type VM struct { - guts *C.struct_JsonnetVm - importCallback ImportCallback -} - -//export go_call_native -func go_call_native(key uintptr, argv **C.struct_JsonnetJsonValue, okPtr *C.int) *C.struct_JsonnetJsonValue { - f := getFunc(key) - vm := f.vm - - goArgv := make([]*JsonValue, f.argc) - for i := 0; i < f.argc; i++ { - p := unsafe.Pointer(uintptr(unsafe.Pointer(argv)) + unsafe.Sizeof(*argv)*uintptr(i)) - argptr := (**C.struct_JsonnetJsonValue)(p) - // NB: argv will be freed by jsonnet after this - // function exits, so don't want (*JsonValue).destroy - // finalizer. - goArgv[i] = &JsonValue{ - vm: vm, - guts: *argptr, - } - } - - ret, err := f.callback(goArgv...) - if err != nil { - *okPtr = C.int(0) - ret = vm.NewString(err.Error()) - } else { - *okPtr = C.int(1) - } - - return ret.take() -} - -//export go_call_import -func go_call_import(vmPtr unsafe.Pointer, base, rel *C.char, pathPtr **C.char, okPtr *C.int) *C.char { - vm := (*VM)(vmPtr) - result, path, err := vm.importCallback(C.GoString(base), C.GoString(rel)) - if err != nil { - *okPtr = C.int(0) - return jsonnetString(vm, err.Error()) - } - *pathPtr = jsonnetString(vm, path) - *okPtr = C.int(1) - return jsonnetString(vm, result) -} - -// Evaluate a file containing Jsonnet code, return a JSON string. -func Version() string { - return C.GoString(C.jsonnet_version()) -} - -// Create a new Jsonnet virtual machine. -func Make() *VM { - vm := &VM{guts: C.jsonnet_make()} - return vm -} - -// Complement of Make(). -func (vm *VM) Destroy() { - unregisterFuncs(vm) - C.jsonnet_destroy(vm.guts) - vm.guts = nil -} - -// jsonnet often wants char* strings that were allocated via -// jsonnet_realloc. This function does that. -func jsonnetString(vm *VM, s string) *C.char { - clen := C.size_t(len(s)) + 1 // num bytes including trailing \0 - - // TODO: remove additional copy - cstr := C.CString(s) - defer C.free(unsafe.Pointer(cstr)) - - ret := C.jsonnet_realloc(vm.guts, nil, clen) - C.memcpy(unsafe.Pointer(ret), unsafe.Pointer(cstr), clen) - - return ret -} - -// Evaluate a file containing Jsonnet code, return a JSON string. -func (vm *VM) EvaluateFile(filename string) (string, error) { - var e C.int - z := C.GoString(C.jsonnet_evaluate_file(vm.guts, C.CString(filename), &e)) - if e != 0 { - return "", errors.New(z) - } - return z, nil -} - -// Evaluate a string containing Jsonnet code, return a JSON string. -func (vm *VM) EvaluateSnippet(filename, snippet string) (string, error) { - var e C.int - z := C.GoString(C.jsonnet_evaluate_snippet(vm.guts, C.CString(filename), C.CString(snippet), &e)) - if e != 0 { - return "", errors.New(z) - } - return z, nil -} - -// Format a file containing Jsonnet code, return a JSON string. -func (vm *VM) FormatFile(filename string) (string, error) { - var e C.int - z := C.GoString(C.jsonnet_fmt_file(vm.guts, C.CString(filename), &e)) - if e != 0 { - return "", errors.New(z) - } - return z, nil -} - -// Indentation level when reformatting (number of spaces) -func (vm *VM) FormatIndent(n int) { - C.jsonnet_fmt_indent(vm.guts, C.int(n)) -} - -// Format a string containing Jsonnet code, return a JSON string. -func (vm *VM) FormatSnippet(filename, snippet string) (string, error) { - var e C.int - z := C.GoString(C.jsonnet_fmt_snippet(vm.guts, C.CString(filename), C.CString(snippet), &e)) - if e != 0 { - return "", errors.New(z) - } - return z, nil -} - -// Override the callback used to locate imports. -func (vm *VM) ImportCallback(f ImportCallback) { - vm.importCallback = f - C.jsonnet_import_callback(vm.guts, (*C.JsonnetImportCallback)(unsafe.Pointer(C.CallImport_cgo)), unsafe.Pointer(vm)) -} - -// NativeCallback is a helper around NativeCallbackRaw that uses -// `reflect` to convert argument and result types to/from JsonValue. -// `f` is expected to be a function that takes argument types -// supported by `(*JsonValue).Extract` and returns `(x, error)` where -// `x` is a type supported by `NewJson`. -func (vm *VM) NativeCallback(name string, params []string, f interface{}) { - ty := reflect.TypeOf(f) - if ty.NumIn() != len(params) { - panic("Wrong number of parameters") - } - if ty.NumOut() != 2 { - panic("Wrong number of output parameters") - } - - wrapper := func(args ...*JsonValue) (*JsonValue, error) { - in := make([]reflect.Value, len(args)) - for i, arg := range args { - value := reflect.ValueOf(arg.Extract()) - if vty := value.Type(); !vty.ConvertibleTo(ty.In(i)) { - return nil, fmt.Errorf("parameter %d (type %s) cannot be converted to type %s", i, vty, ty.In(i)) - } - in[i] = value.Convert(ty.In(i)) - } - - out := reflect.ValueOf(f).Call(in) - - result := vm.NewJson(out[0].Interface()) - var err error - if out[1].IsValid() && !out[1].IsNil() { - err = out[1].Interface().(error) - } - return result, err - } - - vm.NativeCallbackRaw(name, params, wrapper) -} - -func (vm *VM) NativeCallbackRaw(name string, params []string, f NativeCallback) { - cname := C.CString(name) - defer C.free(unsafe.Pointer(cname)) - - // jsonnet expects this to be NULL-terminated, so the last - // element is left as nil - cparams := make([]*C.char, len(params)+1) - for i, param := range params { - cparams[i] = C.CString(param) - defer C.free(unsafe.Pointer(cparams[i])) - } - - key := registerFunc(vm, len(params), f) - C.jsonnet_native_callback(vm.guts, cname, (*C.JsonnetNativeCallback)(C.CallNative_cgo), unsafe.Pointer(key), (**C.char)(unsafe.Pointer(&cparams[0]))) -} - -// Bind a Jsonnet external var to the given value. -func (vm *VM) ExtVar(key, val string) { - C.jsonnet_ext_var(vm.guts, C.CString(key), C.CString(val)) -} - -// Bind a Jsonnet external var to the given Jsonnet code. -func (vm *VM) ExtCode(key, val string) { - C.jsonnet_ext_code(vm.guts, C.CString(key), C.CString(val)) -} - -// Bind a Jsonnet top-level argument to the given value. -func (vm *VM) TlaVar(key, val string) { - C.jsonnet_tla_var(vm.guts, C.CString(key), C.CString(val)) -} - -// Bind a Jsonnet top-level argument to the given Jsonnet code. -func (vm *VM) TlaCode(key, val string) { - C.jsonnet_tla_code(vm.guts, C.CString(key), C.CString(val)) -} - -// Set the maximum stack depth. -func (vm *VM) MaxStack(v uint) { - C.jsonnet_max_stack(vm.guts, C.uint(v)) -} - -// Set the number of lines of stack trace to display (0 for all of them). -func (vm *VM) MaxTrace(v uint) { - C.jsonnet_max_trace(vm.guts, C.uint(v)) -} - -// Set the number of objects required before a garbage collection cycle is allowed. -func (vm *VM) GcMinObjects(v uint) { - C.jsonnet_gc_min_objects(vm.guts, C.uint(v)) -} - -// Run the garbage collector after this amount of growth in the number of objects. -func (vm *VM) GcGrowthTrigger(v float64) { - C.jsonnet_gc_growth_trigger(vm.guts, C.double(v)) -} - -// Expect a string as output and don't JSON encode it. -func (vm *VM) StringOutput(v bool) { - if v { - C.jsonnet_string_output(vm.guts, C.int(1)) - } else { - C.jsonnet_string_output(vm.guts, C.int(0)) - } -} - -// Add to the default import callback's library search path. -func (vm *VM) JpathAdd(path string) { - C.jsonnet_jpath_add(vm.guts, C.CString(path)) -} - -/* The following are not implemented because they are trivial to implement in Go on top of the - * existing API by parsing and post-processing the JSON output by regular evaluation. - * - * jsonnet_evaluate_file_multi - * jsonnet_evaluate_snippet_multi - * jsonnet_evaluate_file_stream - * jsonnet_evaluate_snippet_stream - */ - -// JsonValue represents a jsonnet JSON object. -type JsonValue struct { - vm *VM - guts *C.struct_JsonnetJsonValue -} - -func (v *JsonValue) Extract() interface{} { - if x, ok := v.ExtractString(); ok { - return x - } - if x, ok := v.ExtractNumber(); ok { - return x - } - if x, ok := v.ExtractBool(); ok { - return x - } - if ok := v.ExtractNull(); ok { - return nil - } - panic("Unable to extract value") -} - -// ExtractString returns the string value and true if the value was a string -func (v *JsonValue) ExtractString() (string, bool) { - cstr := C.jsonnet_json_extract_string(v.vm.guts, v.guts) - if cstr == nil { - return "", false - } - return C.GoString(cstr), true -} - -func (v *JsonValue) ExtractNumber() (float64, bool) { - var ret C.double - ok := C.jsonnet_json_extract_number(v.vm.guts, v.guts, &ret) - return float64(ret), ok != 0 -} - -func (v *JsonValue) ExtractBool() (bool, bool) { - ret := C.jsonnet_json_extract_bool(v.vm.guts, v.guts) - switch ret { - case 0: - return false, true - case 1: - return true, true - case 2: - // Not a bool - return false, false - default: - panic("jsonnet_json_extract_number returned unexpected value") - } -} - -// ExtractNull returns true iff the value is null -func (v *JsonValue) ExtractNull() bool { - ret := C.jsonnet_json_extract_null(v.vm.guts, v.guts) - return ret != 0 -} - -func (vm *VM) newjson(ptr *C.struct_JsonnetJsonValue) *JsonValue { - v := &JsonValue{vm: vm, guts: ptr} - runtime.SetFinalizer(v, (*JsonValue).destroy) - return v -} - -func (v *JsonValue) destroy() { - if v.guts == nil { - return - } - C.jsonnet_json_destroy(v.vm.guts, v.guts) - v.guts = nil - runtime.SetFinalizer(v, nil) -} - -// Take ownership of the embedded ptr, effectively consuming the JsonValue -func (v *JsonValue) take() *C.struct_JsonnetJsonValue { - ptr := v.guts - if ptr == nil { - panic("taking nil pointer from JsonValue") - } - v.guts = nil - runtime.SetFinalizer(v, nil) - return ptr -} - -func (vm *VM) NewJson(value interface{}) *JsonValue { - switch val := value.(type) { - case string: - return vm.NewString(val) - case int: - return vm.NewNumber(float64(val)) - case float64: - return vm.NewNumber(val) - case bool: - return vm.NewBool(val) - case nil: - return vm.NewNull() - case []interface{}: - a := vm.NewArray() - for _, v := range val { - a.ArrayAppend(vm.NewJson(v)) - } - return a - case map[string]interface{}: - o := vm.NewObject() - for k, v := range val { - o.ObjectAppend(k, vm.NewJson(v)) - } - return o - default: - panic(fmt.Sprintf("NewJson can't handle type: %T", value)) - } -} - -func (vm *VM) NewString(v string) *JsonValue { - cstr := C.CString(v) - defer C.free(unsafe.Pointer(cstr)) - ptr := C.jsonnet_json_make_string(vm.guts, cstr) - return vm.newjson(ptr) -} - -func (vm *VM) NewNumber(v float64) *JsonValue { - ptr := C.jsonnet_json_make_number(vm.guts, C.double(v)) - return vm.newjson(ptr) -} - -func (vm *VM) NewBool(v bool) *JsonValue { - var i C.int - if v { - i = 1 - } else { - i = 0 - } - ptr := C.jsonnet_json_make_bool(vm.guts, i) - return vm.newjson(ptr) -} - -func (vm *VM) NewNull() *JsonValue { - ptr := C.jsonnet_json_make_null(vm.guts) - return vm.newjson(ptr) -} - -func (vm *VM) NewArray() *JsonValue { - ptr := C.jsonnet_json_make_array(vm.guts) - return vm.newjson(ptr) -} - -func (v *JsonValue) ArrayAppend(item *JsonValue) { - C.jsonnet_json_array_append(v.vm.guts, v.guts, item.take()) -} - -func (vm *VM) NewObject() *JsonValue { - ptr := C.jsonnet_json_make_object(vm.guts) - return vm.newjson(ptr) -} - -func (v *JsonValue) ObjectAppend(key string, value *JsonValue) { - ckey := C.CString(key) - defer C.free(unsafe.Pointer(ckey)) - - C.jsonnet_json_object_append(v.vm.guts, v.guts, ckey, value.take()) -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/lexer.cpp b/vendor/github.com/strickyak/jsonnet_cgo/lexer.cpp deleted file mode 100644 index 89b48a3ced4fce856e0c7074a6fee1215cd3b561..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/lexer.cpp +++ /dev/null @@ -1,810 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <cassert> - -#include <map> -#include <string> -#include <sstream> - -#include "lexer.h" -#include "static_error.h" -#include "unicode.h" - -static const std::vector<std::string> EMPTY; - -/** Strip whitespace from both ends of a string, but only up to margin on the left hand side. */ -static std::string strip_ws(const std::string &s, unsigned margin) -{ - if (s.size() == 0) return s; // Avoid underflow below. - size_t i = 0; - while (i < s.length() && (s[i] == ' ' || s[i] == '\t' || s[i] == '\r') && i < margin) - i++; - size_t j = s.size(); - while (j > i && (s[j - 1] == ' ' || s[j - 1] == '\t' || s[j - 1] == '\r')) { - j--; - } - return std::string(&s[i], &s[j]); -} - -/** Split a string by \n and also strip left (up to margin) & right whitespace from each line. */ -static std::vector<std::string> line_split(const std::string &s, unsigned margin) -{ - std::vector<std::string> ret; - std::stringstream ss; - for (size_t i=0 ; i<s.length() ; ++i) { - if (s[i] == '\n') { - ret.emplace_back(strip_ws(ss.str(), margin)); - ss.str(""); - } else { - ss << s[i]; - } - } - ret.emplace_back(strip_ws(ss.str(), margin)); - return ret; -} - - - -/** Consume whitespace. - * - * Return number of \n and number of spaces after last \n. Convert \t to spaces. - */ -static void lex_ws(const char *&c, unsigned &new_lines, unsigned &indent, const char *&line_start, - unsigned long &line_number) -{ - indent = 0; - new_lines = 0; - for (; *c != '\0' && (*c == ' ' || *c == '\n' || *c == '\t' || *c == '\r'); c++) { - switch (*c) { - case '\r': - // Ignore. - break; - - case '\n': - indent = 0; - new_lines++; - line_number++; - line_start = c + 1; - break; - - case ' ': - indent += 1; - break; - - // This only works for \t at the beginning of lines, but we strip it everywhere else - // anyway. The only case where this will cause a problem is spaces followed by \t - // at the beginning of a line. However that is rare, ill-advised, and if re-indentation - // is enabled it will be fixed later. - case '\t': - indent += 8; - break; - } - } -} - - -/** -# Consume all text until the end of the line, return number of newlines after that and indent -*/ -static void lex_until_newline(const char *&c, std::string &text, unsigned &blanks, unsigned &indent, - const char *&line_start, unsigned long &line_number) -{ - const char *original_c = c; - const char *last_non_space = c; - for (; *c != '\0' && *c != '\n'; c++) { - if (*c != ' ' && *c != '\t' && *c != '\r') - last_non_space = c; - } - text = std::string(original_c, last_non_space - original_c + 1); - // Consume subsequent whitespace including the '\n'. - unsigned new_lines; - lex_ws(c, new_lines, indent, line_start, line_number); - blanks = new_lines == 0 ? 0 : new_lines - 1; -} - -static bool is_upper(char c) -{ - return c >= 'A' && c <= 'Z'; -} - -static bool is_lower(char c) -{ - return c >= 'a' && c <= 'z'; -} - -static bool is_number(char c) -{ - return c >= '0' && c <= '9'; -} - -static bool is_identifier_first(char c) -{ - return is_upper(c) || is_lower(c) || c == '_'; -} - -static bool is_identifier(char c) -{ - return is_identifier_first(c) || is_number(c); -} - -static bool is_symbol(char c) -{ - switch (c) { - case '!': case '$': case ':': - case '~': case '+': case '-': - case '&': case '|': case '^': - case '=': case '<': case '>': - case '*': case '/': case '%': - return true; - } - return false; -} - -static const std::map<std::string, Token::Kind> keywords = { - {"assert", Token::ASSERT}, - {"else", Token::ELSE}, - {"error", Token::ERROR}, - {"false", Token::FALSE}, - {"for", Token::FOR}, - {"function", Token::FUNCTION}, - {"if", Token::IF}, - {"import", Token::IMPORT}, - {"importstr", Token::IMPORTSTR}, - {"in", Token::IN}, - {"local", Token::LOCAL}, - {"null", Token::NULL_LIT}, - {"self", Token::SELF}, - {"super", Token::SUPER}, - {"tailstrict", Token::TAILSTRICT}, - {"then", Token::THEN}, - {"true", Token::TRUE}, -}; - -Token::Kind lex_get_keyword_kind(const std::string &identifier) -{ - auto it = keywords.find(identifier); - if (it == keywords.end()) return Token::IDENTIFIER; - return it->second; -} - -std::string lex_number(const char *&c, const std::string &filename, const Location &begin) -{ - // This function should be understood with reference to the linked image: - // http://www.json.org/number.gif - - // Note, we deviate from the json.org documentation as follows: - // There is no reason to lex negative numbers as atomic tokens, it is better to parse them - // as a unary operator combined with a numeric literal. This avoids x-1 being tokenized as - // <identifier> <number> instead of the intended <identifier> <binop> <number>. - - enum State { - BEGIN, - AFTER_ZERO, - AFTER_ONE_TO_NINE, - AFTER_DOT, - AFTER_DIGIT, - AFTER_E, - AFTER_EXP_SIGN, - AFTER_EXP_DIGIT - } state; - - std::string r; - - state = BEGIN; - while (true) { - switch (state) { - case BEGIN: - switch (*c) { - case '0': - state = AFTER_ZERO; - break; - - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_ONE_TO_NINE; - break; - - default: - throw StaticError(filename, begin, "Couldn't lex number"); - } - break; - - case AFTER_ZERO: - switch (*c) { - case '.': - state = AFTER_DOT; - break; - - case 'e': case 'E': - state = AFTER_E; - break; - - default: - goto end; - } - break; - - case AFTER_ONE_TO_NINE: - switch (*c) { - case '.': - state = AFTER_DOT; - break; - - case 'e': case 'E': - state = AFTER_E; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_ONE_TO_NINE; - break; - - default: - goto end; - } - break; - - case AFTER_DOT: - switch (*c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_DIGIT; - break; - - default: { - std::stringstream ss; - ss << "Couldn't lex number, junk after decimal point: " << *c; - throw StaticError(filename, begin, ss.str()); - } - } - break; - - case AFTER_DIGIT: - switch (*c) { - case 'e': case 'E': - state = AFTER_E; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_DIGIT; - break; - - default: - goto end; - } - break; - - case AFTER_E: - switch (*c) { - case '+': case '-': - state = AFTER_EXP_SIGN; - break; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_EXP_DIGIT; - break; - - default: { - std::stringstream ss; - ss << "Couldn't lex number, junk after 'E': " << *c; - throw StaticError(filename, begin, ss.str()); - } - } - break; - - case AFTER_EXP_SIGN: - switch (*c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_EXP_DIGIT; - break; - - default: { - std::stringstream ss; - ss << "Couldn't lex number, junk after exponent sign: " << *c; - throw StaticError(filename, begin, ss.str()); - } - } - break; - - case AFTER_EXP_DIGIT: - switch (*c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - state = AFTER_EXP_DIGIT; - break; - - default: - goto end; - } - break; - } - r += *c; - c++; - } - end: - return r; -} - -// Check that b has at least the same whitespace prefix as a and returns the amount of this -// whitespace, otherwise returns 0. If a has no whitespace prefix than return 0. -static int whitespace_check(const char *a, const char *b) -{ - int i = 0; - while (a[i] == ' ' || a[i] == '\t') { - if (b[i] != a[i]) return 0; - i++; - } - return i; -} - -/* -static void add_whitespace(Fodder &fodder, const char *s, size_t n) -{ - std::string ws(s, n); - if (fodder.size() == 0 || fodder.back().kind != FodderElement::WHITESPACE) { - fodder.emplace_back(FodderElement::WHITESPACE, ws); - } else { - fodder.back().data += ws; - } -} -*/ - -Tokens jsonnet_lex(const std::string &filename, const char *input) -{ - unsigned long line_number = 1; - const char *line_start = input; - - Tokens r; - - const char *c = input; - - Fodder fodder; - bool fresh_line = true; // Are we tokenizing from the beginning of a new line? - - while (*c!='\0') { - - // Used to ensure we have actually advanced the pointer by the end of the iteration. - const char *original_c = c; - - Token::Kind kind; - std::string data; - std::string string_block_indent; - std::string string_block_term_indent; - - unsigned new_lines, indent; - lex_ws(c, new_lines, indent, line_start, line_number); - - // If it's the end of the file, discard final whitespace. - if (*c == '\0') - break; - - if (new_lines > 0) { - // Otherwise store whitespace in fodder. - unsigned blanks = new_lines - 1; - fodder.emplace_back(FodderElement::LINE_END, blanks, indent, EMPTY); - fresh_line = true; - } - - Location begin(line_number, c - line_start + 1); - - switch (*c) { - - // The following operators should never be combined with subsequent symbols. - case '{': - kind = Token::BRACE_L; - c++; - break; - - case '}': - kind = Token::BRACE_R; - c++; - break; - - case '[': - kind = Token::BRACKET_L; - c++; - break; - - case ']': - kind = Token::BRACKET_R; - c++; - break; - - case ',': - kind = Token::COMMA; - c++; - break; - - case '.': - kind = Token::DOT; - c++; - break; - - case '(': - kind = Token::PAREN_L; - c++; - break; - - case ')': - kind = Token::PAREN_R; - c++; - break; - - case ';': - kind = Token::SEMICOLON; - c++; - break; - - // Numeric literals. - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - kind = Token::NUMBER; - data = lex_number(c, filename, begin); - break; - - // UString literals. - case '"': { - c++; - for (; ; ++c) { - if (*c == '\0') { - throw StaticError(filename, begin, "Unterminated string"); - } - if (*c == '"') { - break; - } - if (*c == '\\' && *(c+1) != '\0') { - data += *c; - ++c; - } - if (*c == '\n') { - // Maintain line/column counters. - line_number++; - line_start = c+1; - } - data += *c; - } - c++; // Advance beyond the ". - kind = Token::STRING_DOUBLE; - } - break; - - // UString literals. - case '\'': { - c++; - for (; ; ++c) { - if (*c == '\0') { - throw StaticError(filename, begin, "Unterminated string"); - } - if (*c == '\'') { - break; - } - if (*c == '\\' && *(c+1) != '\0') { - data += *c; - ++c; - } - if (*c == '\n') { - // Maintain line/column counters. - line_number++; - line_start = c+1; - } - data += *c; - } - c++; // Advance beyond the '. - kind = Token::STRING_SINGLE; - } - break; - - // Verbatim string literals. - // ' and " quoting is interpreted here, unlike non-verbatim strings - // where it is done later by jsonnet_string_unescape. This is OK - // in this case because no information is lost by resoving the - // repeated quote into a single quote, so we can go back to the - // original form in the formatter. - case '@': { - c++; - if (*c != '"' && *c != '\'') { - std::stringstream ss; - ss << "Couldn't lex verbatim string, junk after '@': " << *c; - throw StaticError(filename, begin, ss.str()); - } - const char quot = *c; - c++; // Advance beyond the opening quote. - for (; ; ++c) { - if (*c == '\0') { - throw StaticError(filename, begin, "Unterminated verbatim string"); - } - if (*c == quot) { - if (*(c+1) == quot) { - c++; - } else { - break; - } - } - data += *c; - } - c++; // Advance beyond the closing quote. - if (quot == '"') { - kind = Token::VERBATIM_STRING_DOUBLE; - } else { - kind = Token::VERBATIM_STRING_SINGLE; - } - } - break; - - // Keywords - default: - if (is_identifier_first(*c)) { - std::string id; - for (; is_identifier(*c); ++c) - id += *c; - kind = lex_get_keyword_kind(id); - data = id; - - } else if (is_symbol(*c) || *c == '#') { - - // Single line C++ and Python style comments. - if (*c == '#' || (*c == '/' && *(c+1) == '/')) { - std::vector<std::string> comment(1); - unsigned blanks; - unsigned indent; - lex_until_newline(c, comment[0], blanks, indent, line_start, line_number); - auto kind = fresh_line ? FodderElement::PARAGRAPH : FodderElement::LINE_END; - fodder.emplace_back(kind, blanks, indent, comment); - fresh_line = true; - continue; // We've not got a token, just fodder, so keep scanning. - } - - // Multi-line C style comment. - if (*c == '/' && *(c+1) == '*') { - - unsigned margin = c - line_start; - - const char *initial_c = c; - c += 2; // Avoid matching /*/: skip the /* before starting the search for */. - - while (!(*c == '*' && *(c+1) == '/')) { - if (*c == '\0') { - auto msg = "Multi-line comment has no terminating */."; - throw StaticError(filename, begin, msg); - } - if (*c == '\n') { - // Just keep track of the line / column counters. - line_number++; - line_start = c+1; - } - ++c; - } - c += 2; // Move the pointer to the char after the closing '/'. - - std::string comment(initial_c, c - initial_c); // Includes the "/*" and "*/". - - // Lex whitespace after comment - unsigned new_lines_after, indent_after; - lex_ws(c, new_lines_after, indent_after, line_start, line_number); - std::vector<std::string> lines; - if (comment.find('\n') >= comment.length()) { - // Comment looks like /* foo */ - lines.push_back(comment); - fodder.emplace_back(FodderElement::INTERSTITIAL, 0, 0, lines); - if (new_lines_after > 0) { - fodder.emplace_back(FodderElement::LINE_END, new_lines_after - 1, - indent_after, EMPTY); - fresh_line = true; - } - } else { - lines = line_split(comment, margin); - assert(lines[0][0] == '/'); - // Little hack to support PARAGRAPHs with * down the LHS: - // Add a space to lines that start with a '*' - bool all_star = true; - for (auto &l : lines) { - if (l[0] != '*') - all_star = false; - } - if (all_star) { - for (auto &l : lines) { - if (l[0] == '*') l = " " + l; - } - } - if (new_lines_after == 0) { - // Ensure a line end after the paragraph. - new_lines_after = 1; - indent_after = 0; - } - if (!fresh_line) - // Ensure a line end before the comment. - fodder.emplace_back(FodderElement::LINE_END, 0, 0, EMPTY); - fodder.emplace_back(FodderElement::PARAGRAPH, new_lines_after - 1, - indent_after, lines); - fresh_line = true; - } - continue; // We've not got a token, just fodder, so keep scanning. - } - - // Text block - if (*c == '|' && *(c+1) == '|' && *(c+2) == '|') { - if (*(c+3) != '\n') { - auto msg = "Text block syntax requires new line after |||."; - throw StaticError(filename, begin, msg); - } - std::stringstream block; - c += 4; // Skip the "|||\n" - line_number++; - // Skip any blank lines at the beginning of the block. - while (*c == '\n') { - line_number++; - ++c; - block << '\n'; - } - line_start = c; - const char *first_line = c; - int ws_chars = whitespace_check(first_line, c); - string_block_indent = std::string(first_line, ws_chars); - if (ws_chars == 0) { - auto msg = "Text block's first line must start with whitespace."; - throw StaticError(filename, begin, msg); - } - while (true) { - assert(ws_chars > 0); - // Read up to the \n - for (c = &c[ws_chars]; *c != '\n' ; ++c) { - if (*c == '\0') - throw StaticError(filename, begin, "Unexpected EOF"); - block << *c; - } - // Add the \n - block << '\n'; - ++c; - line_number++; - line_start = c; - // Skip any blank lines - while (*c == '\n') { - line_number++; - ++c; - block << '\n'; - } - // Examine next line - ws_chars = whitespace_check(first_line, c); - if (ws_chars == 0) { - // End of text block - // Skip over any whitespace - while (*c == ' ' || *c == '\t') { - string_block_term_indent += *c; - ++c; - } - // Expect ||| - if (!(*c == '|' && *(c+1) == '|' && *(c+2) == '|')) { - auto msg = "Text block not terminated with |||"; - throw StaticError(filename, begin, msg); - } - c += 3; // Leave after the last | - data = block.str(); - kind = Token::STRING_BLOCK; - break; // Out of the while loop. - } - } - - break; // Out of the switch. - } - - const char *operator_begin = c; - for (; is_symbol(*c) ; ++c) { - // Not allowed // in operators - if (*c == '/' && *(c+1) == '/') break; - // Not allowed /* in operators - if (*c == '/' && *(c+1) == '*') break; - // Not allowed ||| in operators - if (*c == '|' && *(c+1) == '|' && *(c+2) == '|') break; - } - // Not allowed to end with a + - ~ ! unless a single char. - // So, wind it back if we need to (but not too far). - while (c > operator_begin + 1 - && (*(c-1) == '+' || *(c-1) == '-' || *(c-1) == '~' || *(c-1) == '!')) { - c--; - } - data += std::string(operator_begin, c); - if (data == "$") { - kind = Token::DOLLAR; - data = ""; - } else { - kind = Token::OPERATOR; - } - } else { - std::stringstream ss; - ss << "Could not lex the character "; - auto uc = (unsigned char)(*c); - if (*c < 32) - ss << "code " << unsigned(uc); - else - ss << "'" << *c << "'"; - throw StaticError(filename, begin, ss.str()); - } - } - - // Ensure that a bug in the above code does not cause an infinite memory consuming loop due - // to pushing empty tokens. - if (c == original_c) { - throw StaticError(filename, begin, "Internal lexing error: Pointer did not advance"); - } - - Location end(line_number, c - line_start); - r.emplace_back(kind, fodder, data, string_block_indent, string_block_term_indent, - LocationRange(filename, begin, end)); - fodder.clear(); - fresh_line = false; - } - - Location end(line_number, c - line_start + 1); - r.emplace_back(Token::END_OF_FILE, fodder, "", "", "", LocationRange(filename, end, end)); - return r; -} - -std::string jsonnet_unlex(const Tokens &tokens) -{ - std::stringstream ss; - for (const auto &t : tokens) { - for (const auto &f : t.fodder) { - switch (f.kind) { - case FodderElement::LINE_END: { - if (f.comment.size() > 0) { - ss << "LineEnd(" << f.blanks << ", " << f.indent << ", " - << f.comment[0] << ")\n"; - } else { - ss << "LineEnd(" << f.blanks << ", " << f.indent << ")\n"; - } - } break; - - case FodderElement::INTERSTITIAL: { - ss << "Interstitial(" << f.comment[0] << ")\n"; - } break; - - case FodderElement::PARAGRAPH: { - ss << "Paragraph(\n"; - for (const auto &line : f.comment) { - ss << " " << line << '\n'; - } - ss << ")\n"; - } break; - } - } - if (t.kind == Token::END_OF_FILE) { - ss << "EOF\n"; - break; - } - if (t.kind == Token::STRING_DOUBLE) { - ss << "\"" << t.data << "\"\n"; - } else if (t.kind == Token::STRING_SINGLE) { - ss << "'" << t.data << "'\n"; - } else if (t.kind == Token::STRING_BLOCK) { - ss << "|||\n"; - ss << t.stringBlockIndent; - for (const char *cp = t.data.c_str() ; *cp != '\0' ; ++cp) { - ss << *cp; - if (*cp == '\n' && *(cp + 1) != '\n' && *(cp + 1) != '\0') { - ss << t.stringBlockIndent; - } - } - ss << t.stringBlockTermIndent << "|||\n"; - } else { - ss << t.data << "\n"; - } - } - return ss.str(); -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/lexer.h b/vendor/github.com/strickyak/jsonnet_cgo/lexer.h deleted file mode 100644 index 05176143f319392c64ec5d3e3e80a9c140d8c899..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/lexer.h +++ /dev/null @@ -1,250 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_LEXER_H -#define JSONNET_LEXER_H - -#include <cstdlib> -#include <cassert> - -#include <iostream> -#include <string> -#include <list> -#include <sstream> -#include <vector> - -#include "unicode.h" -#include "static_error.h" - -/** Whitespace and comments. - * - * "Fodder" (as in cannon fodder) implies this data is expendable. - */ -struct FodderElement { - enum Kind { - LINE_END, - INTERSTITIAL, - PARAGRAPH, - }; - Kind kind; - unsigned blanks; - unsigned indent; - std::vector<std::string> comment; - FodderElement(Kind kind, unsigned blanks, unsigned indent, - const std::vector<std::string> &comment) - : kind(kind), blanks(blanks), indent(indent), comment(comment) - { - assert(kind != LINE_END || comment.size() <= 1); - assert(kind != INTERSTITIAL || (blanks == 0 && indent == 0 && comment.size() == 1)); - assert(kind != PARAGRAPH || comment.size() >= 1); - } -}; -static inline std::ostream &operator<<(std::ostream &o, const FodderElement &f) -{ - switch (f.kind) { - case FodderElement::LINE_END: - o << "END(" << f.blanks << ", " << f.indent << ", " << f.comment[0] << ")"; - break; - case FodderElement::INTERSTITIAL: - o << "INT(" << f.blanks << ", " << f.indent << ", " << f.comment[0] << ")"; - break; - case FodderElement::PARAGRAPH: - o << "PAR(" << f.blanks << ", " << f.indent << ", " << f.comment[0] << "...)"; - break; - } - return o; -} -typedef std::vector<FodderElement> Fodder; - -static inline std::ostream &operator<<(std::ostream &o, const Fodder &fodder) -{ - bool first = true; - for (const auto &f : fodder) { - o << (first ? "[" : ", "); - first = false; - o << f; - } - o << (first ? "[]" : "]"); - return o; -} - -struct Token { - enum Kind { - // Symbols - BRACE_L, - BRACE_R, - BRACKET_L, - BRACKET_R, - COMMA, - DOLLAR, - DOT, - PAREN_L, - PAREN_R, - SEMICOLON, - - // Arbitrary length lexemes - IDENTIFIER, - NUMBER, - OPERATOR, - STRING_DOUBLE, - STRING_SINGLE, - STRING_BLOCK, - VERBATIM_STRING_SINGLE, - VERBATIM_STRING_DOUBLE, - - // Keywords - ASSERT, - ELSE, - ERROR, - FALSE, - FOR, - FUNCTION, - IF, - IMPORT, - IMPORTSTR, - IN, - LOCAL, - NULL_LIT, - TAILSTRICT, - THEN, - SELF, - SUPER, - TRUE, - - // A special token that holds line/column information about the end of the file. - END_OF_FILE - } kind; - - /** Fodder before this token. */ - Fodder fodder; - - /** Content of the token if it wasn't a keyword. */ - std::string data; - - /** If kind == STRING_BLOCK then stores the sequence of whitespace that indented the block. */ - std::string stringBlockIndent; - - /** If kind == STRING_BLOCK then stores the sequence of whitespace that indented the end of - * the block. - * - * This is always fewer whitespace characters than in stringBlockIndent. - */ - std::string stringBlockTermIndent; - - UString data32(void) { return decode_utf8(data); } - - LocationRange location; - - Token(Kind kind, const Fodder &fodder, const std::string &data, - const std::string &string_block_indent, const std::string &string_block_term_indent, - const LocationRange &location) - : kind(kind), fodder(fodder), data(data), stringBlockIndent(string_block_indent), - stringBlockTermIndent(string_block_term_indent), location(location) - { } - - Token(Kind kind, const std::string &data="") - : kind(kind), data(data) { } - - static const char *toString(Kind v) - { - switch (v) { - case BRACE_L: return "\"{\""; - case BRACE_R: return "\"}\""; - case BRACKET_L: return "\"[\""; - case BRACKET_R: return "\"]\""; - case COMMA: return "\",\""; - case DOLLAR: return "\"$\""; - case DOT: return "\".\""; - - case PAREN_L: return "\"(\""; - case PAREN_R: return "\")\""; - case SEMICOLON: return "\";\""; - - case IDENTIFIER: return "IDENTIFIER"; - case NUMBER: return "NUMBER"; - case OPERATOR: return "OPERATOR"; - case STRING_SINGLE: return "STRING_SINGLE"; - case STRING_DOUBLE: return "STRING_DOUBLE"; - case VERBATIM_STRING_SINGLE: return "VERBATIM_STRING_SINGLE"; - case VERBATIM_STRING_DOUBLE: return "VERBATIM_STRING_DOUBLE"; - case STRING_BLOCK: return "STRING_BLOCK"; - - case ASSERT: return "assert"; - case ELSE: return "else"; - case ERROR: return "error"; - case FALSE: return "false"; - case FOR: return "for"; - case FUNCTION: return "function"; - case IF: return "if"; - case IMPORT: return "import"; - case IMPORTSTR: return "importstr"; - case IN: return "in"; - case LOCAL: return "local"; - case NULL_LIT: return "null"; - case SELF: return "self"; - case SUPER: return "super"; - case TAILSTRICT: return "tailstrict"; - case THEN: return "then"; - case TRUE: return "true"; - - case END_OF_FILE: return "end of file"; - default: - std::cerr << "INTERNAL ERROR: Unknown token kind: " << v << std::endl; - std::abort(); - } - } -}; - -/** The result of lexing. - * - * Because of the EOF token, this will always contain at least one token. So element 0 can be used - * to get the filename. - */ -typedef std::list<Token> Tokens; - -static inline bool operator==(const Token &a, const Token &b) -{ - if (a.kind != b.kind) return false; - if (a.data != b.data) return false; - return true; -} - -static inline std::ostream &operator<<(std::ostream &o, Token::Kind v) -{ - o << Token::toString(v); - return o; -} - -static inline std::ostream &operator<<(std::ostream &o, const Token &v) -{ - if (v.data == "") { - o << Token::toString(v.kind); - } else if (v.kind == Token::OPERATOR) { - o << "\"" << v.data << "\""; - } else { - o << "(" << Token::toString(v.kind) << ", \"" << v.data << "\")"; - } - return o; -} - -/** IF the given identifier is a keyword, return its kind, otherwise return IDENTIFIER. */ -Token::Kind lex_get_keyword_kind(const std::string &identifier); - -Tokens jsonnet_lex(const std::string &filename, const char *input); - -std::string jsonnet_unlex(const Tokens &tokens); - -#endif // JSONNET_LEXER_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/libjsonnet.cpp b/vendor/github.com/strickyak/jsonnet_cgo/libjsonnet.cpp deleted file mode 100644 index abe97c33c64b70c7612fb0aa999de662c54837b3..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/libjsonnet.cpp +++ /dev/null @@ -1,673 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <cstdlib> -#include <cstring> -#include <cerrno> - -#include <exception> -#include <fstream> -#include <iostream> -#include <sstream> -#include <string> - -extern "C" { -#include "libjsonnet.h" -} - -#include "desugarer.h" -#include "formatter.h" -#include "json.h" -#include "parser.h" -#include "static_analysis.h" -#include "vm.h" - -static void memory_panic(void) -{ - fputs("FATAL ERROR: A memory allocation error occurred.\n", stderr); - abort(); -} - -static char *from_string(JsonnetVm* vm, const std::string &v) -{ - char *r = jsonnet_realloc(vm, nullptr, v.length() + 1); - std::strcpy(r, v.c_str()); - return r; -} - -static char *default_import_callback(void *ctx, const char *dir, const char *file, - char **found_here_cptr, int *success); - -const char *jsonnet_json_extract_string(JsonnetVm *vm, const struct JsonnetJsonValue *v) -{ - (void) vm; - if (v->kind != JsonnetJsonValue::STRING) - return nullptr; - return v->string.c_str(); -} - -int jsonnet_json_extract_number(struct JsonnetVm *vm, const struct JsonnetJsonValue *v, double *out) -{ - (void) vm; - if (v->kind != JsonnetJsonValue::NUMBER) - return 0; - *out = v->number; - return 1; -} - -int jsonnet_json_extract_bool(struct JsonnetVm *vm, const struct JsonnetJsonValue *v) -{ - (void) vm; - if (v->kind != JsonnetJsonValue::BOOL) return 2; - return v->number != 0; -} - -int jsonnet_json_extract_null(struct JsonnetVm *vm, const struct JsonnetJsonValue *v) -{ - (void) vm; - return v->kind == JsonnetJsonValue::NULL_KIND; -} - -JsonnetJsonValue *jsonnet_json_make_string(JsonnetVm *vm, const char *v) -{ - (void) vm; - JsonnetJsonValue *r = new JsonnetJsonValue(); - r->kind = JsonnetJsonValue::STRING; - r->string = v; - return r; -} - -JsonnetJsonValue *jsonnet_json_make_number(struct JsonnetVm *vm, double v) -{ - (void) vm; - JsonnetJsonValue *r = new JsonnetJsonValue(); - r->kind = JsonnetJsonValue::NUMBER; - r->number = v; - return r; -} - -JsonnetJsonValue *jsonnet_json_make_bool(struct JsonnetVm *vm, int v) -{ - (void) vm; - JsonnetJsonValue *r = new JsonnetJsonValue(); - r->kind = JsonnetJsonValue::BOOL; - r->number = v != 0; - return r; -} - -JsonnetJsonValue *jsonnet_json_make_null(struct JsonnetVm *vm) -{ - (void) vm; - JsonnetJsonValue *r = new JsonnetJsonValue(); - r->kind = JsonnetJsonValue::NULL_KIND; - return r; -} - -JsonnetJsonValue *jsonnet_json_make_array(JsonnetVm *vm) -{ - (void) vm; - JsonnetJsonValue *r = new JsonnetJsonValue(); - r->kind = JsonnetJsonValue::ARRAY; - return r; -} - -void jsonnet_json_array_append(JsonnetVm *vm, JsonnetJsonValue *arr, JsonnetJsonValue *v) -{ - (void) vm; - assert(arr->kind == JsonnetJsonValue::ARRAY); - arr->elements.emplace_back(v); -} - -JsonnetJsonValue *jsonnet_json_make_object(JsonnetVm *vm) -{ - (void) vm; - JsonnetJsonValue *r = new JsonnetJsonValue(); - r->kind = JsonnetJsonValue::OBJECT; - return r; -} - -void jsonnet_json_object_append(JsonnetVm *vm, JsonnetJsonValue *obj, - const char *f, JsonnetJsonValue *v) -{ - (void) vm; - assert(obj->kind == JsonnetJsonValue::OBJECT); - obj->fields[std::string(f)] = std::unique_ptr<JsonnetJsonValue>(v); -} - -void jsonnet_json_destroy(JsonnetVm *vm, JsonnetJsonValue *v) -{ - (void) vm; - delete v; -} - -struct JsonnetVm { - double gcGrowthTrigger; - unsigned maxStack; - unsigned gcMinObjects; - unsigned maxTrace; - std::map<std::string, VmExt> ext; - std::map<std::string, VmExt> tla; - JsonnetImportCallback *importCallback; - VmNativeCallbackMap nativeCallbacks; - void *importCallbackContext; - bool stringOutput; - std::vector<std::string> jpaths; - - FmtOpts fmtOpts; - bool fmtDebugDesugaring; - - JsonnetVm(void) - : gcGrowthTrigger(2.0), maxStack(500), gcMinObjects(1000), maxTrace(20), - importCallback(default_import_callback), importCallbackContext(this), stringOutput(false), - fmtDebugDesugaring(false) - { - jpaths.emplace_back("/usr/share/" + std::string(jsonnet_version()) + "/"); - jpaths.emplace_back("/usr/local/share/" + std::string(jsonnet_version()) + "/"); - } -}; - -enum ImportStatus { - IMPORT_STATUS_OK, - IMPORT_STATUS_FILE_NOT_FOUND, - IMPORT_STATUS_IO_ERROR -}; - -static enum ImportStatus try_path(const std::string &dir, const std::string &rel, - std::string &content, std::string &found_here, - std::string &err_msg) -{ - std::string abs_path; - if (rel.length() == 0) { - err_msg = "The empty string is not a valid filename"; - return IMPORT_STATUS_IO_ERROR; - } - // It is possible that rel is actually absolute. - if (rel[0] == '/') { - abs_path = rel; - } else { - abs_path = dir + rel; - } - - if (abs_path[abs_path.length() - 1] == '/') { - err_msg = "Attempted to import a directory"; - return IMPORT_STATUS_IO_ERROR; - } - - std::ifstream f; - f.open(abs_path.c_str()); - if (!f.good()) return IMPORT_STATUS_FILE_NOT_FOUND; - try { - content.assign(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()); - } catch (const std::ios_base::failure &io_err) { - err_msg = io_err.what(); - return IMPORT_STATUS_IO_ERROR; - } - if (!f.good()) { - err_msg = strerror(errno); - return IMPORT_STATUS_IO_ERROR; - } - - found_here = abs_path; - - return IMPORT_STATUS_OK; -} - -static char *default_import_callback(void *ctx, const char *dir, const char *file, - char **found_here_cptr, int *success) -{ - auto *vm = static_cast<JsonnetVm*>(ctx); - - std::string input, found_here, err_msg; - - ImportStatus status = try_path(dir, file, input, found_here, err_msg); - - std::vector<std::string> jpaths(vm->jpaths); - - // If not found, try library search path. - while (status == IMPORT_STATUS_FILE_NOT_FOUND) { - if (jpaths.size() == 0) { - *success = 0; - const char *err = "No match locally or in the Jsonnet library paths."; - char *r = jsonnet_realloc(vm, nullptr, std::strlen(err) + 1); - std::strcpy(r, err); - return r; - } - status = try_path(jpaths.back(), file, input, found_here, err_msg); - jpaths.pop_back(); - } - - if (status == IMPORT_STATUS_IO_ERROR) { - *success = 0; - return from_string(vm, err_msg); - } else { - assert(status == IMPORT_STATUS_OK); - *success = 1; - *found_here_cptr = from_string(vm, found_here); - return from_string(vm, input); - } -} - -#define TRY try { -#define CATCH(func) \ - } catch (const std::bad_alloc &) {\ - memory_panic(); \ - } catch (const std::exception &e) {\ - std::cerr << "Something went wrong during " func ", please report this: " \ - << e.what() << std::endl; \ - abort(); \ - } - -const char *jsonnet_version(void) -{ - return LIB_JSONNET_VERSION; -} - -JsonnetVm *jsonnet_make(void) -{ - TRY - return new JsonnetVm(); - CATCH("jsonnet_make") - return nullptr; -} - -void jsonnet_destroy(JsonnetVm *vm) -{ - TRY - delete vm; - CATCH("jsonnet_destroy") -} - -void jsonnet_max_stack(JsonnetVm *vm, unsigned v) -{ - vm->maxStack = v; -} - -void jsonnet_gc_min_objects(JsonnetVm *vm, unsigned v) -{ - vm->gcMinObjects = v; -} - -void jsonnet_gc_growth_trigger(JsonnetVm *vm, double v) -{ - vm->gcGrowthTrigger = v; -} - -void jsonnet_string_output(struct JsonnetVm *vm, int v) -{ - vm->stringOutput = bool(v); -} - -void jsonnet_import_callback(struct JsonnetVm *vm, JsonnetImportCallback *cb, void *ctx) -{ - vm->importCallback = cb; - vm->importCallbackContext = ctx; -} - -void jsonnet_native_callback(struct JsonnetVm *vm, const char *name, JsonnetNativeCallback *cb, - void *ctx, const char * const *params) -{ - std::vector<std::string> params2; - for (; *params != nullptr; params++) - params2.push_back(*params); - vm->nativeCallbacks[name] = VmNativeCallback {cb, ctx, params2}; -} - - -void jsonnet_ext_var(JsonnetVm *vm, const char *key, const char *val) -{ - vm->ext[key] = VmExt(val, false); -} - -void jsonnet_ext_code(JsonnetVm *vm, const char *key, const char *val) -{ - vm->ext[key] = VmExt(val, true); -} - -void jsonnet_tla_var(JsonnetVm *vm, const char *key, const char *val) -{ - vm->tla[key] = VmExt(val, false); -} - -void jsonnet_tla_code(JsonnetVm *vm, const char *key, const char *val) -{ - vm->tla[key] = VmExt(val, true); -} - -void jsonnet_fmt_debug_desugaring(JsonnetVm *vm, int v) -{ - vm->fmtDebugDesugaring = v; -} - -void jsonnet_fmt_indent(JsonnetVm *vm, int v) -{ - vm->fmtOpts.indent = v; -} - -void jsonnet_fmt_max_blank_lines(JsonnetVm *vm, int v) -{ - vm->fmtOpts.maxBlankLines = v; -} - -void jsonnet_fmt_string(JsonnetVm *vm, int v) -{ - if (v != 'd' && v != 's' && v != 'l') - v = 'l'; - vm->fmtOpts.stringStyle = v; -} - -void jsonnet_fmt_comment(JsonnetVm *vm, int v) -{ - if (v != 'h' && v != 's' && v != 'l') - v = 'l'; - vm->fmtOpts.commentStyle = v; -} - -void jsonnet_fmt_pad_arrays(JsonnetVm *vm, int v) -{ - vm->fmtOpts.padArrays = v; -} - -void jsonnet_fmt_pad_objects(JsonnetVm *vm, int v) -{ - vm->fmtOpts.padObjects = v; -} - -void jsonnet_fmt_pretty_field_names(JsonnetVm *vm, int v) -{ - vm->fmtOpts.prettyFieldNames = v; -} - -void jsonnet_max_trace(JsonnetVm *vm, unsigned v) -{ - vm->maxTrace = v; -} - -void jsonnet_jpath_add(JsonnetVm *vm, const char *path_) -{ - if (std::strlen(path_) == 0) return; - std::string path = path_; - if (path[path.length() - 1] != '/') path += '/'; - vm->jpaths.emplace_back(path); -} - -static char *jsonnet_fmt_snippet_aux(JsonnetVm *vm, const char *filename, const char *snippet, - int *error) -{ - try { - Allocator alloc; - std::string json_str; - AST *expr; - std::map<std::string, std::string> files; - Tokens tokens = jsonnet_lex(filename, snippet); - - // std::cout << jsonnet_unlex(tokens); - - expr = jsonnet_parse(&alloc, tokens); - Fodder final_fodder = tokens.front().fodder; - - if (vm->fmtDebugDesugaring) - jsonnet_desugar(&alloc, expr, &vm->tla); - - json_str = jsonnet_fmt(expr, final_fodder, vm->fmtOpts); - - json_str += "\n"; - - *error = false; - return from_string(vm, json_str); - - } catch (StaticError &e) { - std::stringstream ss; - ss << "STATIC ERROR: " << e << std::endl; - *error = true; - return from_string(vm, ss.str()); - } - -} - -char *jsonnet_fmt_file(JsonnetVm *vm, const char *filename, int *error) -{ - TRY - std::ifstream f; - f.open(filename); - if (!f.good()) { - std::stringstream ss; - ss << "Opening input file: " << filename << ": " << strerror(errno); - *error = true; - return from_string(vm, ss.str()); - } - std::string input; - input.assign(std::istreambuf_iterator<char>(f), - std::istreambuf_iterator<char>()); - - return jsonnet_fmt_snippet_aux(vm, filename, input.c_str(), error); - CATCH("jsonnet_fmt_file") - return nullptr; // Never happens. -} - -char *jsonnet_fmt_snippet(JsonnetVm *vm, const char *filename, const char *snippet, int *error) -{ - TRY - return jsonnet_fmt_snippet_aux(vm, filename, snippet, error); - CATCH("jsonnet_fmt_snippet") - return nullptr; // Never happens. -} - - -namespace { -enum EvalKind { REGULAR, MULTI, STREAM }; -} // namespace - -static char *jsonnet_evaluate_snippet_aux(JsonnetVm *vm, const char *filename, - const char *snippet, int *error, EvalKind kind) -{ - try { - Allocator alloc; - AST *expr; - Tokens tokens = jsonnet_lex(filename, snippet); - - expr = jsonnet_parse(&alloc, tokens); - - jsonnet_desugar(&alloc, expr, &vm->tla); - - jsonnet_static_analysis(expr); - switch (kind) { - case REGULAR: { - std::string json_str = jsonnet_vm_execute( - &alloc, expr, vm->ext, vm->maxStack, vm->gcMinObjects, - vm->gcGrowthTrigger, vm->nativeCallbacks, vm->importCallback, - vm->importCallbackContext, vm->stringOutput); - json_str += "\n"; - *error = false; - return from_string(vm, json_str); - } - break; - - case MULTI: { - std::map<std::string, std::string> files = jsonnet_vm_execute_multi( - &alloc, expr, vm->ext, vm->maxStack, vm->gcMinObjects, - vm->gcGrowthTrigger, vm->nativeCallbacks, vm->importCallback, - vm->importCallbackContext, vm->stringOutput); - size_t sz = 1; // final sentinel - for (const auto &pair : files) { - sz += pair.first.length() + 1; // include sentinel - sz += pair.second.length() + 2; // Add a '\n' as well as sentinel - } - char *buf = (char*)::malloc(sz); - if (buf == nullptr) memory_panic(); - std::ptrdiff_t i = 0; - for (const auto &pair : files) { - memcpy(&buf[i], pair.first.c_str(), pair.first.length() + 1); - i += pair.first.length() + 1; - memcpy(&buf[i], pair.second.c_str(), pair.second.length()); - i += pair.second.length(); - buf[i] = '\n'; - i++; - buf[i] = '\0'; - i++; - } - buf[i] = '\0'; // final sentinel - *error = false; - return buf; - } - break; - - case STREAM: { - std::vector<std::string> documents = jsonnet_vm_execute_stream( - &alloc, expr, vm->ext, vm->maxStack, vm->gcMinObjects, - vm->gcGrowthTrigger, vm->nativeCallbacks, vm->importCallback, - vm->importCallbackContext); - size_t sz = 1; // final sentinel - for (const auto &doc : documents) { - sz += doc.length() + 2; // Add a '\n' as well as sentinel - } - char *buf = (char*)::malloc(sz); - if (buf == nullptr) memory_panic(); - std::ptrdiff_t i = 0; - for (const auto &doc : documents) { - memcpy(&buf[i], doc.c_str(), doc.length()); - i += doc.length(); - buf[i] = '\n'; - i++; - buf[i] = '\0'; - i++; - } - buf[i] = '\0'; // final sentinel - *error = false; - return buf; - } - break; - - default: - fputs("INTERNAL ERROR: bad value of 'kind', probably memory corruption.\n", stderr); - abort(); - } - - } catch (StaticError &e) { - std::stringstream ss; - ss << "STATIC ERROR: " << e << std::endl; - *error = true; - return from_string(vm, ss.str()); - - } catch (RuntimeError &e) { - std::stringstream ss; - ss << "RUNTIME ERROR: " << e.msg << std::endl; - const long max_above = vm->maxTrace / 2; - const long max_below = vm->maxTrace - max_above; - const long sz = e.stackTrace.size(); - for (long i = 0 ; i < sz ; ++i) { - const auto &f = e.stackTrace[i]; - if (vm->maxTrace > 0 && i >= max_above && i < sz - max_below) { - if (i == max_above) - ss << "\t..." << std::endl; - } else { - ss << "\t" << f.location << "\t" << f.name << std::endl; - } - } - *error = true; - return from_string(vm, ss.str()); - } - - return nullptr; // Quiet, compiler. -} - -static char *jsonnet_evaluate_file_aux(JsonnetVm *vm, const char *filename, int *error, - EvalKind kind) -{ - std::ifstream f; - f.open(filename); - if (!f.good()) { - std::stringstream ss; - ss << "Opening input file: " << filename << ": " << strerror(errno); - *error = true; - return from_string(vm, ss.str()); - } - std::string input; - input.assign(std::istreambuf_iterator<char>(f), - std::istreambuf_iterator<char>()); - - return jsonnet_evaluate_snippet_aux(vm, filename, input.c_str(), error, kind); -} - -char *jsonnet_evaluate_file(JsonnetVm *vm, const char *filename, int *error) -{ - TRY - return jsonnet_evaluate_file_aux(vm, filename, error, REGULAR); - CATCH("jsonnet_evaluate_file") - return nullptr; // Never happens. -} - -char *jsonnet_evaluate_file_multi(JsonnetVm *vm, const char *filename, int *error) -{ - TRY - return jsonnet_evaluate_file_aux(vm, filename, error, MULTI); - CATCH("jsonnet_evaluate_file_multi") - return nullptr; // Never happens. -} - -char *jsonnet_evaluate_file_stream(JsonnetVm *vm, const char *filename, int *error) -{ - TRY - return jsonnet_evaluate_file_aux(vm, filename, error, STREAM); - CATCH("jsonnet_evaluate_file_stream") - return nullptr; // Never happens. -} - -char *jsonnet_evaluate_snippet(JsonnetVm *vm, const char *filename, const char *snippet, int *error) -{ - TRY - return jsonnet_evaluate_snippet_aux(vm, filename, snippet, error, REGULAR); - CATCH("jsonnet_evaluate_snippet") - return nullptr; // Never happens. -} - -char *jsonnet_evaluate_snippet_multi(JsonnetVm *vm, const char *filename, - const char *snippet, int *error) -{ - TRY - return jsonnet_evaluate_snippet_aux(vm, filename, snippet, error, MULTI); - CATCH("jsonnet_evaluate_snippet_multi") - return nullptr; // Never happens. -} - -char *jsonnet_evaluate_snippet_stream(JsonnetVm *vm, const char *filename, - const char *snippet, int *error) -{ - TRY - return jsonnet_evaluate_snippet_aux(vm, filename, snippet, error, STREAM); - CATCH("jsonnet_evaluate_snippet_stream") - return nullptr; // Never happens. -} - -char *jsonnet_realloc(JsonnetVm *vm, char *str, size_t sz) -{ - (void) vm; - if (str == nullptr) { - if (sz == 0) return nullptr; - auto *r = static_cast<char*>(::malloc(sz)); - if (r == nullptr) memory_panic(); - return r; - } else { - if (sz == 0) { - ::free(str); - return nullptr; - } else { - auto *r = static_cast<char*>(::realloc(str, sz)); - if (r == nullptr) memory_panic(); - return r; - } - } -} - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/libjsonnet.h b/vendor/github.com/strickyak/jsonnet_cgo/libjsonnet.h deleted file mode 100644 index ebaf8ff1999c1b3e568d0e934d34d6acea8736c0..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/libjsonnet.h +++ /dev/null @@ -1,365 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef LIB_JSONNET_H -#define LIB_JSONNET_H - -#include <stddef.h> - -/** \file This file is a library interface for evaluating Jsonnet. It is written in C++ but exposes - * a C interface for easier wrapping by other languages. See \see jsonnet_lib_test.c for an example - * of using the library. - */ - - -#define LIB_JSONNET_VERSION "v0.9.4" - - -/** Return the version string of the Jsonnet interpreter. Conforms to semantic versioning - * http://semver.org/ If this does not match LIB_JSONNET_VERSION then there is a mismatch between - * header and compiled library. - */ -const char *jsonnet_version(void); - -/** Jsonnet virtual machine context. */ -struct JsonnetVm; - -/** Create a new Jsonnet virtual machine. */ -struct JsonnetVm *jsonnet_make(void); - -/** Set the maximum stack depth. */ -void jsonnet_max_stack(struct JsonnetVm *vm, unsigned v); - -/** Set the number of objects required before a garbage collection cycle is allowed. */ -void jsonnet_gc_min_objects(struct JsonnetVm *vm, unsigned v); - -/** Run the garbage collector after this amount of growth in the number of objects. */ -void jsonnet_gc_growth_trigger(struct JsonnetVm *vm, double v); - -/** Expect a string as output and don't JSON encode it. */ -void jsonnet_string_output(struct JsonnetVm *vm, int v); - -/** Callback used to load imports. - * - * The returned char* should be allocated with jsonnet_realloc. It will be cleaned up by - * libjsonnet when no-longer needed. - * - * \param ctx User pointer, given in jsonnet_import_callback. - * \param base The directory containing the code that did the import. - * \param rel The path imported by the code. - * \param found_here Set this byref param to path to the file, absolute or relative to the - * process's CWD. This is necessary so that imports from the content of the imported file can - * be resolved correctly. Allocate memory with jsonnet_realloc. Only use when *success = 0. - * \param success Set this byref param to 1 to indicate success and 0 for failure. - * \returns The content of the imported file, or an error message. - */ -typedef char *JsonnetImportCallback(void *ctx, const char *base, const char *rel, char **found_here, int *success); - -/** An opaque type which can only be utilized via the jsonnet_json_* family of functions. - */ -struct JsonnetJsonValue; - -/** If the value is a string, return it as UTF8 otherwise return NULL. - */ -const char *jsonnet_json_extract_string(struct JsonnetVm *vm, const struct JsonnetJsonValue *v); - -/** If the value is a number, return 1 and store the number in out, otherwise return 0. - */ -int jsonnet_json_extract_number(struct JsonnetVm *vm, const struct JsonnetJsonValue *v, double *out); - -/** Return 0 if the value is false, 1 if it is true, and 2 if it is not a bool. - */ -int jsonnet_json_extract_bool(struct JsonnetVm *vm, const struct JsonnetJsonValue *v); - -/** Return 1 if the value is null, else 0. - */ -int jsonnet_json_extract_null(struct JsonnetVm *vm, const struct JsonnetJsonValue *v); - -/** Convert the given UTF8 string to a JsonnetJsonValue. - */ -struct JsonnetJsonValue *jsonnet_json_make_string(struct JsonnetVm *vm, const char *v); - -/** Convert the given double to a JsonnetJsonValue. - */ -struct JsonnetJsonValue *jsonnet_json_make_number(struct JsonnetVm *vm, double v); - -/** Convert the given bool (1 or 0) to a JsonnetJsonValue. - */ -struct JsonnetJsonValue *jsonnet_json_make_bool(struct JsonnetVm *vm, int v); - -/** Make a JsonnetJsonValue representing null. - */ -struct JsonnetJsonValue *jsonnet_json_make_null(struct JsonnetVm *vm); - -/** Make a JsonnetJsonValue representing an array. - * - * Assign elements with jsonnet_json_array_append. - */ -struct JsonnetJsonValue *jsonnet_json_make_array(struct JsonnetVm *vm); - -/** Add v to the end of the array. - */ -void jsonnet_json_array_append(struct JsonnetVm *vm, - struct JsonnetJsonValue *arr, - struct JsonnetJsonValue *v); - -/** Make a JsonnetJsonValue representing an object with the given number of fields. - * - * Every index of the array must have a unique value assigned with jsonnet_json_array_element. - */ -struct JsonnetJsonValue *jsonnet_json_make_object(struct JsonnetVm *vm); - -/** Add the field f to the object, bound to v. - * - * This replaces any previous binding of the field. - */ -void jsonnet_json_object_append(struct JsonnetVm *vm, - struct JsonnetJsonValue *obj, - const char *f, - struct JsonnetJsonValue *v); - -/** Clean up a JSON subtree. - * - * This is useful if you want to abort with an error mid-way through building a complex value. - */ -void jsonnet_json_destroy(struct JsonnetVm *vm, struct JsonnetJsonValue *v); - -/** Callback to provide native extensions to Jsonnet. - * - * The returned JsonnetJsonValue* should be allocated with jsonnet_realloc. It will be cleaned up - * along with the objects rooted at argv by libjsonnet when no-longer needed. Return a string upon - * failure, which will appear in Jsonnet as an error. - * - * \param ctx User pointer, given in jsonnet_native_callback. - * \param argc The number of arguments from Jsonnet code. - * \param argv Array of arguments from Jsonnet code. - * \param success Set this byref param to 1 to indicate success and 0 for failure. - * \returns The content of the imported file, or an error message. - */ -typedef struct JsonnetJsonValue *JsonnetNativeCallback(void *ctx, - const struct JsonnetJsonValue * const *argv, - int *success); - -/** Allocate, resize, or free a buffer. This will abort if the memory cannot be allocated. It will - * only return NULL if sz was zero. - * - * \param buf If NULL, allocate a new buffer. If an previously allocated buffer, resize it. - * \param sz The size of the buffer to return. If zero, frees the buffer. - * \returns The new buffer. - */ -char *jsonnet_realloc(struct JsonnetVm *vm, char *buf, size_t sz); - -/** Override the callback used to locate imports. - */ -void jsonnet_import_callback(struct JsonnetVm *vm, JsonnetImportCallback *cb, void *ctx); - -/** Register a native extension. - * - * This will appear in Jsonnet as a function type and can be accessed from std.nativeExt("foo"). - * - * DO NOT register native callbacks with side-effects! Jsonnet is a lazy functional language and - * will call your function when you least expect it, more times than you expect, or not at all. - * - * \param vm The vm. - * \param name The name of the function as visible to Jsonnet code, e.g. "foo". - * \param cb The PURE function that implements the behavior you want. - * \param ctx User pointer, stash non-global state you need here. - * \param params NULL-terminated array of the names of the params. Must be valid identifiers. - */ -void jsonnet_native_callback(struct JsonnetVm *vm, const char *name, JsonnetNativeCallback *cb, - void *ctx, const char * const *params); - -/** Bind a Jsonnet external var to the given string. - * - * Argument values are copied so memory should be managed by caller. - */ -void jsonnet_ext_var(struct JsonnetVm *vm, const char *key, const char *val); - -/** Bind a Jsonnet external var to the given code. - * - * Argument values are copied so memory should be managed by caller. - */ -void jsonnet_ext_code(struct JsonnetVm *vm, const char *key, const char *val); - -/** Bind a string top-level argument for a top-level parameter. - * - * Argument values are copied so memory should be managed by caller. - */ -void jsonnet_tla_var(struct JsonnetVm *vm, const char *key, const char *val); - -/** Bind a code top-level argument for a top-level parameter. - * - * Argument values are copied so memory should be managed by caller. - */ -void jsonnet_tla_code(struct JsonnetVm *vm, const char *key, const char *val); - -/** Indentation level when reformatting (number of spaeces). - * - * \param n Number of spaces, must be > 0. - */ -void jsonnet_fmt_indent(struct JsonnetVm *vm, int n); - -/** Indentation level when reformatting (number of spaeces). - * - * \param n Number of spaces, must be > 0. - */ -void jsonnet_fmt_max_blank_lines(struct JsonnetVm *vm, int n); - -/** Preferred style for string literals ("" or ''). - * - * \param c String style as a char ('d', 's', or 'l' (leave)). - */ -void jsonnet_fmt_string(struct JsonnetVm *vm, int c); - -/** Preferred style for line comments (# or //). - * - * \param c Comment style as a char ('h', 's', or 'l' (leave)). - */ -void jsonnet_fmt_comment(struct JsonnetVm *vm, int c); - -/** Whether to add an extra space on the inside of arrays. - */ -void jsonnet_fmt_pad_arrays(struct JsonnetVm *vm, int v); - -/** Whether to add an extra space on the inside of objects. - */ -void jsonnet_fmt_pad_objects(struct JsonnetVm *vm, int v); - -/** Use syntax sugar where possible with field names. - */ -void jsonnet_fmt_pretty_field_names(struct JsonnetVm *vm, int v); - -/** If set to 1, will reformat the Jsonnet input after desugaring. */ -void jsonnet_fmt_debug_desugaring(struct JsonnetVm *vm, int v); - -/** Reformat a file containing Jsonnet code, return a Jsonnet string. - * - * The returned string should be cleaned up with jsonnet_realloc. - * - * \param filename Path to a file containing Jsonnet code. - * \param error Return by reference whether or not there was an error. - * \returns Either Jsonnet code or the error message. - */ -char *jsonnet_fmt_file(struct JsonnetVm *vm, - const char *filename, - int *error); - -/** Evaluate a string containing Jsonnet code, return a Jsonnet string. - * - * The returned string should be cleaned up with jsonnet_realloc. - * - * \param filename Path to a file (used in error messages). - * \param snippet Jsonnet code to execute. - * \param error Return by reference whether or not there was an error. - * \returns Either JSON or the error message. - */ -char *jsonnet_fmt_snippet(struct JsonnetVm *vm, - const char *filename, - const char *snippet, - int *error); - -/** Set the number of lines of stack trace to display (0 for all of them). */ -void jsonnet_max_trace(struct JsonnetVm *vm, unsigned v); - -/** Add to the default import callback's library search path. */ -void jsonnet_jpath_add(struct JsonnetVm *vm, const char *v); - -/** Evaluate a file containing Jsonnet code, return a JSON string. - * - * The returned string should be cleaned up with jsonnet_realloc. - * - * \param filename Path to a file containing Jsonnet code. - * \param error Return by reference whether or not there was an error. - * \returns Either JSON or the error message. - */ -char *jsonnet_evaluate_file(struct JsonnetVm *vm, - const char *filename, - int *error); - -/** Evaluate a string containing Jsonnet code, return a JSON string. - * - * The returned string should be cleaned up with jsonnet_realloc. - * - * \param filename Path to a file (used in error messages). - * \param snippet Jsonnet code to execute. - * \param error Return by reference whether or not there was an error. - * \returns Either JSON or the error message. - */ -char *jsonnet_evaluate_snippet(struct JsonnetVm *vm, - const char *filename, - const char *snippet, - int *error); - -/** Evaluate a file containing Jsonnet code, return a number of named JSON files. - * - * The returned character buffer contains an even number of strings, the filename and JSON for each - * JSON file interleaved. It should be cleaned up with jsonnet_realloc. - * - * \param filename Path to a file containing Jsonnet code. - * \param error Return by reference whether or not there was an error. - * \returns Either the error, or a sequence of strings separated by \0, terminated with \0\0. - */ -char *jsonnet_evaluate_file_multi(struct JsonnetVm *vm, - const char *filename, - int *error); - -/** Evaluate a string containing Jsonnet code, return a number of named JSON files. - * - * The returned character buffer contains an even number of strings, the filename and JSON for each - * JSON file interleaved. It should be cleaned up with jsonnet_realloc. - * - * \param filename Path to a file containing Jsonnet code. - * \param snippet Jsonnet code to execute. - * \param error Return by reference whether or not there was an error. - * \returns Either the error, or a sequence of strings separated by \0, terminated with \0\0. - */ -char *jsonnet_evaluate_snippet_multi(struct JsonnetVm *vm, - const char *filename, - const char *snippet, - int *error); - -/** Evaluate a file containing Jsonnet code, return a number of JSON files. - * - * The returned character buffer contains several strings. It should be cleaned up with - * jsonnet_realloc. - * - * \param filename Path to a file containing Jsonnet code. - * \param error Return by reference whether or not there was an error. - * \returns Either the error, or a sequence of strings separated by \0, terminated with \0\0. - */ -char *jsonnet_evaluate_file_stream(struct JsonnetVm *vm, - const char *filename, - int *error); - -/** Evaluate a string containing Jsonnet code, return a number of JSON files. - * - * The returned character buffer contains several strings. It should be cleaned up with - * jsonnet_realloc. - * - * \param filename Path to a file containing Jsonnet code. - * \param snippet Jsonnet code to execute. - * \param error Return by reference whether or not there was an error. - * \returns Either the error, or a sequence of strings separated by \0, terminated with \0\0. - */ -char *jsonnet_evaluate_snippet_stream(struct JsonnetVm *vm, - const char *filename, - const char *snippet, - int *error); - -/** Complement of \see jsonnet_vm_make. */ -void jsonnet_destroy(struct JsonnetVm *vm); - -#endif // LIB_JSONNET_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/md5.cpp b/vendor/github.com/strickyak/jsonnet_cgo/md5.cpp deleted file mode 100644 index b51d2e9bdd68a47ba2dc31528080f607546ab1b6..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/md5.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* MD5 - converted to C++ class by Frank Thilo (thilo@unix-ag.org) - for bzflag (http://www.bzflag.org) - - based on: - - md5.h and md5.c - reference implemantion of RFC 1321 - - Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All -rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD5 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD5 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this -documentation and/or software. - -*/ - -/* interface header */ -#include "md5.h" - -/* system implementation headers */ -#include <cstdio> - - -// Constants for MD5Transform routine. -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -/////////////////////////////////////////////// - -// F, G, H and I are basic MD5 functions. -inline MD5::uint4 MD5::F(uint4 x, uint4 y, uint4 z) { - return (x&y) | (~x&z); -} - -inline MD5::uint4 MD5::G(uint4 x, uint4 y, uint4 z) { - return (x&z) | (y&~z); -} - -inline MD5::uint4 MD5::H(uint4 x, uint4 y, uint4 z) { - return x^y^z; -} - -inline MD5::uint4 MD5::I(uint4 x, uint4 y, uint4 z) { - return y ^ (x | ~z); -} - -// rotate_left rotates x left n bits. -inline MD5::uint4 MD5::rotate_left(uint4 x, int n) { - return (x << n) | (x >> (32-n)); -} - -// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. -// Rotation is separate from addition to prevent recomputation. -inline void MD5::FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a+ F(b,c,d) + x + ac, s) + b; -} - -inline void MD5::GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a + G(b,c,d) + x + ac, s) + b; -} - -inline void MD5::HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a + H(b,c,d) + x + ac, s) + b; -} - -inline void MD5::II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a + I(b,c,d) + x + ac, s) + b; -} - -////////////////////////////////////////////// - -// default ctor, just initailize -MD5::MD5() -{ - init(); -} - -////////////////////////////////////////////// - -// nifty shortcut ctor, compute MD5 for string and finalize it right away -MD5::MD5(const std::string &text) -{ - init(); - update(text.c_str(), text.length()); - finalize(); -} - -////////////////////////////// - -void MD5::init() -{ - finalized=false; - - count[0] = 0; - count[1] = 0; - - // load magic initialization constants. - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; -} - -////////////////////////////// - -// decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4. -void MD5::decode(uint4 output[], const uint1 input[], size_type len) -{ - for (unsigned int i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) | - (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24); -} - -////////////////////////////// - -// encodes input (uint4) into output (unsigned char). Assumes len is -// a multiple of 4. -void MD5::encode(uint1 output[], const uint4 input[], size_type len) -{ - for (size_type i = 0, j = 0; j < len; i++, j += 4) { - output[j] = input[i] & 0xff; - output[j+1] = (input[i] >> 8) & 0xff; - output[j+2] = (input[i] >> 16) & 0xff; - output[j+3] = (input[i] >> 24) & 0xff; - } -} - -////////////////////////////// - -// apply MD5 algo on a block -void MD5::transform(const uint1 block[blocksize]) -{ - uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - decode (x, block, blocksize); - - /* Round 1 */ - FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ - FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ - FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ - FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ - FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ - FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ - FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ - FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ - FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ - FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ - FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ - - /* Round 2 */ - GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ - GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ - GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ - GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ - GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ - GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ - GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ - GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ - GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ - GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ - GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ - HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ - HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ - HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ - HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ - HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ - HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ - HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ - HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ - HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ - HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ - - /* Round 4 */ - II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ - II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ - II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ - II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ - II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ - II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ - II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ - II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ - II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ - II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - - // Zeroize sensitive information. - memset(x, 0, sizeof x); -} - -////////////////////////////// - -// MD5 block update operation. Continues an MD5 message-digest -// operation, processing another message block -void MD5::update(const unsigned char input[], size_type length) -{ - // compute number of bytes mod 64 - size_type index = count[0] / 8 % blocksize; - - // Update number of bits - if ((count[0] += (length << 3)) < (length << 3)) - count[1]++; - count[1] += (length >> 29); - - // number of bytes we need to fill in buffer - size_type firstpart = 64 - index; - - size_type i; - - // transform as many times as possible. - if (length >= firstpart) - { - // fill buffer first, transform - memcpy(&buffer[index], input, firstpart); - transform(buffer); - - // transform chunks of blocksize (64 bytes) - for (i = firstpart; i + blocksize <= length; i += blocksize) - transform(&input[i]); - - index = 0; - } - else - i = 0; - - // buffer remaining input - memcpy(&buffer[index], &input[i], length-i); -} - -////////////////////////////// - -// for convenience provide a verson with signed char -void MD5::update(const char input[], size_type length) -{ - update((const unsigned char*)input, length); -} - -////////////////////////////// - -// MD5 finalization. Ends an MD5 message-digest operation, writing the -// the message digest and zeroizing the context. -MD5& MD5::finalize() -{ - static unsigned char padding[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - if (!finalized) { - // Save number of bits - unsigned char bits[8]; - encode(bits, count, 8); - - // pad out to 56 mod 64. - size_type index = count[0] / 8 % 64; - size_type padLen = (index < 56) ? (56 - index) : (120 - index); - update(padding, padLen); - - // Append length (before padding) - update(bits, 8); - - // Store state in digest - encode(digest, state, 16); - - // Zeroize sensitive information. - memset(buffer, 0, sizeof buffer); - memset(count, 0, sizeof count); - - finalized=true; - } - - return *this; -} - -////////////////////////////// - -// return hex representation of digest as string -std::string MD5::hexdigest() const -{ - if (!finalized) - return ""; - - char buf[33]; - for (int i=0; i<16; i++) - sprintf(buf+i*2, "%02x", digest[i]); - buf[32]=0; - - return std::string(buf); -} - -////////////////////////////// - -std::ostream& operator<<(std::ostream& out, MD5 md5) -{ - return out << md5.hexdigest(); -} - -////////////////////////////// - -std::string md5(const std::string str) -{ - MD5 md5 = MD5(str); - - return md5.hexdigest(); -} - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/md5.h b/vendor/github.com/strickyak/jsonnet_cgo/md5.h deleted file mode 100644 index d57b2c647bd2188da6a298ad3cc07642d112fd0b..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/md5.h +++ /dev/null @@ -1,93 +0,0 @@ -/* MD5 - converted to C++ class by Frank Thilo (thilo@unix-ag.org) - for bzflag (http://www.bzflag.org) - - based on: - - md5.h and md5.c - reference implementation of RFC 1321 - - Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All -rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD5 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD5 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this -documentation and/or software. - -*/ - -#ifndef BZF_MD5_H -#define BZF_MD5_H - -#include <cstring> -#include <iostream> - - -// a small class for calculating MD5 hashes of strings or byte arrays -// it is not meant to be fast or secure -// -// usage: 1) feed it blocks of uchars with update() -// 2) finalize() -// 3) get hexdigest() string -// or -// MD5(std::string).hexdigest() -// -// assumes that char is 8 bit and int is 32 bit -class MD5 -{ -public: - typedef unsigned int size_type; // must be 32bit - - MD5(); - MD5(const std::string& text); - void update(const unsigned char *buf, size_type length); - void update(const char *buf, size_type length); - MD5& finalize(); - std::string hexdigest() const; - friend std::ostream& operator<<(std::ostream&, MD5 md5); - -private: - void init(); - typedef unsigned char uint1; // 8bit - typedef unsigned int uint4; // 32bit - enum {blocksize = 64}; // VC6 won't eat a const static int here - - void transform(const uint1 block[blocksize]); - static void decode(uint4 output[], const uint1 input[], size_type len); - static void encode(uint1 output[], const uint4 input[], size_type len); - - bool finalized; - uint1 buffer[blocksize]; // bytes that didn't fit in last 64 byte chunk - uint4 count[2]; // 64bit counter for number of bits (lo, hi) - uint4 state[4]; // digest so far - uint1 digest[16]; // the result - - // low level logic operations - static inline uint4 F(uint4 x, uint4 y, uint4 z); - static inline uint4 G(uint4 x, uint4 y, uint4 z); - static inline uint4 H(uint4 x, uint4 y, uint4 z); - static inline uint4 I(uint4 x, uint4 y, uint4 z); - static inline uint4 rotate_left(uint4 x, int n); - static inline void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); - static inline void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); - static inline void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); - static inline void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); -}; - -std::string md5(const std::string str); - -#endif diff --git a/vendor/github.com/strickyak/jsonnet_cgo/parser.cpp b/vendor/github.com/strickyak/jsonnet_cgo/parser.cpp deleted file mode 100644 index b0d1ac9a8597c127370d09d6ba74cdf17b3fb64a..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/parser.cpp +++ /dev/null @@ -1,996 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <cstdlib> -#include <cassert> -#include <cmath> - -#include <list> -#include <set> -#include <sstream> -#include <string> -#include <iomanip> - - -#include "ast.h" -#include "desugarer.h" -#include "lexer.h" -#include "parser.h" -#include "static_error.h" - - -std::string jsonnet_unparse_number(double v) -{ - std::stringstream ss; - if (v == floor(v)) { - ss << std::fixed << std::setprecision(0) << v; - } else { - // See "What Every Computer Scientist Should Know About Floating-Point Arithmetic" - // Theorem 15 - // http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html - ss << std::setprecision(17); - ss << v; - } - return ss.str(); -} - - -namespace { - -static bool op_is_unary(const std::string &op, UnaryOp &uop) -{ - auto it = unary_map.find(op); - if (it == unary_map.end()) return false; - uop = it->second; - return true; -} - -static bool op_is_binary(const std::string &op, BinaryOp &bop) -{ - auto it = binary_map.find(op); - if (it == binary_map.end()) return false; - bop = it->second; - return true; -} - -LocationRange span(const Token &begin) -{ - return LocationRange(begin.location.file, begin.location.begin, begin.location.end); -} - -LocationRange span(const Token &begin, const Token &end) -{ - return LocationRange(begin.location.file, begin.location.begin, end.location.end); -} - -LocationRange span(const Token &begin, AST *end) -{ - return LocationRange(begin.location.file, begin.location.begin, end->location.end); -} - -/** Holds state while parsing a given token list. - */ -class Parser { - - // The private member functions are utilities for dealing with the token stream. - - StaticError unexpected(const Token &tok, const std::string &while_) - { - std::stringstream ss; - ss << "Unexpected: " << tok.kind << " while " << while_; - return StaticError(tok.location, ss.str()); - } - - Token pop(void) - { - Token tok = peek(); - tokens.pop_front(); - return tok; - } - - void push(Token tok) { - tokens.push_front(tok); - } - - Token peek(void) - { - Token tok = tokens.front(); - return tok; - } - - /** Only call this is peek() is not an EOF token. */ - Token doublePeek(void) - { - Tokens::iterator it = tokens.begin(); // First one. - it++; // Now pointing at the second one. - return *(it); - } - - Token popExpect(Token::Kind k, const char *data=nullptr) - { - Token tok = pop(); - if (tok.kind != k) { - std::stringstream ss; - ss << "Expected token " << k << " but got " << tok; - throw StaticError(tok.location, ss.str()); - } - if (data != nullptr && tok.data != data) { - std::stringstream ss; - ss << "Expected operator " << data << " but got " << tok.data; - throw StaticError(tok.location, ss.str()); - } - return tok; - } - - std::list<Token> &tokens; - Allocator *alloc; - - public: - - Parser(Tokens &tokens, Allocator *alloc) - : tokens(tokens), alloc(alloc) - { } - - /** Parse a comma-separated list of expressions. - * - * Allows an optional ending comma. - * \param exprs Expressions added here. - * \param end The token that ends the list (e.g. ] or )). - * \param element_kind Used in error messages when a comma was not found. - * \returns The last token (the one that matched parameter end). - */ - Token parseArgs(ArgParams &args, Token::Kind end, - const std::string &element_kind, bool &got_comma) - { - got_comma = false; - bool first = true; - do { - Token next = peek(); - if (next.kind == end) { - // got_comma can be true or false here. - return pop(); - } - if (!first && !got_comma) { - std::stringstream ss; - ss << "Expected a comma before next " << element_kind << "."; - throw StaticError(next.location, ss.str()); - } - // Either id=expr or id or expr, but note that expr could be id==1 so this needs - // look-ahead. - Fodder id_fodder; - const Identifier *id = nullptr; - Fodder eq_fodder; - if (peek().kind == Token::IDENTIFIER) { - Token maybe_eq = doublePeek(); - if (maybe_eq.kind == Token::OPERATOR && maybe_eq.data == "=") { - id_fodder = peek().fodder; - id = alloc->makeIdentifier(peek().data32()); - eq_fodder = maybe_eq.fodder; - pop(); // id - pop(); // eq - } - } - AST *expr = parse(MAX_PRECEDENCE); - got_comma = false; - first = false; - Fodder comma_fodder; - if (peek().kind == Token::COMMA) { - Token comma = pop(); - comma_fodder = comma.fodder; - got_comma = true; - } - args.emplace_back(id_fodder, id, eq_fodder, expr, comma_fodder); - } while (true); - } - - ArgParams parseParams(const std::string &element_kind, bool &got_comma, Fodder &close_fodder) - { - ArgParams params; - Token paren_r = parseArgs(params, Token::PAREN_R, element_kind, got_comma); - - // Check they're all identifiers - // parseArgs returns f(x) with x as an expression. Convert it here. - for (auto &p : params) { - if (p.id == nullptr) { - auto *pv = dynamic_cast<Var*>(p.expr); - if (pv == nullptr) { - throw StaticError(p.expr->location, - "Could not parse parameter here."); - - } - p.id = pv->id; - p.idFodder = pv->openFodder; - p.expr = nullptr; - } - } - - close_fodder = paren_r.fodder; - - return params; - } - - Token parseBind(Local::Binds &binds) - { - Token var_id = popExpect(Token::IDENTIFIER); - auto *id = alloc->makeIdentifier(var_id.data32()); - for (const auto &bind : binds) { - if (bind.var == id) - throw StaticError(var_id.location, "Duplicate local var: " + var_id.data); - } - bool is_function = false; - ArgParams params; - bool trailing_comma = false; - Fodder fodder_l, fodder_r; - if (peek().kind == Token::PAREN_L) { - Token paren_l = pop(); - fodder_l = paren_l.fodder; - params = parseParams("function parameter", trailing_comma, fodder_r); - is_function = true; - } - Token eq = popExpect(Token::OPERATOR, "="); - AST *body = parse(MAX_PRECEDENCE); - Token delim = pop(); - binds.emplace_back(var_id.fodder, id, eq.fodder, body, is_function, fodder_l, params, - trailing_comma, fodder_r, delim.fodder); - return delim; - } - - - Token parseObjectRemainder(AST *&obj, const Token &tok) - { - ObjectFields fields; - std::set<std::string> literal_fields; // For duplicate fields detection. - std::set<const Identifier *> binds; // For duplicate locals detection. - - bool got_comma = false; - bool first = true; - Token next = pop(); - - do { - - if (next.kind == Token::BRACE_R) { - obj = alloc->make<Object>( - span(tok, next), tok.fodder, fields, got_comma, next.fodder); - return next; - - } else if (next.kind == Token::FOR) { - // It's a comprehension - unsigned num_fields = 0; - unsigned num_asserts = 0; - const ObjectField *field_ptr = nullptr; - for (const auto &field : fields) { - if (field.kind == ObjectField::LOCAL) continue; - if (field.kind == ObjectField::ASSERT) { - num_asserts++; - continue; - } - field_ptr = &field; - num_fields++; - } - if (num_asserts > 0) { - auto msg = "Object comprehension cannot have asserts."; - throw StaticError(next.location, msg); - } - if (num_fields != 1) { - auto msg = "Object comprehension can only have one field."; - throw StaticError(next.location, msg); - } - const ObjectField &field = *field_ptr; - - if (field.hide != ObjectField::INHERIT) { - auto msg = "Object comprehensions cannot have hidden fields."; - throw StaticError(next.location, msg); - } - - if (field.kind != ObjectField::FIELD_EXPR) { - auto msg = "Object comprehensions can only have [e] fields."; - throw StaticError(next.location, msg); - } - - std::vector<ComprehensionSpec> specs; - Token last = parseComprehensionSpecs(Token::BRACE_R, next.fodder, specs); - obj = alloc->make<ObjectComprehension>( - span(tok, last), tok.fodder, fields, got_comma, specs, last.fodder); - - return last; - } - - if (!got_comma && !first) - throw StaticError(next.location, "Expected a comma before next field."); - - first = false; - got_comma = false; - - switch (next.kind) { - case Token::BRACKET_L: case Token::IDENTIFIER: case Token::STRING_DOUBLE: - case Token::STRING_SINGLE: case Token::STRING_BLOCK: { - ObjectField::Kind kind; - AST *expr1 = nullptr; - const Identifier *id = nullptr; - Fodder fodder1, fodder2; - if (next.kind == Token::IDENTIFIER) { - fodder1 = next.fodder; - kind = ObjectField::FIELD_ID; - id = alloc->makeIdentifier(next.data32()); - } else if (next.kind == Token::STRING_DOUBLE) { - kind = ObjectField::FIELD_STR; - expr1 = alloc->make<LiteralString>( - next.location, next.fodder, next.data32(), LiteralString::DOUBLE, - "", ""); - } else if (next.kind == Token::STRING_SINGLE) { - kind = ObjectField::FIELD_STR; - expr1 = alloc->make<LiteralString>( - next.location, next.fodder, next.data32(), LiteralString::SINGLE, - "", ""); - } else if (next.kind == Token::STRING_BLOCK) { - kind = ObjectField::FIELD_STR; - expr1 = alloc->make<LiteralString>( - next.location, next.fodder, next.data32(), LiteralString::BLOCK, - next.stringBlockIndent, next.stringBlockTermIndent); - } else { - kind = ObjectField::FIELD_EXPR; - fodder1 = next.fodder; - expr1 = parse(MAX_PRECEDENCE); - Token bracket_r = popExpect(Token::BRACKET_R); - fodder2 = bracket_r.fodder; - } - - bool is_method = false; - bool meth_comma = false; - ArgParams params; - Fodder fodder_l; - Fodder fodder_r; - if (peek().kind == Token::PAREN_L) { - Token paren_l = pop(); - fodder_l = paren_l.fodder; - params = parseParams("method parameter", meth_comma, fodder_r); - is_method = true; - } - - bool plus_sugar = false; - - Token op = popExpect(Token::OPERATOR); - const char *od = op.data.c_str(); - if (*od == '+') { - plus_sugar = true; - od++; - } - unsigned colons = 0; - for (; *od != '\0' ; ++od) { - if (*od != ':') { - throw StaticError( - next.location, - "Expected one of :, ::, :::, +:, +::, +:::, got: " + op.data); - } - ++colons; - } - ObjectField::Hide field_hide; - switch (colons) { - case 1: - field_hide = ObjectField::INHERIT; - break; - - case 2: - field_hide = ObjectField::HIDDEN; - break; - - case 3: - field_hide = ObjectField::VISIBLE; - break; - - default: - throw StaticError( - next.location, - "Expected one of :, ::, :::, +:, +::, +:::, got: " + op.data); - } - - // Basic checks for invalid Jsonnet code. - if (is_method && plus_sugar) { - throw StaticError( - next.location, "Cannot use +: syntax sugar in a method: " + next.data); - } - if (kind != ObjectField::FIELD_EXPR) { - if (!literal_fields.insert(next.data).second) { - throw StaticError(next.location, "Duplicate field: "+next.data); - } - } - - AST *body = parse(MAX_PRECEDENCE); - - Fodder comma_fodder; - next = pop(); - if (next.kind == Token::COMMA) { - comma_fodder = next.fodder; - next = pop(); - got_comma = true; - } - fields.emplace_back( - kind, fodder1, fodder2, fodder_l, fodder_r, field_hide, plus_sugar, - is_method, expr1, id, params, meth_comma, op.fodder, body, nullptr, - comma_fodder); - } - break; - - case Token::LOCAL: { - Fodder local_fodder = next.fodder; - Token var_id = popExpect(Token::IDENTIFIER); - auto *id = alloc->makeIdentifier(var_id.data32()); - - if (binds.find(id) != binds.end()) { - throw StaticError(var_id.location, "Duplicate local var: " + var_id.data); - } - bool is_method = false; - bool func_comma = false; - ArgParams params; - Fodder paren_l_fodder; - Fodder paren_r_fodder; - if (peek().kind == Token::PAREN_L) { - Token paren_l = pop(); - paren_l_fodder = paren_l.fodder; - is_method = true; - params = parseParams("function parameter", func_comma, paren_r_fodder); - } - Token eq = popExpect(Token::OPERATOR, "="); - AST *body = parse(MAX_PRECEDENCE); - binds.insert(id); - - Fodder comma_fodder; - next = pop(); - if (next.kind == Token::COMMA) { - comma_fodder = next.fodder; - next = pop(); - got_comma = true; - } - fields.push_back( - ObjectField::Local( - local_fodder, var_id.fodder, paren_l_fodder, paren_r_fodder, - is_method, id, params, func_comma, eq.fodder, body, comma_fodder)); - - } - break; - - case Token::ASSERT: { - Fodder assert_fodder = next.fodder; - AST *cond = parse(MAX_PRECEDENCE); - AST *msg = nullptr; - Fodder colon_fodder; - if (peek().kind == Token::OPERATOR && peek().data == ":") { - Token colon = pop(); - colon_fodder = colon.fodder; - msg = parse(MAX_PRECEDENCE); - } - - Fodder comma_fodder; - next = pop(); - if (next.kind == Token::COMMA) { - comma_fodder = next.fodder; - next = pop(); - got_comma = true; - } - fields.push_back(ObjectField::Assert(assert_fodder, cond, colon_fodder, msg, - comma_fodder)); - } - break; - - default: - throw unexpected(next, "parsing field definition"); - } - - - } while (true); - } - - /** parses for x in expr for y in expr if expr for z in expr ... */ - Token parseComprehensionSpecs(Token::Kind end, Fodder for_fodder, - std::vector<ComprehensionSpec> &specs) - { - while (true) { - LocationRange l; - Token id_token = popExpect(Token::IDENTIFIER); - const Identifier *id = alloc->makeIdentifier(id_token.data32()); - Token in_token = popExpect(Token::IN); - AST *arr = parse(MAX_PRECEDENCE); - specs.emplace_back(ComprehensionSpec::FOR, for_fodder, id_token.fodder, id, - in_token.fodder, arr); - - Token maybe_if = pop(); - for (; maybe_if.kind == Token::IF; maybe_if = pop()) { - AST *cond = parse(MAX_PRECEDENCE); - specs.emplace_back(ComprehensionSpec::IF, maybe_if.fodder, Fodder{}, nullptr, - Fodder{}, cond); - } - if (maybe_if.kind == end) { - return maybe_if; - } - if (maybe_if.kind != Token::FOR) { - std::stringstream ss; - ss << "Expected for, if or " << end << " after for clause, got: " << maybe_if; - throw StaticError(maybe_if.location, ss.str()); - } - for_fodder = maybe_if.fodder; - } - } - - AST *parseTerminal(void) - { - Token tok = pop(); - switch (tok.kind) { - case Token::ASSERT: - case Token::BRACE_R: - case Token::BRACKET_R: - case Token::COMMA: - case Token::DOT: - case Token::ELSE: - case Token::ERROR: - case Token::FOR: - case Token::FUNCTION: - case Token::IF: - case Token::IN: - case Token::IMPORT: - case Token::IMPORTSTR: - case Token::LOCAL: - case Token::OPERATOR: - case Token::PAREN_R: - case Token::SEMICOLON: - case Token::TAILSTRICT: - case Token::THEN: - throw unexpected(tok, "parsing terminal"); - - case Token::END_OF_FILE: - throw StaticError(tok.location, "Unexpected end of file."); - - case Token::BRACE_L: { - AST *obj; - parseObjectRemainder(obj, tok); - return obj; - } - - case Token::BRACKET_L: { - Token next = peek(); - if (next.kind == Token::BRACKET_R) { - Token bracket_r = pop(); - return alloc->make<Array>(span(tok, next), tok.fodder, Array::Elements{}, - false, bracket_r.fodder); - } - AST *first = parse(MAX_PRECEDENCE); - bool got_comma = false; - Fodder comma_fodder; - next = peek(); - if (!got_comma && next.kind == Token::COMMA) { - Token comma = pop(); - comma_fodder = comma.fodder; - next = peek(); - got_comma = true; - } - - if (next.kind == Token::FOR) { - // It's a comprehension - Token for_token = pop(); - std::vector<ComprehensionSpec> specs; - Token last = parseComprehensionSpecs(Token::BRACKET_R, for_token.fodder, specs); - return alloc->make<ArrayComprehension>( - span(tok, last), tok.fodder, first, comma_fodder, got_comma, specs, - last.fodder); - } - - // Not a comprehension: It can have more elements. - Array::Elements elements; - elements.emplace_back(first, comma_fodder); - do { - if (next.kind == Token::BRACKET_R) { - Token bracket_r = pop(); - return alloc->make<Array>( - span(tok, next), tok.fodder, elements, got_comma, bracket_r.fodder); - } - if (!got_comma) { - std::stringstream ss; - ss << "Expected a comma before next array element."; - throw StaticError(next.location, ss.str()); - } - AST *expr = parse(MAX_PRECEDENCE); - comma_fodder.clear(); - got_comma = false; - next = peek(); - if (next.kind == Token::COMMA) { - Token comma = pop(); - comma_fodder = comma.fodder; - next = peek(); - got_comma = true; - } - elements.emplace_back(expr, comma_fodder); - } while (true); - } - - case Token::PAREN_L: { - auto *inner = parse(MAX_PRECEDENCE); - Token close = popExpect(Token::PAREN_R); - return alloc->make<Parens>(span(tok, close), tok.fodder, inner, close.fodder); - } - - // Literals - case Token::NUMBER: - return alloc->make<LiteralNumber>(span(tok), tok.fodder, tok.data); - - case Token::STRING_SINGLE: - return alloc->make<LiteralString>( - span(tok), tok.fodder, tok.data32(), LiteralString::SINGLE, "", ""); - case Token::STRING_DOUBLE: - return alloc->make<LiteralString>( - span(tok), tok.fodder, tok.data32(), LiteralString::DOUBLE, "", ""); - case Token::STRING_BLOCK: - return alloc->make<LiteralString>( - span(tok), tok.fodder, tok.data32(), LiteralString::BLOCK, - tok.stringBlockIndent, tok.stringBlockTermIndent); - case Token::VERBATIM_STRING_SINGLE: - return alloc->make<LiteralString>( - span(tok), tok.fodder, tok.data32(), LiteralString::VERBATIM_SINGLE, "", ""); - case Token::VERBATIM_STRING_DOUBLE: - return alloc->make<LiteralString>( - span(tok), tok.fodder, tok.data32(), LiteralString::VERBATIM_DOUBLE, "", ""); - - - case Token::FALSE: - return alloc->make<LiteralBoolean>(span(tok), tok.fodder, false); - - case Token::TRUE: - return alloc->make<LiteralBoolean>(span(tok), tok.fodder, true); - - case Token::NULL_LIT: - return alloc->make<LiteralNull>(span(tok), tok.fodder); - - // Variables - case Token::DOLLAR: - return alloc->make<Dollar>(span(tok), tok.fodder); - - case Token::IDENTIFIER: - return alloc->make<Var>(span(tok), tok.fodder, alloc->makeIdentifier(tok.data32())); - - case Token::SELF: - return alloc->make<Self>(span(tok), tok.fodder); - - case Token::SUPER: { - Token next = pop(); - AST *index = nullptr; - const Identifier *id = nullptr; - Fodder id_fodder; - switch (next.kind) { - case Token::DOT: { - Token field_id = popExpect(Token::IDENTIFIER); - id_fodder = field_id.fodder; - id = alloc->makeIdentifier(field_id.data32()); - } break; - case Token::BRACKET_L: { - index = parse(MAX_PRECEDENCE); - Token bracket_r = popExpect(Token::BRACKET_R); - id_fodder = bracket_r.fodder; // Not id_fodder, but use the same var. - } break; - default: - throw StaticError(tok.location, "Expected . or [ after super."); - } - return alloc->make<SuperIndex>(span(tok), tok.fodder, next.fodder, index, - id_fodder, id); - } - } - - std::cerr << "INTERNAL ERROR: Unknown tok kind: " << tok.kind << std::endl; - std::abort(); - return nullptr; // Quiet, compiler. - } - - AST *parse(int precedence) - { - Token begin = peek(); - - switch (begin.kind) { - - // These cases have effectively MAX_PRECEDENCE as the first - // call to parse will parse them. - case Token::ASSERT: { - pop(); - AST *cond = parse(MAX_PRECEDENCE); - Fodder colonFodder; - AST *msg = nullptr; - if (peek().kind == Token::OPERATOR && peek().data == ":") { - Token colon = pop(); - colonFodder = colon.fodder; - msg = parse(MAX_PRECEDENCE); - } - Token semicolon = popExpect(Token::SEMICOLON); - AST *rest = parse(MAX_PRECEDENCE); - return alloc->make<Assert>(span(begin, rest), begin.fodder, cond, colonFodder, - msg, semicolon.fodder, rest); - } - - case Token::ERROR: { - pop(); - AST *expr = parse(MAX_PRECEDENCE); - return alloc->make<Error>(span(begin, expr), begin.fodder, expr); - } - - case Token::IF: { - pop(); - AST *cond = parse(MAX_PRECEDENCE); - Token then = popExpect(Token::THEN); - AST *branch_true = parse(MAX_PRECEDENCE); - if (peek().kind == Token::ELSE) { - Token else_ = pop(); - AST *branch_false = parse(MAX_PRECEDENCE); - return alloc->make<Conditional>( - span(begin, branch_false), begin.fodder, cond, then.fodder, branch_true, - else_.fodder, branch_false); - } - return alloc->make<Conditional>(span(begin, branch_true), begin.fodder, cond, - then.fodder, branch_true, Fodder{}, nullptr); - } - - case Token::FUNCTION: { - pop(); // Still available in 'begin'. - Token paren_l = pop(); - if (paren_l.kind == Token::PAREN_L) { - std::vector<AST*> params_asts; - bool got_comma; - Fodder paren_r_fodder; - ArgParams params = parseParams( - "function parameter", got_comma, paren_r_fodder); - AST *body = parse(MAX_PRECEDENCE); - return alloc->make<Function>( - span(begin, body), begin.fodder, paren_l.fodder, params, got_comma, - paren_r_fodder, body); - } else { - std::stringstream ss; - ss << "Expected ( but got " << paren_l; - throw StaticError(paren_l.location, ss.str()); - } - } - - case Token::IMPORT: { - pop(); - AST *body = parse(MAX_PRECEDENCE); - if (auto *lit = dynamic_cast<LiteralString*>(body)) { - if (lit->tokenKind == LiteralString::BLOCK) { - throw StaticError(lit->location, - "Cannot use text blocks in import statements."); - } - return alloc->make<Import>(span(begin, body), begin.fodder, lit); - } else { - std::stringstream ss; - ss << "Computed imports are not allowed."; - throw StaticError(body->location, ss.str()); - } - } - - case Token::IMPORTSTR: { - pop(); - AST *body = parse(MAX_PRECEDENCE); - if (auto *lit = dynamic_cast<LiteralString*>(body)) { - if (lit->tokenKind == LiteralString::BLOCK) { - throw StaticError(lit->location, - "Cannot use text blocks in import statements."); - } - return alloc->make<Importstr>(span(begin, body), begin.fodder, lit); - } else { - std::stringstream ss; - ss << "Computed imports are not allowed."; - throw StaticError(body->location, ss.str()); - } - } - - case Token::LOCAL: { - pop(); - Local::Binds binds; - do { - Token delim = parseBind(binds); - if (delim.kind != Token::SEMICOLON && delim.kind != Token::COMMA) { - std::stringstream ss; - ss << "Expected , or ; but got " << delim; - throw StaticError(delim.location, ss.str()); - } - if (delim.kind == Token::SEMICOLON) break; - } while (true); - AST *body = parse(MAX_PRECEDENCE); - return alloc->make<Local>(span(begin, body), begin.fodder, binds, body); - } - - default: - - // Unary operator. - if (begin.kind == Token::OPERATOR) { - UnaryOp uop; - if (!op_is_unary(begin.data, uop)) { - std::stringstream ss; - ss << "Not a unary operator: " << begin.data; - throw StaticError(begin.location, ss.str()); - } - if (UNARY_PRECEDENCE == precedence) { - Token op = pop(); - AST *expr = parse(precedence); - return alloc->make<Unary>(span(op, expr), op.fodder, uop, expr); - } - } - - // Base case - if (precedence == 0) return parseTerminal(); - - AST *lhs = parse(precedence - 1); - - Fodder begin_fodder; - - while (true) { - - // Then next token must be a binary operator. - - // The compiler can't figure out that this is never used uninitialized. - BinaryOp bop = BOP_PLUS; - - // Check precedence is correct for this level. If we're - // parsing operators with higher precedence, then return - // lhs and let lower levels deal with the operator. - switch (peek().kind) { - // Logical / arithmetic binary operator. - case Token::IN: - case Token::OPERATOR: - if (peek().data == ":") { - // Special case for the colons in assert. - // Since COLON is no-longer a special token, we have to make sure it - // does not trip the op_is_binary test below. It should - // terminate parsing of the expression here, returning control - // to the parsing of the actual assert AST. - return lhs; - } - if (peek().data == "::") { - // Special case for [e::] - // We need to stop parsing e when we see the :: and - // avoid tripping the op_is_binary test below. - return lhs; - } - if (!op_is_binary(peek().data, bop)) { - std::stringstream ss; - ss << "Not a binary operator: " << peek().data; - throw StaticError(peek().location, ss.str()); - } - if (precedence_map[bop] != precedence) return lhs; - break; - - // Index, Apply - case Token::DOT: case Token::BRACKET_L: - case Token::PAREN_L: case Token::BRACE_L: - if (APPLY_PRECEDENCE != precedence) return lhs; - break; - - default: - return lhs; - } - - Token op = pop(); - if (op.kind == Token::BRACKET_L) { - bool is_slice; - AST *first = nullptr; - Fodder second_fodder; - AST *second = nullptr; - Fodder third_fodder; - AST *third = nullptr; - - if (peek().kind == Token::BRACKET_R) - throw unexpected(pop(), "parsing index"); - - if (peek().data != ":" && peek().data != "::") { - first = parse(MAX_PRECEDENCE); - } - - if (peek().kind == Token::OPERATOR && peek().data == "::") { - // Handle :: - is_slice = true; - Token joined = pop(); - second_fodder = joined.fodder; - - if (peek().kind != Token::BRACKET_R) - third = parse(MAX_PRECEDENCE); - - } else if (peek().kind != Token::BRACKET_R) { - is_slice = true; - Token delim = pop(); - if (delim.data != ":") - throw unexpected(delim, "parsing slice"); - - second_fodder = delim.fodder; - - if (peek().data != ":" && peek().kind != Token::BRACKET_R) - second = parse(MAX_PRECEDENCE); - - if (peek().kind != Token::BRACKET_R) { - Token delim = pop(); - if (delim.data != ":") - throw unexpected(delim, "parsing slice"); - - third_fodder = delim.fodder; - - if (peek().kind != Token::BRACKET_R) - third = parse(MAX_PRECEDENCE); - } - } else { - is_slice = false; - } - Token end = popExpect(Token::BRACKET_R); - lhs = alloc->make<Index>(span(begin, end), begin_fodder, lhs, op.fodder, - is_slice, first, second_fodder, second, - third_fodder, third, end.fodder); - - } else if (op.kind == Token::DOT) { - Token field_id = popExpect(Token::IDENTIFIER); - const Identifier *id = alloc->makeIdentifier(field_id.data32()); - lhs = alloc->make<Index>(span(begin, field_id), begin_fodder, lhs, - op.fodder, field_id.fodder, id); - - } else if (op.kind == Token::PAREN_L) { - ArgParams args; - bool got_comma; - Token end = parseArgs(args, Token::PAREN_R, "function argument", got_comma); - bool tailstrict = false; - Fodder tailstrict_fodder; - if (peek().kind == Token::TAILSTRICT) { - Token tailstrict_token = pop(); - tailstrict_fodder = tailstrict_token.fodder; - tailstrict = true; - } - lhs = alloc->make<Apply>(span(begin, end), begin_fodder, lhs, op.fodder, - args, got_comma, end.fodder, tailstrict_fodder, - tailstrict); - - } else if (op.kind == Token::BRACE_L) { - AST *obj; - Token end = parseObjectRemainder(obj, op); - lhs = alloc->make<ApplyBrace>(span(begin, end), begin_fodder, lhs, obj); - - } else if (op.kind == Token::IN) { - if (peek().kind == Token::SUPER) { - Token super = pop(); - lhs = alloc->make<InSuper>( - span(begin, super), begin_fodder, lhs, op.fodder, super.fodder); - } else { - AST *rhs = parse(precedence - 1); - lhs = alloc->make<Binary>( - span(begin, rhs), begin_fodder, lhs, op.fodder, bop, rhs); - } - - } else { - // Logical / arithmetic binary operator. - assert(op.kind == Token::OPERATOR); - AST *rhs = parse(precedence - 1); - lhs = alloc->make<Binary>(span(begin, rhs), begin_fodder, lhs, op.fodder, - bop, rhs); - } - - begin_fodder.clear(); - } - } - } - -}; - -} // namespace - -AST *jsonnet_parse(Allocator *alloc, Tokens &tokens) -{ - Parser parser(tokens, alloc); - AST *expr = parser.parse(MAX_PRECEDENCE); - if (tokens.front().kind != Token::END_OF_FILE) { - std::stringstream ss; - ss << "Did not expect: " << tokens.front(); - throw StaticError(tokens.front().location, ss.str()); - } - - return expr; -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/parser.h b/vendor/github.com/strickyak/jsonnet_cgo/parser.h deleted file mode 100644 index ab4d173dfe8ac59c05cfe16b792d55ee667770d7..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/parser.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_PARSER_H -#define JSONNET_PARSER_H - -#include <string> - -#include "ast.h" -#include "lexer.h" -#include "unicode.h" - -/** Parse a given JSON++ string. - * - * \param alloc Used to allocate the AST nodes. The Allocator must outlive the - * AST pointer returned. - * \param tokens The list of tokens (all tokens are popped except EOF). - * \returns The parsed abstract syntax tree. - */ -AST *jsonnet_parse(Allocator *alloc, Tokens &tokens); - -/** Outputs a number, trying to preserve precision as well as possible. - */ -std::string jsonnet_unparse_number(double v); - -/** The inverse of jsonnet_parse. - */ -std::string jsonnet_unparse_jsonnet(const AST *ast, const Fodder &final_fodder, unsigned indent, - bool pad_arrays, bool pad_objects, char comment_style); - -#endif // JSONNET_PARSER_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/pass.cpp b/vendor/github.com/strickyak/jsonnet_cgo/pass.cpp deleted file mode 100644 index ce274a54cd1f8f8574fdfa6b037149e327a8a9e5..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/pass.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "pass.h" - -void CompilerPass::fodder(Fodder &fodder) -{ - for (auto &f : fodder) - fodderElement(f); -} - -void CompilerPass::specs(std::vector<ComprehensionSpec> &specs) -{ - for (auto &spec : specs) { - fodder(spec.openFodder); - switch (spec.kind) { - case ComprehensionSpec::FOR: - fodder(spec.varFodder); - fodder(spec.inFodder); - expr(spec.expr); - break; - case ComprehensionSpec::IF: - expr(spec.expr); - break; - } - } -} - -void CompilerPass::params(Fodder &fodder_l, ArgParams ¶ms, Fodder &fodder_r) -{ - fodder(fodder_l); - for (auto ¶m : params) { - fodder(param.idFodder); - if (param.expr) { - fodder(param.eqFodder); - expr(param.expr); - } - fodder(param.commaFodder); - } - fodder(fodder_r); -} - -void CompilerPass::fieldParams(ObjectField &field) -{ - if (field.methodSugar) { - params(field.fodderL, field.params, field.fodderR); - } -} - -void CompilerPass::fields(ObjectFields &fields) -{ - for (auto &field : fields) { - - switch (field.kind) { - case ObjectField::LOCAL: { - fodder(field.fodder1); - fodder(field.fodder2); - fieldParams(field); - fodder(field.opFodder); - expr(field.expr2); - } break; - - case ObjectField::FIELD_ID: - case ObjectField::FIELD_STR: - case ObjectField::FIELD_EXPR: { - if (field.kind == ObjectField::FIELD_ID) { - fodder(field.fodder1); - - } else if (field.kind == ObjectField::FIELD_STR) { - expr(field.expr1); - - } else if (field.kind == ObjectField::FIELD_EXPR) { - fodder(field.fodder1); - expr(field.expr1); - fodder(field.fodder2); - } - fieldParams(field); - fodder(field.opFodder); - expr(field.expr2); - - } break; - - case ObjectField::ASSERT: { - fodder(field.fodder1); - expr(field.expr2); - if (field.expr3 != nullptr) { - fodder(field.opFodder); - expr(field.expr3); - } - } break; - } - - fodder(field.commaFodder); - } -} - -void CompilerPass::expr(AST *&ast_) -{ - fodder(ast_->openFodder); - visitExpr(ast_); -} - -void CompilerPass::visit(Apply *ast) -{ - expr(ast->target); - fodder(ast->fodderL); - for (auto &arg : ast->args) { - expr(arg.expr); - fodder(arg.commaFodder); - } - fodder(ast->fodderR); - if (ast->tailstrict) { - fodder(ast->tailstrictFodder); - } -} - -void CompilerPass::visit(ApplyBrace *ast) -{ - expr(ast->left); - expr(ast->right); -} - -void CompilerPass::visit(Array *ast) -{ - for (auto &element : ast->elements) { - expr(element.expr); - fodder(element.commaFodder); - } - fodder(ast->closeFodder); -} - -void CompilerPass::visit(ArrayComprehension *ast) -{ - expr(ast->body); - fodder(ast->commaFodder); - specs(ast->specs); - fodder(ast->closeFodder); -} - -void CompilerPass::visit(Assert *ast) -{ - expr(ast->cond); - if (ast->message != nullptr) { - fodder(ast->colonFodder); - expr(ast->message); - } - fodder(ast->semicolonFodder); - expr(ast->rest); -} - -void CompilerPass::visit(Binary *ast) -{ - expr(ast->left); - fodder(ast->opFodder); - expr(ast->right); -} - -void CompilerPass::visit(Conditional *ast) -{ - expr(ast->cond); - fodder(ast->thenFodder); - if (ast->branchFalse != nullptr) { - expr(ast->branchTrue); - fodder(ast->elseFodder); - expr(ast->branchFalse); - } else { - expr(ast->branchTrue); - } -} - -void CompilerPass::visit(Error *ast) -{ - expr(ast->expr); -} - -void CompilerPass::visit(Function *ast) -{ - params(ast->parenLeftFodder, ast->params, ast->parenRightFodder); - expr(ast->body); -} - -void CompilerPass::visit(Import *ast) -{ - visit(ast->file); -} - -void CompilerPass::visit(Importstr *ast) -{ - visit(ast->file); -} - -void CompilerPass::visit(InSuper *ast) -{ - expr(ast->element); -} - -void CompilerPass::visit(Index *ast) -{ - expr(ast->target); - if (ast->id != nullptr) { - } else { - if (ast->isSlice) { - if (ast->index != nullptr) - expr(ast->index); - if (ast->end != nullptr) - expr(ast->end); - if (ast->step != nullptr) - expr(ast->step); - } else { - expr(ast->index); - } - } -} - -void CompilerPass::visit(Local *ast) -{ - assert(ast->binds.size() > 0); - for (auto &bind : ast->binds) { - fodder(bind.varFodder); - if (bind.functionSugar) { - params(bind.parenLeftFodder, bind.params, bind.parenRightFodder); - } - fodder(bind.opFodder); - expr(bind.body); - fodder(bind.closeFodder); - } - expr(ast->body); -} - -void CompilerPass::visit(Object *ast) -{ - fields(ast->fields); - fodder(ast->closeFodder); -} - -void CompilerPass::visit(DesugaredObject *ast) -{ - for (AST *assert : ast->asserts) { - expr(assert); - } - for (auto &field : ast->fields) { - expr(field.name); - expr(field.body); - } -} - -void CompilerPass::visit(ObjectComprehension *ast) -{ - fields(ast->fields); - specs(ast->specs); - fodder(ast->closeFodder); -} - -void CompilerPass::visit(ObjectComprehensionSimple *ast) -{ - expr(ast->field); - expr(ast->value); - expr(ast->array); -} - -void CompilerPass::visit(Parens *ast) -{ - expr(ast->expr); - fodder(ast->closeFodder); -} - -void CompilerPass::visit(SuperIndex *ast) -{ - if (ast->id != nullptr) { - } else { - expr(ast->index); - } -} - -void CompilerPass::visit(Unary *ast) -{ - expr(ast->expr); -} - -void CompilerPass::visitExpr(AST *&ast_) -{ - if (auto *ast = dynamic_cast<Apply*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<ApplyBrace*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Array*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Assert*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Binary*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<BuiltinFunction*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Dollar*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Error*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Function*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Import*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Importstr*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<InSuper*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Index*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Local*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<LiteralBoolean*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<LiteralNumber*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<LiteralString*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<LiteralNull*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Object*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<DesugaredObject*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Parens*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Self*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<SuperIndex*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Unary*>(ast_)) { - visit(ast); - } else if (auto *ast = dynamic_cast<Var*>(ast_)) { - visit(ast); - - } else { - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; - std::abort(); - - } -} - -void CompilerPass::file(AST *&body, Fodder &final_fodder) -{ - expr(body); - fodder(final_fodder); -} - -/** A pass that clones the AST it is given. */ -class ClonePass : public CompilerPass { - public: - ClonePass(Allocator &alloc) : CompilerPass(alloc) { } - virtual void expr(AST *&ast); -}; - -void ClonePass::expr(AST *&ast_) -{ - if (auto *ast = dynamic_cast<Apply*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<ApplyBrace*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Array*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<ArrayComprehension*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Assert*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Binary*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<BuiltinFunction*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Conditional*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Dollar*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Error*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Function*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Import*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Importstr*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<InSuper*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Index*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Local*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<LiteralBoolean*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<LiteralNumber*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<LiteralString*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<LiteralNull*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Object*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<DesugaredObject*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<ObjectComprehension*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Parens*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Self*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<SuperIndex*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Unary*>(ast_)) { - ast_ = alloc.clone(ast); - } else if (auto *ast = dynamic_cast<Var*>(ast_)) { - ast_ = alloc.clone(ast); - - } else { - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; - std::abort(); - - } - - CompilerPass::expr(ast_); -} - -AST *clone_ast(Allocator &alloc, AST *ast) -{ - AST *r = ast; - ClonePass(alloc).expr(r); - return r; -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/pass.h b/vendor/github.com/strickyak/jsonnet_cgo/pass.h deleted file mode 100644 index 10c3c9d85dbc7faa6a5b4e684072e6c949a5b891..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/pass.h +++ /dev/null @@ -1,117 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_PASS_H -#define JSONNET_PASS_H - -#include "ast.h" - -/** A generic Pass that does nothing but can be extended to easily define real passes. - */ -class CompilerPass { - public: - - protected: - Allocator &alloc; - - public: - CompilerPass(Allocator &alloc) : alloc(alloc) { } - - virtual void fodderElement(FodderElement &) { } - - virtual void fodder(Fodder &fodder); - - virtual void specs(std::vector<ComprehensionSpec> &specs); - - virtual void params(Fodder &fodder_l, ArgParams ¶ms, Fodder &fodder_r); - - virtual void fieldParams(ObjectField &field); - - virtual void fields(ObjectFields &fields); - - virtual void expr(AST *&ast_); - - virtual void visit(Apply *ast); - - virtual void visit(ApplyBrace *ast); - - virtual void visit(Array *ast); - - virtual void visit(ArrayComprehension *ast); - - virtual void visit(Assert *ast); - - virtual void visit(Binary *ast); - - virtual void visit(BuiltinFunction *) { } - - virtual void visit(Conditional *ast); - - virtual void visit(Dollar *) { } - - virtual void visit(Error *ast); - - virtual void visit(Function *ast); - - virtual void visit(Import *ast); - - virtual void visit(Importstr *ast); - - virtual void visit(InSuper *ast); - - virtual void visit(Index *ast); - - virtual void visit(Local *ast); - - virtual void visit(LiteralBoolean *) { } - - virtual void visit(LiteralNumber *) { } - - virtual void visit(LiteralString *) { } - - virtual void visit(LiteralNull *) { } - - virtual void visit(Object *ast); - - virtual void visit(DesugaredObject *ast); - - virtual void visit(ObjectComprehension *ast); - - virtual void visit(ObjectComprehensionSimple *ast); - - virtual void visit(Parens *ast); - - virtual void visit(Self *) { } - - virtual void visit(SuperIndex *ast); - - virtual void visit(Unary *ast); - - virtual void visit(Var *) { } - - virtual void visitExpr(AST *&ast_); - - virtual void file(AST *&body, Fodder &final_fodder); -}; - - -/** Return an equivalent AST that can be modified without affecting the original. - * - * This is a deep copy. - */ -AST *clone_ast(Allocator &alloc, AST *ast); - -#endif diff --git a/vendor/github.com/strickyak/jsonnet_cgo/state.h b/vendor/github.com/strickyak/jsonnet_cgo/state.h deleted file mode 100644 index b009806abb0e9ec715abc8d8bd96b412d9a5e64f..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/state.h +++ /dev/null @@ -1,444 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_STATE_H -#define JSONNET_STATE_H - -namespace { - -/** Mark & sweep: advanced by 1 each GC cycle. - */ -typedef unsigned char GarbageCollectionMark; - -/** Supertype of everything that is allocated on the heap. - */ -struct HeapEntity { - GarbageCollectionMark mark; - virtual ~HeapEntity() { } -}; - -/** Tagged union of all values. - * - * Primitives (<= 8 bytes) are copied by value. Otherwise a pointer to a HeapEntity is used. - */ -struct Value { - enum Type { - NULL_TYPE = 0x0, // Unfortunately NULL is a macro in C. - BOOLEAN = 0x1, - DOUBLE = 0x2, - - ARRAY = 0x10, - FUNCTION = 0x11, - OBJECT = 0x12, - STRING = 0x13 - }; - Type t; - union { - HeapEntity *h; - double d; - bool b; - } v; - bool isHeap(void) const - { - return t & 0x10; - } -}; - -/** Convert the type into a string, for error messages. */ -std::string type_str(Value::Type t) -{ - switch (t) { - case Value::NULL_TYPE: return "null"; - case Value::BOOLEAN: return "boolean"; - case Value::DOUBLE: return "double"; - case Value::ARRAY: return "array"; - case Value::FUNCTION: return "function"; - case Value::OBJECT: return "object"; - case Value::STRING: return "string"; - default: - std::cerr << "INTERNAL ERROR: Unknown type: " << t << std::endl; - std::abort(); - return ""; // Quiet, compiler. - } -} - -/** Convert the value's type into a string, for error messages. */ -std::string type_str(const Value &v) -{ - return type_str(v.t); -} - -struct HeapThunk; - -/** Stores the values bound to variables. - * - * Each nested local statement, function call, and field access has its own binding frame to - * give the values for the local variable, function parameters, or upValues. - */ -typedef std::map<const Identifier*, HeapThunk*> BindingFrame; - -/** Supertype of all objects. Types of Value::OBJECT will point at these. */ -struct HeapObject : public HeapEntity { -}; - -/** Hold an unevaluated expression. This implements lazy semantics. - */ -struct HeapThunk : public HeapEntity { - /** Whether or not the thunk was forced. */ - bool filled; - - /** The result when the thunk was forced, if filled == true. */ - Value content; - - /** Used in error tracebacks. */ - const Identifier *name; - - /** The captured environment. - * - * Note, this is non-const because we have to add cyclic references to it. - */ - BindingFrame upValues; - - /** The captured self variable, or nullptr if there was none. \see CallFrame. */ - HeapObject *self; - - /** The offset from the captured self variable. \see CallFrame. */ - unsigned offset; - - /** Evaluated to force the thunk. */ - const AST *body; - - HeapThunk(const Identifier *name, HeapObject *self, unsigned offset, const AST *body) - : filled(false), name(name), self(self), offset(offset), body(body) - { } - - void fill(const Value &v) - { - content = v; - filled = true; - self = nullptr; - upValues.clear(); - } -}; - -struct HeapArray : public HeapEntity { - // It is convenient for this to not be const, so that we can add elements to it one at a - // time after creation. Thus, elements are not GCed as the array is being - // created. - std::vector<HeapThunk*> elements; - HeapArray(const std::vector<HeapThunk*> &elements) - : elements(elements) - { } -}; - -/** Supertype of all objects that are not super objects or extended objects. */ -struct HeapLeafObject : public HeapObject { -}; - -/** Objects created via the simple object constructor construct. */ -struct HeapSimpleObject : public HeapLeafObject { - /** The captured environment. */ - const BindingFrame upValues; - - struct Field { - /** Will the field appear in output? */ - ObjectField::Hide hide; - /** Expression that is evaluated when indexing this field. */ - AST *body; - }; - - /** The fields. - * - * These are evaluated in the captured environment and with self and super bound - * dynamically. - */ - const std::map<const Identifier*, Field> fields; - - /** The object's invariants. - * - * These are evaluated in the captured environment with self and super bound. - */ - std::vector<AST*> asserts; - - HeapSimpleObject(const BindingFrame &up_values, - const std::map<const Identifier*, Field> fields, std::vector<AST*> asserts) - : upValues(up_values), fields(fields), asserts(asserts) - { } -}; - -/** Objects created by the + construct. */ -struct HeapExtendedObject : public HeapObject { - /** The left hand side of the construct. */ - HeapObject *left; - - /** The right hand side of the construct. */ - HeapObject *right; - - HeapExtendedObject(HeapObject *left, HeapObject *right) - : left(left), right(right) - { } -}; - -/** Objects created by the ObjectComprehensionSimple construct. */ -struct HeapComprehensionObject : public HeapLeafObject { - - /** The captured environment. */ - const BindingFrame upValues; - - /** The expression used to compute the field values. */ - const AST* value; - - /** The identifier of bound variable in that construct. */ - const Identifier * const id; - - /** Binding for id. - * - * For each field, holds the value that should be bound to id. This is the corresponding - * array element from the original array used to define this object. This should not really - * be a thunk, but it makes the implementation easier. - * - * It is convenient to make this non-const to allow building up the values one by one, so that - * the garbage collector can see them at each intermediate point. - */ - std::map<const Identifier*, HeapThunk*> compValues; - - HeapComprehensionObject(const BindingFrame &up_values, const AST *value, - const Identifier *id, - const std::map<const Identifier*, HeapThunk*> &comp_values) - : upValues(up_values), value(value), id(id), compValues(comp_values) - { } -}; - -/** Stores the function itself and also the captured environment. - * - * Either body is non-null and builtinName is "", or body is null and builtin refers to a built-in - * function. In the former case, the closure represents a user function, otherwise calling it - * will trigger the builtin function to execute. Params is empty when the function is a - * builtin. - */ -struct HeapClosure : public HeapEntity { - /** The captured environment. */ - const BindingFrame upValues; - /** The captured self variable, or nullptr if there was none. \see Frame. */ - HeapObject *self; - /** The offset from the captured self variable. \see Frame.*/ - unsigned offset; - struct Param { - const Identifier *id; - const AST *def; - Param(const Identifier *id, const AST *def) - : id(id), def(def) - { } - }; - typedef std::vector<Param> Params; - const Params params; - const AST *body; - std::string builtinName; - HeapClosure(const BindingFrame &up_values, - HeapObject *self, - unsigned offset, - const Params ¶ms, - const AST *body, const std::string &builtin_name) - : upValues(up_values), self(self), offset(offset), - params(params), body(body), builtinName(builtin_name) - { } -}; - -/** Stores a simple string on the heap. */ -struct HeapString : public HeapEntity { - const UString value; - HeapString(const UString &value) - : value(value) - { } -}; - -/** The heap does memory management, i.e. garbage collection. */ -class Heap { - - /** How many objects must exist in the heap before we bother doing garbage collection? - */ - unsigned gcTuneMinObjects; - - /** How much must the heap have grown since the last cycle to trigger a collection? - */ - double gcTuneGrowthTrigger; - - /** Value used to mark entities at the last garbage collection cycle. */ - GarbageCollectionMark lastMark; - - /** The heap entities (strings, arrays, objects, functions, etc). - * - * Not all may be reachable, all should have o->mark == this->lastMark. Entities are - * removed from the heap via O(1) swap with last element, so the ordering of entities is - * arbitrary and changes every garbage collection cycle. - */ - std::vector<HeapEntity*> entities; - - /** The number of heap entities at the last garbage collection cycle. */ - unsigned long lastNumEntities; - - /** The number of heap entities now. */ - unsigned long numEntities; - - /** Add the HeapEntity inside v to vec, if the value exists on the heap. - */ - void addIfHeapEntity(Value v, std::vector<HeapEntity*> &vec) - { - if (v.isHeap()) vec.push_back(v.v.h); - } - - /** Add the HeapEntity inside v to vec, if the value exists on the heap. - */ - void addIfHeapEntity(HeapEntity *v, std::vector<HeapEntity*> &vec) - { - vec.push_back(v); - } - - public: - - Heap(unsigned gc_tune_min_objects, double gc_tune_growth_trigger) - : gcTuneMinObjects(gc_tune_min_objects), gcTuneGrowthTrigger(gc_tune_growth_trigger), - lastMark(0), lastNumEntities(0), numEntities(0) - { - } - - ~Heap(void) - { - // Nothing is marked, everything will be collected. - sweep(); - } - - /** Garbage collection: Mark v, and entities reachable from v. */ - void markFrom(Value v) - { - if (v.isHeap()) markFrom(v.v.h); - } - - /** Garbage collection: Mark heap entities reachable from the given heap entity. */ - void markFrom(HeapEntity *from) - { - assert(from != nullptr); - const GarbageCollectionMark thisMark = lastMark + 1; - struct State { - HeapEntity *ent; - std::vector<HeapEntity*> children; - State(HeapEntity *ent) : ent(ent) { } - }; - - std::vector<State> stack; - stack.emplace_back(from); - - while (stack.size() > 0) { - size_t curr_index = stack.size() - 1; - State &s = stack[curr_index]; - HeapEntity *curr = s.ent; - if (curr->mark != thisMark) { - curr->mark = thisMark; - - if (auto *obj = dynamic_cast<HeapSimpleObject*>(curr)) { - for (auto upv : obj->upValues) - addIfHeapEntity(upv.second, s.children); - - } else if (auto *obj = dynamic_cast<HeapExtendedObject*>(curr)) { - addIfHeapEntity(obj->left, s.children); - addIfHeapEntity(obj->right, s.children); - - } else if (auto *obj = dynamic_cast<HeapComprehensionObject*>(curr)) { - for (auto upv : obj->upValues) - addIfHeapEntity(upv.second, s.children); - for (auto upv : obj->compValues) - addIfHeapEntity(upv.second, s.children); - - - } else if (auto *arr = dynamic_cast<HeapArray*>(curr)) { - for (auto el : arr->elements) - addIfHeapEntity(el, s.children); - - } else if (auto *func = dynamic_cast<HeapClosure*>(curr)) { - for (auto upv : func->upValues) - addIfHeapEntity(upv.second, s.children); - if (func->self) - addIfHeapEntity(func->self, s.children); - - } else if (auto *thunk = dynamic_cast<HeapThunk*>(curr)) { - if (thunk->filled) { - if (thunk->content.isHeap()) - addIfHeapEntity(thunk->content.v.h, s.children); - } else { - for (auto upv : thunk->upValues) - addIfHeapEntity(upv.second, s.children); - if (thunk->self) - addIfHeapEntity(thunk->self, s.children); - } - } - } - - if (s.children.size() > 0) { - HeapEntity *next = s.children[s.children.size() - 1]; - s.children.pop_back(); - stack.emplace_back(next); // CAUTION: s invalidated here - } else { - stack.pop_back(); // CAUTION: s invalidated here - } - } - } - - /** Delete everything that was not marked since the last collection. */ - void sweep(void) - { - lastMark++; - // Heap shrinks during this loop. Do not cache entities.size(). - for (unsigned long i=0 ; i<entities.size() ; ++i) { - HeapEntity *x = entities[i]; - if (x->mark != lastMark) { - delete x; - if (i != entities.size() - 1) { - // Swap it with the back. - entities[i] = entities[entities.size()-1]; - } - entities.pop_back(); - --i; - } - } - lastNumEntities = numEntities = entities.size(); - } - - /** Is it time to initiate a GC cycle? */ - bool checkHeap(void) - { - return numEntities > gcTuneMinObjects - && numEntities > gcTuneGrowthTrigger * lastNumEntities; - } - - /** Allocate a heap entity. - * - * If the heap is large enough (\see gcTuneMinObjects) and has grown by enough since the - * last collection cycle (\see gcTuneGrowthTrigger), a collection cycle is performed. - */ - template <class T, class... Args> T* makeEntity(Args&&... args) - { - T *r = new T(std::forward<Args>(args)...); - entities.push_back(r); - r->mark = lastMark; - numEntities = entities.size(); - return r; - } - -}; - -} // namespace - -#endif // JSONNET_STATE_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/static_analysis.cpp b/vendor/github.com/strickyak/jsonnet_cgo/static_analysis.cpp deleted file mode 100644 index 9f234f6b79867ab4783de449f579bc6e37111211..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/static_analysis.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <set> - -#include "static_analysis.h" -#include "static_error.h" -#include "ast.h" - -typedef std::set<const Identifier *> IdSet; - -/** Inserts all of s into r. */ -static void append(IdSet &r, const IdSet &s) -{ - r.insert(s.begin(), s.end()); -} - -/** Statically analyse the given ast. - * - * \param ast_ The AST. - * \param in_object Whether or not ast_ is within the lexical scope of an object AST. - * \param vars The variables defined within lexical scope of ast_. - * \returns The free variables in ast_. - */ -static IdSet static_analysis(AST *ast_, bool in_object, const IdSet &vars) -{ - IdSet r; - - if (auto *ast = dynamic_cast<const Apply*>(ast_)) { - append(r, static_analysis(ast->target, in_object, vars)); - for (const auto &arg : ast->args) - append(r, static_analysis(arg.expr, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Array*>(ast_)) { - for (auto & el : ast->elements) - append(r, static_analysis(el.expr, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Binary*>(ast_)) { - append(r, static_analysis(ast->left, in_object, vars)); - append(r, static_analysis(ast->right, in_object, vars)); - - } else if (dynamic_cast<const BuiltinFunction*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<const Conditional*>(ast_)) { - append(r, static_analysis(ast->cond, in_object, vars)); - append(r, static_analysis(ast->branchTrue, in_object, vars)); - append(r, static_analysis(ast->branchFalse, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Error*>(ast_)) { - append(r, static_analysis(ast->expr, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Function*>(ast_)) { - auto new_vars = vars; - IdSet params; - for (const auto &p : ast->params) { - if (params.find(p.id) != params.end()) { - std::string msg = "Duplicate function parameter: " + encode_utf8(p.id->name); - throw StaticError(ast_->location, msg); - } - params.insert(p.id); - new_vars.insert(p.id); - } - - auto fv = static_analysis(ast->body, in_object, new_vars); - for (const auto &p : ast->params) { - if (p.expr != nullptr) - append(fv, static_analysis(p.expr, in_object, new_vars)); - } - for (const auto &p : ast->params) - fv.erase(p.id); - append(r, fv); - - } else if (dynamic_cast<const Import*>(ast_)) { - // Nothing to do. - - } else if (dynamic_cast<const Importstr*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<const InSuper*>(ast_)) { - if (!in_object) - throw StaticError(ast_->location, "Can't use super outside of an object."); - append(r, static_analysis(ast->element, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Index*>(ast_)) { - append(r, static_analysis(ast->target, in_object, vars)); - append(r, static_analysis(ast->index, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Local*>(ast_)) { - IdSet ast_vars; - for (const auto &bind: ast->binds) { - ast_vars.insert(bind.var); - } - auto new_vars = vars; - append(new_vars, ast_vars); - IdSet fvs; - for (const auto &bind: ast->binds) { - append(fvs, static_analysis(bind.body, in_object, new_vars)); - } - - append(fvs, static_analysis(ast->body, in_object, new_vars)); - - for (const auto &bind: ast->binds) - fvs.erase(bind.var); - - append(r, fvs); - - } else if (dynamic_cast<const LiteralBoolean*>(ast_)) { - // Nothing to do. - - } else if (dynamic_cast<const LiteralNumber*>(ast_)) { - // Nothing to do. - - } else if (dynamic_cast<const LiteralString*>(ast_)) { - // Nothing to do. - - } else if (dynamic_cast<const LiteralNull*>(ast_)) { - // Nothing to do. - - } else if (auto *ast = dynamic_cast<DesugaredObject*>(ast_)) { - for (auto &field : ast->fields) { - append(r, static_analysis(field.name, in_object, vars)); - append(r, static_analysis(field.body, true, vars)); - } - for (AST *assert : ast->asserts) { - append(r, static_analysis(assert, true, vars)); - } - - } else if (auto *ast = dynamic_cast<ObjectComprehensionSimple*>(ast_)) { - auto new_vars = vars; - new_vars.insert(ast->id); - append(r, static_analysis(ast->field, false, new_vars)); - append(r, static_analysis(ast->value, true, new_vars)); - r.erase(ast->id); - append(r, static_analysis(ast->array, in_object, vars)); - - } else if (dynamic_cast<const Self*>(ast_)) { - if (!in_object) - throw StaticError(ast_->location, "Can't use self outside of an object."); - - } else if (auto *ast = dynamic_cast<const SuperIndex*>(ast_)) { - if (!in_object) - throw StaticError(ast_->location, "Can't use super outside of an object."); - append(r, static_analysis(ast->index, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Unary*>(ast_)) { - append(r, static_analysis(ast->expr, in_object, vars)); - - } else if (auto *ast = dynamic_cast<const Var*>(ast_)) { - if (vars.find(ast->id) == vars.end()) { - throw StaticError(ast->location, "Unknown variable: "+encode_utf8(ast->id->name)); - } - r.insert(ast->id); - - } else { - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_ << std::endl; - std::abort(); - - } - - for (auto *id : r) - ast_->freeVariables.push_back(id); - - return r; -} - -void jsonnet_static_analysis(AST *ast) -{ - static_analysis(ast, false, IdSet{}); -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/static_analysis.h b/vendor/github.com/strickyak/jsonnet_cgo/static_analysis.h deleted file mode 100644 index 3368d4e9a78377f6934ba7b5af39eb679da65bdd..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/static_analysis.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_STATIC_ANALYSIS_H -#define JSONNET_STATIC_ANALYSIS_H - -#include "ast.h" - -/** Check the ast for appropriate use of self, super, and correctly bound variables. Also - * initialize the freeVariables member of function and object ASTs. - */ -void jsonnet_static_analysis(AST *ast); - -#endif diff --git a/vendor/github.com/strickyak/jsonnet_cgo/static_error.h b/vendor/github.com/strickyak/jsonnet_cgo/static_error.h deleted file mode 100644 index 1b8b7e837f1a080856b1c2101f0812fd0411a356..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/static_error.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_STATIC_ERROR_H -#define JSONNET_STATIC_ERROR_H - -#include <iostream> -#include <sstream> - -struct Location { - unsigned long line; - unsigned long column; - Location(void) - : line(0), column(0) - { } - Location(unsigned long line_number, unsigned long column) - : line(line_number), column(column) - { } - bool isSet(void) const - { - return line != 0; - } -}; - -static inline std::ostream &operator<<(std::ostream &o, const Location &loc) -{ - o << loc.line << ":" << loc.column; - return o; -} - -struct LocationRange { - std::string file; - Location begin, end; - LocationRange(void) - { } - /** This is useful for special locations, e.g. manifestation entry point. */ - LocationRange(const std::string &msg) - : file(msg) - { } - LocationRange(const std::string &file, const Location &begin, const Location &end) - : file(file), begin(begin), end(end) - { } - bool isSet(void) const - { - return begin.isSet(); - } -}; - -static inline std::ostream &operator<<(std::ostream &o, const LocationRange &loc) -{ - if (loc.file.length() > 0) - o << loc.file; - if (loc.isSet()) { - if (loc.file.length() > 0) - o << ":"; - if (loc.begin.line == loc.end.line) { - if (loc.begin.column == loc.end.column) { - o << loc.begin; - } else { - o << loc.begin << "-" << loc.end.column; - } - } else { - o << "(" << loc.begin << ")-(" << loc.end << ")"; - } - } - return o; -} - -struct StaticError { - LocationRange location; - std::string msg; - StaticError(const std::string &msg) - : msg(msg) - { - } - StaticError(const std::string &filename, const Location &location, const std::string &msg) - : location(filename, location, location), msg(msg) - { - } - StaticError(const LocationRange &location, const std::string &msg) - : location(location), msg(msg) - { - } - - std::string toString() const - { - std::stringstream ss; - if (location.isSet()) { - ss << location << ":"; - } - ss << " " << msg; - return ss.str(); - } -}; - -static inline std::ostream &operator<<(std::ostream &o, const StaticError &err) -{ - o << err.toString(); - return o; -} - -#endif // JSONNET_ERROR_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/std.jsonnet.h b/vendor/github.com/strickyak/jsonnet_cgo/std.jsonnet.h deleted file mode 100644 index 94e44061b155d233cf7945bf5b362c6ccf698e10..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/std.jsonnet.h +++ /dev/null @@ -1,2 +0,0 @@ -47,42,10,67,111,112,121,114,105,103,104,116,32,50,48,49,53,32,71,111,111,103,108,101,32,73,110,99,46,32,65,108,108,32,114,105,103,104,116,115,32,114,101,115,101,114,118,101,100,46,10,10,76,105,99,101,110,115,101,100,32,117,110,100,101,114,32,116,104,101,32,65,112,97,99,104,101,32,76,105,99,101,110,115,101,44,32,86,101,114,115,105,111,110,32,50,46,48,32,40,116,104,101,32,34,76,105,99,101,110,115,101,34,41,59,10,121,111,117,32,109,97,121,32,110,111,116,32,117,115,101,32,116,104,105,115,32,102,105,108,101,32,101,120,99,101,112,116,32,105,110,32,99,111,109,112,108,105,97,110,99,101,32,119,105,116,104,32,116,104,101,32,76,105,99,101,110,115,101,46,10,89,111,117,32,109,97,121,32,111,98,116,97,105,110,32,97,32,99,111,112,121,32,111,102,32,116,104,101,32,76,105,99,101,110,115,101,32,97,116,10,10,32,32,32,32,104,116,116,112,58,47,47,119,119,119,46,97,112,97,99,104,101,46,111,114,103,47,108,105,99,101,110,115,101,115,47,76,73,67,69,78,83,69,45,50,46,48,10,10,85,110,108,101,115,115,32,114,101,113,117,105,114,101,100,32,98,121,32,97,112,112,108,105,99,97,98,108,101,32,108,97,119,32,111,114,32,97,103,114,101,101,100,32,116,111,32,105,110,32,119,114,105,116,105,110,103,44,32,115,111,102,116,119,97,114,101,10,100,105,115,116,114,105,98,117,116,101,100,32,117,110,100,101,114,32,116,104,101,32,76,105,99,101,110,115,101,32,105,115,32,100,105,115,116,114,105,98,117,116,101,100,32,111,110,32,97,110,32,34,65,83,32,73,83,34,32,66,65,83,73,83,44,10,87,73,84,72,79,85,84,32,87,65,82,82,65,78,84,73,69,83,32,79,82,32,67,79,78,68,73,84,73,79,78,83,32,79,70,32,65,78,89,32,75,73,78,68,44,32,101,105,116,104,101,114,32,101,120,112,114,101,115,115,32,111,114,32,105,109,112,108,105,101,100,46,10,83,101,101,32,116,104,101,32,76,105,99,101,110,115,101,32,102,111,114,32,116,104,101,32,115,112,101,99,105,102,105,99,32,108,97,110,103,117,97,103,101,32,103,111,118,101,114,110,105,110,103,32,112,101,114,109,105,115,115,105,111,110,115,32,97,110,100,10,108,105,109,105,116,97,116,105,111,110,115,32,117,110,100,101,114,32,116,104,101,32,76,105,99,101,110,115,101,46,10,42,47,10,10,47,42,32,84,104,105,115,32,105,115,32,116,104,101,32,74,115,111,110,110,101,116,32,115,116,97,110,100,97,114,100,32,108,105,98,114,97,114,121,44,32,97,116,32,108,101,97,115,116,32,116,104,101,32,112,97,114,116,115,32,111,102,32,105,116,32,116,104,97,116,32,97,114,101,32,119,114,105,116,116,101,110,32,105,110,32,74,115,111,110,110,101,116,46,10,32,42,10,32,42,32,84,104,101,114,101,32,97,114,101,32,115,111,109,101,32,110,97,116,105,118,101,32,109,101,116,104,111,100,115,32,97,115,32,119,101,108,108,44,32,119,104,105,99,104,32,97,114,101,32,100,101,102,105,110,101,100,32,105,110,32,116,104,101,32,105,110,116,101,114,112,114,101,116,101,114,32,97,110,100,32,97,100,100,101,100,32,116,111,32,116,104,105,115,10,32,42,32,102,105,108,101,46,32,32,73,116,32,105,115,32,110,101,118,101,114,32,110,101,99,101,115,115,97,114,121,32,116,111,32,105,109,112,111,114,116,32,115,116,100,46,106,115,111,110,110,101,116,44,32,105,116,32,105,115,32,101,109,98,101,100,100,101,100,32,105,110,116,111,32,116,104,101,32,105,110,116,101,114,112,114,101,116,101,114,32,97,116,10,32,42,32,99,111,109,112,105,108,101,45,116,105,109,101,32,97,110,100,32,97,117,116,111,109,97,116,105,99,97,108,108,121,32,105,109,112,111,114,116,101,100,32,105,110,116,111,32,97,108,108,32,111,116,104,101,114,32,74,115,111,110,110,101,116,32,112,114,111,103,114,97,109,115,46,10,32,42,47,10,123,10,10,32,32,32,32,108,111,99,97,108,32,115,116,100,32,61,32,115,101,108,102,44,10,10,32,32,32,32,116,111,83,116,114,105,110,103,40,97,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,97,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,32,97,32,101,108,115,101,32,34,34,32,43,32,97,44,10,10,32,32,32,32,115,117,98,115,116,114,40,115,116,114,44,32,102,114,111,109,44,32,108,101,110,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,115,116,114,41,32,33,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,117,98,115,116,114,32,102,105,114,115,116,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,115,116,114,105,110,103,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,115,116,114,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,102,114,111,109,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,117,98,115,116,114,32,115,101,99,111,110,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,102,114,111,109,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,108,101,110,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,117,98,115,116,114,32,116,104,105,114,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,108,101,110,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,108,101,110,32,60,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,117,98,115,116,114,32,116,104,105,114,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,103,114,101,97,116,101,114,32,116,104,97,110,32,122,101,114,111,44,32,103,111,116,32,34,32,43,32,108,101,110,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,34,44,32,115,116,100,46,109,97,107,101,65,114,114,97,121,40,108,101,110,44,32,102,117,110,99,116,105,111,110,40,105,41,32,115,116,114,91,105,32,43,32,102,114,111,109,93,41,41,44,10,10,32,32,32,32,115,116,97,114,116,115,87,105,116,104,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,97,41,32,60,32,115,116,100,46,108,101,110,103,116,104,40,98,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,115,117,98,115,116,114,40,97,44,32,48,44,32,115,116,100,46,108,101,110,103,116,104,40,98,41,41,32,61,61,32,98,44,10,10,32,32,32,32,101,110,100,115,87,105,116,104,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,97,41,32,60,32,115,116,100,46,108,101,110,103,116,104,40,98,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,115,117,98,115,116,114,40,97,44,32,115,116,100,46,108,101,110,103,116,104,40,97,41,32,45,32,115,116,100,46,108,101,110,103,116,104,40,98,41,44,32,115,116,100,46,108,101,110,103,116,104,40,98,41,41,32,61,61,32,98,44,10,10,32,32,32,32,115,116,114,105,110,103,67,104,97,114,115,40,115,116,114,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,109,97,107,101,65,114,114,97,121,40,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,44,32,102,117,110,99,116,105,111,110,40,105,41,32,115,116,114,91,105,93,41,44,10,10,32,32,32,32,112,97,114,115,101,73,110,116,40,115,116,114,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,100,100,68,105,103,105,116,40,97,103,103,114,101,103,97,116,101,44,32,100,105,103,105,116,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,100,105,103,105,116,32,60,32,48,32,124,124,32,100,105,103,105,116,32,62,32,57,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,112,97,114,115,101,73,110,116,32,103,111,116,32,115,116,114,105,110,103,32,119,104,105,99,104,32,100,111,101,115,32,110,111,116,32,109,97,116,99,104,32,114,101,103,101,120,32,91,48,45,57,93,43,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,49,48,32,42,32,97,103,103,114,101,103,97,116,101,32,43,32,100,105,103,105,116,59,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,111,68,105,103,105,116,115,40,115,116,114,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,91,115,116,100,46,99,111,100,101,112,111,105,110,116,40,99,104,97,114,41,32,45,32,115,116,100,46,99,111,100,101,112,111,105,110,116,40,34,48,34,41,32,102,111,114,32,99,104,97,114,32,105,110,32,115,116,100,46,115,116,114,105,110,103,67,104,97,114,115,40,115,116,114,41,93,59,10,32,32,32,32,32,32,32,32,105,102,32,115,116,114,91,48,93,32,61,61,32,34,45,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,45,115,116,100,46,102,111,108,100,108,40,97,100,100,68,105,103,105,116,44,32,116,111,68,105,103,105,116,115,40,115,116,114,91,49,58,93,41,44,32,48,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,102,111,108,100,108,40,97,100,100,68,105,103,105,116,44,32,116,111,68,105,103,105,116,115,40,115,116,114,41,44,32,48,41,44,10,10,32,32,32,32,115,112,108,105,116,40,115,116,114,44,32,99,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,115,116,114,41,32,33,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,32,102,105,114,115,116,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,115,116,114,105,110,103,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,115,116,114,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,99,41,32,33,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,32,115,101,99,111,110,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,115,116,114,105,110,103,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,99,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,99,41,32,33,61,32,49,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,32,115,101,99,111,110,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,104,97,118,101,32,108,101,110,103,116,104,32,49,44,32,103,111,116,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,99,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,115,112,108,105,116,76,105,109,105,116,40,115,116,114,44,32,99,44,32,45,49,41,44,10,10,32,32,32,32,115,112,108,105,116,76,105,109,105,116,40,115,116,114,44,32,99,44,32,109,97,120,115,112,108,105,116,115,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,115,116,114,41,32,33,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,76,105,109,105,116,32,102,105,114,115,116,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,115,116,114,105,110,103,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,115,116,114,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,99,41,32,33,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,76,105,109,105,116,32,115,101,99,111,110,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,115,116,114,105,110,103,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,99,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,99,41,32,33,61,32,49,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,76,105,109,105,116,32,115,101,99,111,110,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,104,97,118,101,32,108,101,110,103,116,104,32,49,44,32,103,111,116,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,99,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,109,97,120,115,112,108,105,116,115,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,115,112,108,105,116,76,105,109,105,116,32,116,104,105,114,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,109,97,120,115,112,108,105,116,115,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,115,116,114,44,32,100,101,108,105,109,44,32,105,44,32,97,114,114,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,105,50,32,61,32,105,32,43,32,49,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,114,114,32,43,32,91,118,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,100,101,108,105,109,32,38,38,32,40,109,97,120,115,112,108,105,116,115,32,61,61,32,45,49,32,124,124,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,60,32,109,97,120,115,112,108,105,116,115,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,100,101,108,105,109,44,32,105,50,44,32,97,114,114,32,43,32,91,118,93,44,32,34,34,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,100,101,108,105,109,44,32,105,50,44,32,97,114,114,44,32,118,32,43,32,99,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,99,44,32,48,44,32,91,93,44,32,34,34,41,44,10,10,32,32,32,32,114,97,110,103,101,40,102,114,111,109,44,32,116,111,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,109,97,107,101,65,114,114,97,121,40,116,111,32,45,32,102,114,111,109,32,43,32,49,44,32,102,117,110,99,116,105,111,110,40,105,41,32,105,32,43,32,102,114,111,109,41,44,10,10,32,32,32,32,115,108,105,99,101,40,105,110,100,101,120,97,98,108,101,44,32,105,110,100,101,120,44,32,101,110,100,44,32,115,116,101,112,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,105,110,118,97,114,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,108,111,111,112,32,105,110,118,97,114,105,97,110,116,32,119,105,116,104,32,100,101,102,97,117,108,116,115,32,97,112,112,108,105,101,100,10,32,32,32,32,32,32,32,32,32,32,32,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,110,100,101,120,97,98,108,101,58,32,105,110,100,101,120,97,98,108,101,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,110,100,101,120,58,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,110,100,101,120,32,61,61,32,110,117,108,108,32,116,104,101,110,32,48,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,110,100,101,120,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,110,100,58,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,101,110,100,32,61,61,32,110,117,108,108,32,116,104,101,110,32,115,116,100,46,108,101,110,103,116,104,40,105,110,100,101,120,97,98,108,101,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,101,110,100,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,101,112,58,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,101,112,32,61,61,32,110,117,108,108,32,116,104,101,110,32,49,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,115,116,101,112,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,101,110,103,116,104,58,32,115,116,100,46,108,101,110,103,116,104,40,105,110,100,101,120,97,98,108,101,41,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,121,112,101,58,32,115,116,100,46,116,121,112,101,40,105,110,100,101,120,97,98,108,101,41,44,10,32,32,32,32,32,32,32,32,32,32,32,32,125,59,10,32,32,32,32,32,32,32,32,105,102,32,105,110,118,97,114,46,105,110,100,101,120,32,60,32,48,32,124,124,32,105,110,118,97,114,46,101,110,100,32,60,32,48,32,124,124,32,105,110,118,97,114,46,115,116,101,112,32,60,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,103,111,116,32,91,37,115,58,37,115,58,37,115,93,32,98,117,116,32,110,101,103,97,116,105,118,101,32,105,110,100,101,120,44,32,101,110,100,44,32,97,110,100,32,115,116,101,112,115,32,97,114,101,32,110,111,116,32,115,117,112,112,111,114,116,101,100,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,37,32,91,105,110,118,97,114,46,105,110,100,101,120,44,32,105,110,118,97,114,46,101,110,100,44,32,105,110,118,97,114,46,115,116,101,112,93,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,101,112,32,61,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,103,111,116,32,37,115,32,98,117,116,32,115,116,101,112,32,109,117,115,116,32,98,101,32,103,114,101,97,116,101,114,32,116,104,97,110,32,48,34,32,37,32,115,116,101,112,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,105,110,100,101,120,97,98,108,101,41,32,33,61,32,34,115,116,114,105,110,103,34,32,38,38,32,115,116,100,46,116,121,112,101,40,105,110,100,101,120,97,98,108,101,41,32,33,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,115,116,100,46,115,108,105,99,101,32,97,99,99,101,112,116,115,32,97,32,115,116,114,105,110,103,32,111,114,32,97,110,32,97,114,114,97,121,44,32,98,117,116,32,103,111,116,58,32,37,115,34,32,37,32,115,116,100,46,116,121,112,101,40,105,110,100,101,120,97,98,108,101,41,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,98,117,105,108,100,40,115,108,105,99,101,44,32,99,117,114,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,117,114,32,62,61,32,105,110,118,97,114,46,101,110,100,32,124,124,32,99,117,114,32,62,61,32,105,110,118,97,114,46,108,101,110,103,116,104,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,108,105,99,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,117,105,108,100,40,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,110,118,97,114,46,116,121,112,101,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,108,105,99,101,32,43,32,105,110,118,97,114,46,105,110,100,101,120,97,98,108,101,91,99,117,114,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,108,105,99,101,32,43,32,91,105,110,118,97,114,46,105,110,100,101,120,97,98,108,101,91,99,117,114,93,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,117,114,32,43,32,105,110,118,97,114,46,115,116,101,112,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,32,32,32,32,98,117,105,108,100,40,105,102,32,105,110,118,97,114,46,116,121,112,101,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,32,34,34,32,101,108,115,101,32,91,93,44,32,105,110,118,97,114,46,105,110,100,101,120,41,44,10,10,32,32,32,32,99,111,117,110,116,40,97,114,114,44,32,120,41,58,58,32,115,116,100,46,108,101,110,103,116,104,40,115,116,100,46,102,105,108,116,101,114,40,102,117,110,99,116,105,111,110,40,118,41,32,118,32,61,61,32,120,44,32,97,114,114,41,41,44,10,10,32,32,32,32,109,111,100,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,97,41,32,61,61,32,34,110,117,109,98,101,114,34,32,38,38,32,115,116,100,46,116,121,112,101,40,98,41,32,61,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,109,111,100,117,108,111,40,97,44,32,98,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,97,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,102,111,114,109,97,116,40,97,44,32,98,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,79,112,101,114,97,116,111,114,32,37,32,99,97,110,110,111,116,32,98,101,32,117,115,101,100,32,111,110,32,116,121,112,101,115,32,34,32,43,32,115,116,100,46,116,121,112,101,40,97,41,32,43,32,34,32,97,110,100,32,34,32,43,32,115,116,100,46,116,121,112,101,40,98,41,32,43,32,34,46,34,44,10,10,32,32,32,32,109,97,112,40,102,117,110,99,44,32,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,102,117,110,99,41,32,33,61,32,34,102,117,110,99,116,105,111,110,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,115,116,100,46,109,97,112,32,102,105,114,115,116,32,112,97,114,97,109,32,109,117,115,116,32,98,101,32,102,117,110,99,116,105,111,110,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,102,117,110,99,41,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,97,114,114,41,32,33,61,32,34,97,114,114,97,121,34,32,38,38,32,115,116,100,46,116,121,112,101,40,97,114,114,41,32,33,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,115,116,100,46,109,97,112,32,115,101,99,111,110,100,32,112,97,114,97,109,32,109,117,115,116,32,98,101,32,97,114,114,97,121,32,47,32,115,116,114,105,110,103,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,97,114,114,41,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,109,97,107,101,65,114,114,97,121,40,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,44,32,102,117,110,99,116,105,111,110,40,105,41,32,102,117,110,99,40,97,114,114,91,105,93,41,41,44,10,10,32,32,32,32,106,111,105,110,40,115,101,112,44,32,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,97,114,114,44,32,105,44,32,102,105,114,115,116,44,32,114,117,110,110,105,110,103,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,117,110,110,105,110,103,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,97,114,114,91,105,93,32,61,61,32,110,117,108,108,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,105,32,43,32,49,44,32,102,105,114,115,116,44,32,114,117,110,110,105,110,103,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,102,105,114,115,116,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,105,32,43,32,49,44,32,102,97,108,115,101,44,32,114,117,110,110,105,110,103,32,43,32,97,114,114,91,105,93,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,105,32,43,32,49,44,32,102,97,108,115,101,44,32,114,117,110,110,105,110,103,32,43,32,115,101,112,32,43,32,97,114,114,91,105,93,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,97,114,114,41,32,33,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,106,111,105,110,32,115,101,99,111,110,100,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,97,114,114,97,121,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,97,114,114,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,115,101,112,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,48,44,32,116,114,117,101,44,32,34,34,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,115,101,112,41,32,61,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,48,44,32,116,114,117,101,44,32,91,93,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,106,111,105,110,32,102,105,114,115,116,32,112,97,114,97,109,101,116,101,114,32,115,104,111,117,108,100,32,98,101,32,115,116,114,105,110,103,32,111,114,32,97,114,114,97,121,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,115,101,112,41,44,10,10,32,32,32,32,108,105,110,101,115,40,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,92,110,34,44,32,97,114,114,32,43,32,91,34,34,93,41,44,10,10,32,32,32,32,102,111,114,109,97,116,40,115,116,114,44,32,118,97,108,115,41,58,58,10,10,32,32,32,32,32,32,32,32,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,10,32,32,32,32,32,32,32,32,47,47,32,80,97,114,115,101,32,116,104,101,32,109,105,110,105,45,108,97,110,103,117,97,103,101,32,47,47,10,32,32,32,32,32,32,32,32,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,121,95,112,97,114,115,101,95,109,97,112,112,105,110,103,95,107,101,121,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,40,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,106,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,33,61,32,34,41,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,43,32,99,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,106,32,43,32,49,44,32,118,58,32,118,32,125,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,105,32,43,32,49,44,32,34,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,44,32,118,58,32,110,117,108,108,32,125,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,121,95,112,97,114,115,101,95,99,102,108,97,103,115,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,106,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,35,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,123,32,97,108,116,58,32,116,114,117,101,32,125,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,48,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,123,32,122,101,114,111,58,32,116,114,117,101,32,125,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,45,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,123,32,108,101,102,116,58,32,116,114,117,101,32,125,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,32,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,123,32,98,108,97,110,107,58,32,116,114,117,101,32,125,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,43,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,123,32,115,105,103,110,58,32,116,114,117,101,32,125,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,106,44,32,118,58,32,118,32,125,59,10,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,105,44,32,123,32,97,108,116,58,32,102,97,108,115,101,44,32,122,101,114,111,58,32,102,97,108,115,101,44,32,108,101,102,116,58,32,102,97,108,115,101,44,32,98,108,97,110,107,58,32,102,97,108,115,101,44,32,115,105,103,110,58,32,102,97,108,115,101,32,125,41,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,121,95,112,97,114,115,101,95,102,105,101,108,100,95,119,105,100,116,104,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,60,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,38,38,32,115,116,114,91,105,93,32,61,61,32,34,42,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,42,34,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,106,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,48,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,48,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,49,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,49,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,50,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,50,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,51,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,51,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,52,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,52,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,53,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,53,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,54,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,54,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,55,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,55,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,56,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,56,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,57,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,106,32,43,32,49,44,32,118,32,42,32,49,48,32,43,32,57,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,106,44,32,118,58,32,118,32,125,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,110,115,117,109,101,40,115,116,114,44,32,105,44,32,48,41,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,121,95,112,97,114,115,101,95,112,114,101,99,105,115,105,111,110,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,46,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,114,121,95,112,97,114,115,101,95,102,105,101,108,100,95,119,105,100,116,104,40,115,116,114,44,32,105,32,43,32,49,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,44,32,118,58,32,110,117,108,108,32,125,59,10,10,32,32,32,32,32,32,32,32,47,47,32,73,103,110,111,114,101,100,44,32,105,102,32,105,116,32,101,120,105,115,116,115,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,121,95,112,97,114,115,101,95,108,101,110,103,116,104,95,109,111,100,105,102,105,101,114,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,104,34,32,124,124,32,99,32,61,61,32,34,108,34,32,124,124,32,99,32,61,61,32,34,76,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,32,43,32,49,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,97,114,115,101,95,99,111,110,118,95,116,121,112,101,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,100,34,32,124,124,32,99,32,61,61,32,34,105,34,32,124,124,32,99,32,61,61,32,34,117,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,100,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,111,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,111,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,120,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,120,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,88,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,120,34,44,32,99,97,112,115,58,32,116,114,117,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,101,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,101,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,69,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,101,34,44,32,99,97,112,115,58,32,116,114,117,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,102,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,102,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,70,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,102,34,44,32,99,97,112,115,58,32,116,114,117,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,103,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,71,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,103,34,44,32,99,97,112,115,58,32,116,114,117,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,99,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,99,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,115,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,115,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,32,61,61,32,34,37,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,32,105,58,32,105,32,43,32,49,44,32,118,58,32,34,37,34,44,32,99,97,112,115,58,32,102,97,108,115,101,32,125,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,85,110,114,101,99,111,103,110,105,115,101,100,32,99,111,110,118,101,114,115,105,111,110,32,116,121,112,101,58,32,34,32,43,32,99,59,10,10,10,32,32,32,32,32,32,32,32,47,47,32,80,97,114,115,101,100,32,105,110,105,116,105,97,108,32,37,44,32,110,111,119,32,116,104,101,32,114,101,115,116,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,97,114,115,101,95,99,111,100,101,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,117,110,99,97,116,101,100,32,102,111,114,109,97,116,32,99,111,100,101,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,109,107,101,121,32,61,32,116,114,121,95,112,97,114,115,101,95,109,97,112,112,105,110,103,95,107,101,121,40,115,116,114,44,32,105,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,102,108,97,103,115,32,61,32,116,114,121,95,112,97,114,115,101,95,99,102,108,97,103,115,40,115,116,114,44,32,109,107,101,121,46,105,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,119,32,61,32,116,114,121,95,112,97,114,115,101,95,102,105,101,108,100,95,119,105,100,116,104,40,115,116,114,44,32,99,102,108,97,103,115,46,105,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,114,101,99,32,61,32,116,114,121,95,112,97,114,115,101,95,112,114,101,99,105,115,105,111,110,40,115,116,114,44,32,102,119,46,105,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,101,110,95,109,111,100,32,61,32,116,114,121,95,112,97,114,115,101,95,108,101,110,103,116,104,95,109,111,100,105,102,105,101,114,40,115,116,114,44,32,112,114,101,99,46,105,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,116,121,112,101,32,61,32,112,97,114,115,101,95,99,111,110,118,95,116,121,112,101,40,115,116,114,44,32,108,101,110,95,109,111,100,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,58,32,99,116,121,112,101,46,105,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,100,101,58,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,109,107,101,121,58,32,109,107,101,121,46,118,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,102,108,97,103,115,58,32,99,102,108,97,103,115,46,118,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,119,58,32,102,119,46,118,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,101,99,58,32,112,114,101,99,46,118,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,116,121,112,101,58,32,99,116,121,112,101,46,118,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,97,112,115,58,32,99,116,121,112,101,46,99,97,112,115,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,125,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,125,59,10,10,32,32,32,32,32,32,32,32,47,47,32,80,97,114,115,101,32,97,32,102,111,114,109,97,116,32,115,116,114,105,110,103,32,40,99,111,110,116,97,105,110,105,110,103,32,110,111,110,101,32,111,114,32,109,111,114,101,32,37,32,102,111,114,109,97,116,32,116,97,103,115,41,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,97,114,115,101,95,99,111,100,101,115,40,115,116,114,44,32,105,44,32,111,117,116,44,32,99,117,114,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,111,117,116,32,43,32,91,99,117,114,93,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,32,61,32,115,116,114,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,32,61,61,32,34,37,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,32,61,32,112,97,114,115,101,95,99,111,100,101,40,115,116,114,44,32,105,32,43,32,49,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,114,115,101,95,99,111,100,101,115,40,115,116,114,44,32,114,46,105,44,32,111,117,116,32,43,32,91,99,117,114,44,32,114,46,99,111,100,101,93,44,32,34,34,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,114,115,101,95,99,111,100,101,115,40,115,116,114,44,32,105,32,43,32,49,44,32,111,117,116,44,32,99,117,114,32,43,32,99,41,32,116,97,105,108,115,116,114,105,99,116,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,111,100,101,115,32,61,32,112,97,114,115,101,95,99,111,100,101,115,40,115,116,114,44,32,48,44,32,91,93,44,32,34,34,41,59,10,10,10,32,32,32,32,32,32,32,32,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,10,32,32,32,32,32,32,32,32,47,47,32,70,111,114,109,97,116,32,116,104,101,32,118,97,108,117,101,115,32,47,47,10,32,32,32,32,32,32,32,32,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,10,10,32,32,32,32,32,32,32,32,47,47,32,85,115,101,102,117,108,32,117,116,105,108,105,116,105,101,115,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,97,100,100,105,110,103,40,119,44,32,115,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,119,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,119,32,60,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,118,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,119,32,45,32,49,44,32,118,32,43,32,115,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,119,44,32,34,34,41,59,10,10,32,32,32,32,32,32,32,32,47,47,32,65,100,100,32,115,32,116,111,32,116,104,101,32,108,101,102,116,32,111,102,32,115,116,114,32,115,111,32,116,104,97,116,32,105,116,115,32,108,101,110,103,116,104,32,105,115,32,97,116,32,108,101,97,115,116,32,119,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,97,100,95,108,101,102,116,40,115,116,114,44,32,119,44,32,115,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,112,97,100,100,105,110,103,40,119,32,45,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,44,32,115,41,32,43,32,115,116,114,59,10,10,32,32,32,32,32,32,32,32,47,47,32,65,100,100,32,115,32,116,111,32,116,104,101,32,114,105,103,104,116,32,111,102,32,115,116,114,32,115,111,32,116,104,97,116,32,105,116,115,32,108,101,110,103,116,104,32,105,115,32,97,116,32,108,101,97,115,116,32,119,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,97,100,95,114,105,103,104,116,40,115,116,114,44,32,119,44,32,115,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,114,32,43,32,112,97,100,100,105,110,103,40,119,32,45,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,44,32,115,41,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,97,110,32,105,110,116,101,103,101,114,32,40,101,46,103,46,44,32,100,101,99,105,109,97,108,32,111,114,32,111,99,116,97,108,41,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,101,110,100,101,114,95,105,110,116,40,110,95,95,44,32,109,105,110,95,99,104,97,114,115,44,32,109,105,110,95,100,105,103,105,116,115,44,32,98,108,97,110,107,44,32,115,105,103,110,44,32,114,97,100,105,120,44,32,122,101,114,111,95,112,114,101,102,105,120,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,95,32,61,32,115,116,100,46,97,98,115,40,110,95,95,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,110,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,110,32,61,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,122,101,114,111,95,112,114,101,102,105,120,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,100,46,102,108,111,111,114,40,110,32,47,32,114,97,100,105,120,41,41,32,43,32,40,110,32,37,32,114,97,100,105,120,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,100,101,99,32,61,32,105,102,32,115,116,100,46,102,108,111,111,114,40,110,95,41,32,61,61,32,48,32,116,104,101,110,32,34,48,34,32,101,108,115,101,32,97,117,120,40,115,116,100,46,102,108,111,111,114,40,110,95,41,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,101,103,32,61,32,110,95,95,32,60,32,48,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,32,61,32,109,105,110,95,99,104,97,114,115,32,45,32,40,105,102,32,110,101,103,32,124,124,32,98,108,97,110,107,32,124,124,32,115,105,103,110,32,116,104,101,110,32,49,32,101,108,115,101,32,48,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,50,32,61,32,115,116,100,46,109,97,120,40,122,112,44,32,109,105,110,95,100,105,103,105,116,115,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,100,101,99,50,32,61,32,112,97,100,95,108,101,102,116,40,100,101,99,44,32,122,112,50,44,32,34,48,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,40,105,102,32,110,101,103,32,116,104,101,110,32,34,45,34,32,101,108,115,101,32,105,102,32,115,105,103,110,32,116,104,101,110,32,34,43,34,32,101,108,115,101,32,105,102,32,98,108,97,110,107,32,116,104,101,110,32,34,32,34,32,101,108,115,101,32,34,34,41,32,43,32,100,101,99,50,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,97,110,32,105,110,116,101,103,101,114,32,105,110,32,104,101,120,97,100,101,99,105,109,97,108,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,101,110,100,101,114,95,104,101,120,40,110,95,95,44,32,109,105,110,95,99,104,97,114,115,44,32,109,105,110,95,100,105,103,105,116,115,44,32,98,108,97,110,107,44,32,115,105,103,110,44,32,97,100,100,95,122,101,114,111,120,44,32,99,97,112,105,116,97,108,115,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,117,109,101,114,97,108,115,32,61,32,91,48,44,32,49,44,32,50,44,32,51,44,32,52,44,32,53,44,32,54,44,32,55,44,32,56,44,32,57,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,102,32,99,97,112,105,116,97,108,115,32,116,104,101,110,32,91,34,65,34,44,32,34,66,34,44,32,34,67,34,44,32,34,68,34,44,32,34,69,34,44,32,34,70,34,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,91,34,97,34,44,32,34,98,34,44,32,34,99,34,44,32,34,100,34,44,32,34,101,34,44,32,34,102,34,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,95,32,61,32,115,116,100,46,97,98,115,40,110,95,95,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,110,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,110,32,61,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,100,46,102,108,111,111,114,40,110,32,47,32,49,54,41,41,32,43,32,110,117,109,101,114,97,108,115,91,110,32,37,32,49,54,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,104,101,120,32,61,32,105,102,32,115,116,100,46,102,108,111,111,114,40,110,95,41,32,61,61,32,48,32,116,104,101,110,32,34,48,34,32,101,108,115,101,32,97,117,120,40,115,116,100,46,102,108,111,111,114,40,110,95,41,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,101,103,32,61,32,110,95,95,32,60,32,48,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,32,61,32,109,105,110,95,99,104,97,114,115,32,45,32,40,105,102,32,110,101,103,32,124,124,32,98,108,97,110,107,32,124,124,32,115,105,103,110,32,116,104,101,110,32,49,32,101,108,115,101,32,48,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,45,32,40,105,102,32,97,100,100,95,122,101,114,111,120,32,116,104,101,110,32,50,32,101,108,115,101,32,48,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,50,32,61,32,115,116,100,46,109,97,120,40,122,112,44,32,109,105,110,95,100,105,103,105,116,115,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,104,101,120,50,32,61,32,40,105,102,32,97,100,100,95,122,101,114,111,120,32,116,104,101,110,32,40,105,102,32,99,97,112,105,116,97,108,115,32,116,104,101,110,32,34,48,88,34,32,101,108,115,101,32,34,48,120,34,41,32,101,108,115,101,32,34,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,112,97,100,95,108,101,102,116,40,104,101,120,44,32,122,112,50,44,32,34,48,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,40,105,102,32,110,101,103,32,116,104,101,110,32,34,45,34,32,101,108,115,101,32,105,102,32,115,105,103,110,32,116,104,101,110,32,34,43,34,32,101,108,115,101,32,105,102,32,98,108,97,110,107,32,116,104,101,110,32,34,32,34,32,101,108,115,101,32,34,34,41,32,43,32,104,101,120,50,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,105,112,95,116,114,97,105,108,105,110,103,95,122,101,114,111,40,115,116,114,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,115,116,114,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,60,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,114,91,105,93,32,61,61,32,34,48,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,105,32,45,32,49,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,115,117,98,115,116,114,40,115,116,114,44,32,48,44,32,105,32,43,32,49,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,45,32,49,41,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,102,108,111,97,116,105,110,103,32,112,111,105,110,116,32,105,110,32,100,101,99,105,109,97,108,32,102,111,114,109,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,101,110,100,101,114,95,102,108,111,97,116,95,100,101,99,40,110,95,95,44,32,122,101,114,111,95,112,97,100,44,32,98,108,97,110,107,44,32,115,105,103,110,44,32,101,110,115,117,114,101,95,112,116,44,32,116,114,97,105,108,105,110,103,44,32,112,114,101,99,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,95,32,61,32,115,116,100,46,97,98,115,40,110,95,95,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,119,104,111,108,101,32,61,32,115,116,100,46,102,108,111,111,114,40,110,95,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,100,111,116,95,115,105,122,101,32,61,32,105,102,32,112,114,101,99,32,61,61,32,48,32,38,38,32,33,101,110,115,117,114,101,95,112,116,32,116,104,101,110,32,48,32,101,108,115,101,32,49,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,32,61,32,122,101,114,111,95,112,97,100,32,45,32,112,114,101,99,32,45,32,100,111,116,95,115,105,122,101,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,32,114,101,110,100,101,114,95,105,110,116,40,110,95,95,32,47,32,110,95,32,42,32,119,104,111,108,101,44,32,122,112,44,32,48,44,32,98,108,97,110,107,44,32,115,105,103,110,44,32,49,48,44,32,34,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,112,114,101,99,32,61,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,114,32,43,32,105,102,32,101,110,115,117,114,101,95,112,116,32,116,104,101,110,32,34,46,34,32,101,108,115,101,32,34,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,114,97,99,32,61,32,115,116,100,46,102,108,111,111,114,40,40,110,95,32,45,32,119,104,111,108,101,41,32,42,32,115,116,100,46,112,111,119,40,49,48,44,32,112,114,101,99,41,32,43,32,48,46,53,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,116,114,97,105,108,105,110,103,32,124,124,32,102,114,97,99,32,62,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,114,97,99,95,115,116,114,32,61,32,114,101,110,100,101,114,95,105,110,116,40,102,114,97,99,44,32,112,114,101,99,44,32,48,44,32,102,97,108,115,101,44,32,102,97,108,115,101,44,32,49,48,44,32,34,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,114,32,43,32,34,46,34,32,43,32,105,102,32,33,116,114,97,105,108,105,110,103,32,116,104,101,110,32,115,116,114,105,112,95,116,114,97,105,108,105,110,103,95,122,101,114,111,40,102,114,97,99,95,115,116,114,41,32,101,108,115,101,32,102,114,97,99,95,115,116,114,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,114,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,102,108,111,97,116,105,110,103,32,112,111,105,110,116,32,105,110,32,115,99,105,101,110,116,105,102,105,99,32,102,111,114,109,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,101,110,100,101,114,95,102,108,111,97,116,95,115,99,105,40,110,95,95,44,32,122,101,114,111,95,112,97,100,44,32,98,108,97,110,107,44,32,115,105,103,110,44,32,101,110,115,117,114,101,95,112,116,44,32,116,114,97,105,108,105,110,103,44,32,99,97,112,115,44,32,112,114,101,99,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,101,120,112,111,110,101,110,116,32,61,32,115,116,100,46,102,108,111,111,114,40,115,116,100,46,108,111,103,40,115,116,100,46,97,98,115,40,110,95,95,41,41,32,47,32,115,116,100,46,108,111,103,40,49,48,41,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,117,102,102,32,61,32,40,105,102,32,99,97,112,115,32,116,104,101,110,32,34,69,34,32,101,108,115,101,32,34,101,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,114,101,110,100,101,114,95,105,110,116,40,101,120,112,111,110,101,110,116,44,32,51,44,32,48,44,32,102,97,108,115,101,44,32,116,114,117,101,44,32,49,48,44,32,34,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,109,97,110,116,105,115,115,97,32,61,32,110,95,95,32,47,32,115,116,100,46,112,111,119,40,49,48,44,32,101,120,112,111,110,101,110,116,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,50,32,61,32,122,101,114,111,95,112,97,100,32,45,32,115,116,100,46,108,101,110,103,116,104,40,115,117,102,102,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,102,108,111,97,116,95,100,101,99,40,109,97,110,116,105,115,115,97,44,32,122,112,50,44,32,98,108,97,110,107,44,32,115,105,103,110,44,32,101,110,115,117,114,101,95,112,116,44,32,116,114,97,105,108,105,110,103,44,32,112,114,101,99,41,32,43,32,115,117,102,102,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,97,32,118,97,108,117,101,32,119,105,116,104,32,97,110,32,97,114,98,105,116,114,97,114,121,32,102,111,114,109,97,116,32,99,111,100,101,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,111,114,109,97,116,95,99,111,100,101,40,118,97,108,44,32,99,111,100,101,44,32,102,119,44,32,112,114,101,99,95,111,114,95,110,117,108,108,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,102,108,97,103,115,32,61,32,99,111,100,101,46,99,102,108,97,103,115,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,112,112,114,101,99,32,61,32,105,102,32,112,114,101,99,95,111,114,95,110,117,108,108,32,33,61,32,110,117,108,108,32,116,104,101,110,32,112,114,101,99,95,111,114,95,110,117,108,108,32,101,108,115,101,32,54,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,105,112,114,101,99,32,61,32,105,102,32,112,114,101,99,95,111,114,95,110,117,108,108,32,33,61,32,110,117,108,108,32,116,104,101,110,32,112,114,101,99,95,111,114,95,110,117,108,108,32,101,108,115,101,32,48,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,112,32,61,32,105,102,32,99,102,108,97,103,115,46,122,101,114,111,32,38,38,32,33,99,102,108,97,103,115,46,108,101,102,116,32,116,104,101,110,32,102,119,32,101,108,115,101,32,48,59,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,115,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,116,111,83,116,114,105,110,103,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,100,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,70,111,114,109,97,116,32,114,101,113,117,105,114,101,100,32,110,117,109,98,101,114,32,97,116,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,32,43,32,34,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,105,110,116,40,118,97,108,44,32,122,112,44,32,105,112,114,101,99,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,32,99,102,108,97,103,115,46,115,105,103,110,44,32,49,48,44,32,34,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,111,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,70,111,114,109,97,116,32,114,101,113,117,105,114,101,100,32,110,117,109,98,101,114,32,97,116,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,32,43,32,34,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,122,101,114,111,95,112,114,101,102,105,120,32,61,32,105,102,32,99,102,108,97,103,115,46,97,108,116,32,116,104,101,110,32,34,48,34,32,101,108,115,101,32,34,34,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,105,110,116,40,118,97,108,44,32,122,112,44,32,105,112,114,101,99,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,32,99,102,108,97,103,115,46,115,105,103,110,44,32,56,44,32,122,101,114,111,95,112,114,101,102,105,120,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,120,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,70,111,114,109,97,116,32,114,101,113,117,105,114,101,100,32,110,117,109,98,101,114,32,97,116,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,32,43,32,34,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,104,101,120,40,118,97,108,44,32,122,112,44,32,105,112,114,101,99,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,32,99,102,108,97,103,115,46,115,105,103,110,44,32,99,102,108,97,103,115,46,97,108,116,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,100,101,46,99,97,112,115,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,102,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,70,111,114,109,97,116,32,114,101,113,117,105,114,101,100,32,110,117,109,98,101,114,32,97,116,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,32,43,32,34,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,102,108,111,97,116,95,100,101,99,40,118,97,108,44,32,122,112,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,102,108,97,103,115,46,115,105,103,110,44,32,99,102,108,97,103,115,46,97,108,116,44,32,116,114,117,101,44,32,102,112,112,114,101,99,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,101,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,70,111,114,109,97,116,32,114,101,113,117,105,114,101,100,32,110,117,109,98,101,114,32,97,116,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,32,43,32,34,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,102,108,111,97,116,95,115,99,105,40,118,97,108,44,32,122,112,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,102,108,97,103,115,46,115,105,103,110,44,32,99,102,108,97,103,115,46,97,108,116,44,32,116,114,117,101,44,32,99,111,100,101,46,99,97,112,115,44,32,102,112,112,114,101,99,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,70,111,114,109,97,116,32,114,101,113,117,105,114,101,100,32,110,117,109,98,101,114,32,97,116,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,105,32,43,32,34,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,101,120,112,111,110,101,110,116,32,61,32,115,116,100,46,102,108,111,111,114,40,115,116,100,46,108,111,103,40,115,116,100,46,97,98,115,40,118,97,108,41,41,32,47,32,115,116,100,46,108,111,103,40,49,48,41,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,101,120,112,111,110,101,110,116,32,60,32,45,52,32,124,124,32,101,120,112,111,110,101,110,116,32,62,61,32,102,112,112,114,101,99,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,102,108,111,97,116,95,115,99,105,40,118,97,108,44,32,122,112,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,32,99,102,108,97,103,115,46,115,105,103,110,44,32,99,102,108,97,103,115,46,97,108,116,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,102,108,97,103,115,46,97,108,116,44,32,99,111,100,101,46,99,97,112,115,44,32,102,112,112,114,101,99,32,45,32,49,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,100,105,103,105,116,115,95,98,101,102,111,114,101,95,112,116,32,61,32,115,116,100,46,109,97,120,40,49,44,32,101,120,112,111,110,101,110,116,32,43,32,49,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,101,110,100,101,114,95,102,108,111,97,116,95,100,101,99,40,118,97,108,44,32,122,112,44,32,99,102,108,97,103,115,46,98,108,97,110,107,44,32,99,102,108,97,103,115,46,115,105,103,110,44,32,99,102,108,97,103,115,46,97,108,116,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,102,108,97,103,115,46,97,108,116,44,32,102,112,112,114,101,99,32,45,32,100,105,103,105,116,115,95,98,101,102,111,114,101,95,112,116,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,99,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,61,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,99,104,97,114,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,118,97,108,41,32,61,61,32,49,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,118,97,108,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,37,99,32,101,120,112,101,99,116,101,100,32,49,45,115,105,122,101,100,32,115,116,114,105,110,103,32,103,111,116,58,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,37,99,32,101,120,112,101,99,116,101,100,32,110,117,109,98,101,114,32,47,32,115,116,114,105,110,103,44,32,103,111,116,58,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,85,110,107,110,111,119,110,32,99,111,100,101,58,32,34,32,43,32,99,111,100,101,46,99,116,121,112,101,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,97,32,112,97,114,115,101,100,32,102,111,114,109,97,116,32,115,116,114,105,110,103,32,119,105,116,104,32,97,110,32,97,114,114,97,121,32,111,102,32,118,97,108,117,101,115,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,111,114,109,97,116,95,99,111,100,101,115,95,97,114,114,40,99,111,100,101,115,44,32,97,114,114,44,32,105,44,32,106,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,99,111,100,101,115,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,106,32,60,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,84,111,111,32,109,97,110,121,32,118,97,108,117,101,115,32,116,111,32,102,111,114,109,97,116,58,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,43,32,34,44,32,101,120,112,101,99,116,101,100,32,34,32,43,32,106,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,118,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,111,100,101,32,61,32,99,111,100,101,115,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,99,111,100,101,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,97,114,114,40,99,111,100,101,115,44,32,97,114,114,44,32,105,32,43,32,49,44,32,106,44,32,118,32,43,32,99,111,100,101,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,109,112,32,61,32,105,102,32,99,111,100,101,46,102,119,32,61,61,32,34,42,34,32,116,104,101,110,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,106,58,32,106,32,43,32,49,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,119,58,32,105,102,32,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,78,111,116,32,101,110,111,117,103,104,32,118,97,108,117,101,115,32,116,111,32,102,111,114,109,97,116,58,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,114,114,91,106,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,125,32,101,108,115,101,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,106,58,32,106,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,119,58,32,99,111,100,101,46,102,119,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,125,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,109,112,50,32,61,32,105,102,32,99,111,100,101,46,112,114,101,99,32,61,61,32,34,42,34,32,116,104,101,110,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,106,58,32,116,109,112,46,106,32,43,32,49,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,101,99,58,32,105,102,32,116,109,112,46,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,78,111,116,32,101,110,111,117,103,104,32,118,97,108,117,101,115,32,116,111,32,102,111,114,109,97,116,58,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,114,114,91,116,109,112,46,106,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,125,32,101,108,115,101,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,106,58,32,116,109,112,46,106,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,114,101,99,58,32,99,111,100,101,46,112,114,101,99,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,125,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,106,50,32,61,32,116,109,112,50,46,106,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,118,97,108,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,106,50,32,60,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,114,114,91,106,50,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,78,111,116,32,101,110,111,117,103,104,32,118,97,108,117,101,115,32,116,111,32,102,111,114,109,97,116,44,32,103,111,116,32,34,32,43,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,37,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,37,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,40,118,97,108,44,32,99,111,100,101,44,32,116,109,112,46,102,119,44,32,116,109,112,50,46,112,114,101,99,44,32,106,50,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,95,112,97,100,100,101,100,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,99,102,108,97,103,115,46,108,101,102,116,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,100,95,114,105,103,104,116,40,115,44,32,116,109,112,46,102,119,44,32,34,32,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,100,95,108,101,102,116,40,115,44,32,116,109,112,46,102,119,44,32,34,32,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,106,51,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,37,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,106,50,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,106,50,32,43,32,49,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,97,114,114,40,99,111,100,101,115,44,32,97,114,114,44,32,105,32,43,32,49,44,32,106,51,44,32,118,32,43,32,115,95,112,97,100,100,101,100,41,32,116,97,105,108,115,116,114,105,99,116,59,10,10,32,32,32,32,32,32,32,32,47,47,32,82,101,110,100,101,114,32,97,32,112,97,114,115,101,100,32,102,111,114,109,97,116,32,115,116,114,105,110,103,32,119,105,116,104,32,97,110,32,111,98,106,101,99,116,32,111,102,32,118,97,108,117,101,115,46,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,111,114,109,97,116,95,99,111,100,101,115,95,111,98,106,40,99,111,100,101,115,44,32,111,98,106,44,32,105,44,32,118,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,99,111,100,101,115,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,118,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,111,100,101,32,61,32,99,111,100,101,115,91,105,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,99,111,100,101,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,111,98,106,40,99,111,100,101,115,44,32,111,98,106,44,32,105,32,43,32,49,44,32,118,32,43,32,99,111,100,101,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,109,107,101,121,32,61,61,32,110,117,108,108,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,77,97,112,112,105,110,103,32,107,101,121,115,32,114,101,113,117,105,114,101,100,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,100,101,46,109,107,101,121,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,119,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,102,119,32,61,61,32,34,42,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,67,97,110,110,111,116,32,117,115,101,32,42,32,102,105,101,108,100,32,119,105,100,116,104,32,119,105,116,104,32,111,98,106,101,99,116,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,100,101,46,102,119,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,114,101,99,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,112,114,101,99,32,61,61,32,34,42,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,67,97,110,110,111,116,32,117,115,101,32,42,32,112,114,101,99,105,115,105,111,110,32,119,105,116,104,32,111,98,106,101,99,116,46,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,111,100,101,46,112,114,101,99,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,118,97,108,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,111,98,106,101,99,116,72,97,115,65,108,108,40,111,98,106,44,32,102,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,111,98,106,91,102,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,78,111,32,115,117,99,104,32,102,105,101,108,100,58,32,34,32,43,32,102,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,99,116,121,112,101,32,61,61,32,34,37,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,37,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,40,118,97,108,44,32,99,111,100,101,44,32,102,119,44,32,112,114,101,99,44,32,102,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,95,112,97,100,100,101,100,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,111,100,101,46,99,102,108,97,103,115,46,108,101,102,116,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,100,95,114,105,103,104,116,40,115,44,32,102,119,44,32,34,32,34,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,112,97,100,95,108,101,102,116,40,115,44,32,102,119,44,32,34,32,34,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,111,98,106,40,99,111,100,101,115,44,32,111,98,106,44,32,105,32,43,32,49,44,32,118,32,43,32,115,95,112,97,100,100,101,100,41,32,116,97,105,108,115,116,114,105,99,116,59,10,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,115,41,32,61,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,97,114,114,40,99,111,100,101,115,44,32,118,97,108,115,44,32,48,44,32,48,44,32,34,34,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,115,41,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,111,98,106,40,99,111,100,101,115,44,32,118,97,108,115,44,32,48,44,32,34,34,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,109,97,116,95,99,111,100,101,115,95,97,114,114,40,99,111,100,101,115,44,32,91,118,97,108,115,93,44,32,48,44,32,48,44,32,34,34,41,44,10,10,32,32,32,32,102,111,108,100,114,40,102,117,110,99,44,32,97,114,114,44,32,105,110,105,116,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,102,117,110,99,44,32,97,114,114,44,32,114,117,110,110,105,110,103,44,32,105,100,120,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,100,120,32,60,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,117,110,110,105,110,103,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,102,117,110,99,44,32,97,114,114,44,32,102,117,110,99,40,97,114,114,91,105,100,120,93,44,32,114,117,110,110,105,110,103,41,44,32,105,100,120,32,45,32,49,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,97,117,120,40,102,117,110,99,44,32,97,114,114,44,32,105,110,105,116,44,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,45,32,49,41,44,10,10,32,32,32,32,102,111,108,100,108,40,102,117,110,99,44,32,97,114,114,44,32,105,110,105,116,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,102,117,110,99,44,32,97,114,114,44,32,114,117,110,110,105,110,103,44,32,105,100,120,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,100,120,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,117,110,110,105,110,103,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,102,117,110,99,44,32,97,114,114,44,32,102,117,110,99,40,114,117,110,110,105,110,103,44,32,97,114,114,91,105,100,120,93,41,44,32,105,100,120,32,43,32,49,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,97,117,120,40,102,117,110,99,44,32,97,114,114,44,32,105,110,105,116,44,32,48,41,44,10,10,10,32,32,32,32,102,105,108,116,101,114,77,97,112,40,102,105,108,116,101,114,95,102,117,110,99,44,32,109,97,112,95,102,117,110,99,44,32,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,102,105,108,116,101,114,95,102,117,110,99,41,32,33,61,32,34,102,117,110,99,116,105,111,110,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,115,116,100,46,102,105,108,116,101,114,77,97,112,32,102,105,114,115,116,32,112,97,114,97,109,32,109,117,115,116,32,98,101,32,102,117,110,99,116,105,111,110,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,102,105,108,116,101,114,95,102,117,110,99,41,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,109,97,112,95,102,117,110,99,41,32,33,61,32,34,102,117,110,99,116,105,111,110,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,115,116,100,46,102,105,108,116,101,114,77,97,112,32,115,101,99,111,110,100,32,112,97,114,97,109,32,109,117,115,116,32,98,101,32,102,117,110,99,116,105,111,110,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,109,97,112,95,102,117,110,99,41,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,97,114,114,41,32,33,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,40,34,115,116,100,46,102,105,108,116,101,114,77,97,112,32,116,104,105,114,100,32,112,97,114,97,109,32,109,117,115,116,32,98,101,32,97,114,114,97,121,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,97,114,114,41,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,109,97,112,40,109,97,112,95,102,117,110,99,44,32,115,116,100,46,102,105,108,116,101,114,40,102,105,108,116,101,114,95,102,117,110,99,44,32,97,114,114,41,41,44,10,10,32,32,32,32,97,115,115,101,114,116,69,113,117,97,108,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,97,32,61,61,32,98,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,116,114,117,101,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,65,115,115,101,114,116,105,111,110,32,102,97,105,108,101,100,46,32,34,32,43,32,97,32,43,32,34,32,33,61,32,34,32,43,32,98,44,10,10,32,32,32,32,97,98,115,40,110,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,110,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,97,98,115,32,101,120,112,101,99,116,101,100,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,110,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,110,32,62,32,48,32,116,104,101,110,32,110,32,101,108,115,101,32,45,110,44,10,10,32,32,32,32,109,97,120,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,97,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,109,97,120,32,102,105,114,115,116,32,112,97,114,97,109,32,101,120,112,101,99,116,101,100,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,97,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,98,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,109,97,120,32,115,101,99,111,110,100,32,112,97,114,97,109,32,101,120,112,101,99,116,101,100,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,98,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,97,32,62,32,98,32,116,104,101,110,32,97,32,101,108,115,101,32,98,44,10,10,32,32,32,32,109,105,110,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,97,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,109,97,120,32,102,105,114,115,116,32,112,97,114,97,109,32,101,120,112,101,99,116,101,100,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,97,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,98,41,32,33,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,115,116,100,46,109,97,120,32,115,101,99,111,110,100,32,112,97,114,97,109,32,101,120,112,101,99,116,101,100,32,110,117,109,98,101,114,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,98,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,97,32,60,32,98,32,116,104,101,110,32,97,32,101,108,115,101,32,98,44,10,10,32,32,32,32,102,108,97,116,116,101,110,65,114,114,97,121,115,40,97,114,114,115,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,102,111,108,100,108,40,102,117,110,99,116,105,111,110,40,97,44,32,98,41,32,97,32,43,32,98,44,32,97,114,114,115,44,32,91,93,41,44,10,10,32,32,32,32,109,97,110,105,102,101,115,116,73,110,105,40,105,110,105,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,98,111,100,121,95,108,105,110,101,115,40,98,111,100,121,41,32,61,32,91,34,37,115,32,61,32,37,115,34,32,37,32,91,107,44,32,98,111,100,121,91,107,93,93,32,102,111,114,32,107,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,98,111,100,121,41,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,101,99,116,105,111,110,95,108,105,110,101,115,40,115,110,97,109,101,44,32,115,98,111,100,121,41,32,61,32,91,34,91,37,115,93,34,32,37,32,91,115,110,97,109,101,93,93,32,43,32,98,111,100,121,95,108,105,110,101,115,40,115,98,111,100,121,41,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,109,97,105,110,95,98,111,100,121,32,61,32,105,102,32,115,116,100,46,111,98,106,101,99,116,72,97,115,40,105,110,105,44,32,34,109,97,105,110,34,41,32,116,104,101,110,32,98,111,100,121,95,108,105,110,101,115,40,105,110,105,46,109,97,105,110,41,32,101,108,115,101,32,91,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,108,108,95,115,101,99,116,105,111,110,115,32,61,32,91,115,101,99,116,105,111,110,95,108,105,110,101,115,40,107,44,32,105,110,105,46,115,101,99,116,105,111,110,115,91,107,93,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,107,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,105,110,105,46,115,101,99,116,105,111,110,115,41,93,59,10,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,92,110,34,44,32,109,97,105,110,95,98,111,100,121,32,43,32,115,116,100,46,102,108,97,116,116,101,110,65,114,114,97,121,115,40,97,108,108,95,115,101,99,116,105,111,110,115,41,32,43,32,91,34,34,93,41,44,10,10,32,32,32,32,101,115,99,97,112,101,83,116,114,105,110,103,74,115,111,110,40,115,116,114,95,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,32,115,116,100,46,116,111,83,116,114,105,110,103,40,115,116,114,95,41,59,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,97,110,115,40,99,104,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,104,32,61,61,32,34,92,34,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,92,34,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,104,32,61,61,32,34,92,92,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,92,92,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,104,32,61,61,32,34,92,98,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,98,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,104,32,61,61,32,34,92,102,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,102,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,104,32,61,61,32,34,92,110,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,110,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,104,32,61,61,32,34,92,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,114,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,99,104,32,61,61,32,34,92,116,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,116,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,99,112,32,61,32,115,116,100,46,99,111,100,101,112,111,105,110,116,40,99,104,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,112,32,60,32,51,50,32,124,124,32,40,99,112,32,62,61,32,49,50,54,32,38,38,32,99,112,32,60,61,32,49,53,57,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,92,92,117,37,48,52,120,34,32,37,32,91,99,112,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,104,59,10,32,32,32,32,32,32,32,32,34,92,34,37,115,92,34,34,32,37,32,115,116,100,46,106,111,105,110,40,34,34,44,32,91,116,114,97,110,115,40,99,104,41,32,102,111,114,32,99,104,32,105,110,32,115,116,100,46,115,116,114,105,110,103,67,104,97,114,115,40,115,116,114,41,93,41,44,10,10,32,32,32,32,101,115,99,97,112,101,83,116,114,105,110,103,80,121,116,104,111,110,40,115,116,114,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,101,115,99,97,112,101,83,116,114,105,110,103,74,115,111,110,40,115,116,114,41,44,10,10,32,32,32,32,101,115,99,97,112,101,83,116,114,105,110,103,66,97,115,104,40,115,116,114,95,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,32,115,116,100,46,116,111,83,116,114,105,110,103,40,115,116,114,95,41,59,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,97,110,115,40,99,104,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,104,32,61,61,32,34,39,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,39,92,34,39,92,34,39,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,104,59,10,32,32,32,32,32,32,32,32,34,39,37,115,39,34,32,37,32,115,116,100,46,106,111,105,110,40,34,34,44,32,91,116,114,97,110,115,40,99,104,41,32,102,111,114,32,99,104,32,105,110,32,115,116,100,46,115,116,114,105,110,103,67,104,97,114,115,40,115,116,114,41,93,41,44,10,10,32,32,32,32,101,115,99,97,112,101,83,116,114,105,110,103,68,111,108,108,97,114,115,40,115,116,114,95,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,32,115,116,100,46,116,111,83,116,114,105,110,103,40,115,116,114,95,41,59,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,114,97,110,115,40,99,104,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,99,104,32,61,61,32,34,36,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,36,36,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,99,104,59,10,32,32,32,32,32,32,32,32,115,116,100,46,102,111,108,100,108,40,102,117,110,99,116,105,111,110,40,97,44,32,98,41,32,97,32,43,32,116,114,97,110,115,40,98,41,44,32,115,116,100,46,115,116,114,105,110,103,67,104,97,114,115,40,115,116,114,41,44,32,34,34,41,44,10,10,32,32,32,32,109,97,110,105,102,101,115,116,74,115,111,110,40,118,97,108,117,101,41,58,58,32,115,116,100,46,109,97,110,105,102,101,115,116,74,115,111,110,69,120,40,118,97,108,117,101,44,32,34,32,32,32,32,34,41,44,10,10,32,32,32,32,109,97,110,105,102,101,115,116,74,115,111,110,69,120,40,118,97,108,117,101,44,32,105,110,100,101,110,116,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,118,44,32,112,97,116,104,44,32,99,105,110,100,101,110,116,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,118,32,61,61,32,116,114,117,101,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,116,114,117,101,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,118,32,61,61,32,102,97,108,115,101,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,102,97,108,115,101,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,118,32,61,61,32,110,117,108,108,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,110,117,108,108,34,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,41,32,61,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,34,32,43,32,118,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,101,115,99,97,112,101,83,116,114,105,110,103,74,115,111,110,40,118,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,41,32,61,61,32,34,102,117,110,99,116,105,111,110,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,84,114,105,101,100,32,116,111,32,109,97,110,105,102,101,115,116,32,102,117,110,99,116,105,111,110,32,97,116,32,34,32,43,32,112,97,116,104,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,41,32,61,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,97,110,103,101,32,61,32,115,116,100,46,114,97,110,103,101,40,48,44,32,115,116,100,46,108,101,110,103,116,104,40,118,41,32,45,32,49,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,101,119,95,105,110,100,101,110,116,32,61,32,99,105,110,100,101,110,116,32,43,32,105,110,100,101,110,116,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,105,110,101,115,32,61,32,91,34,91,92,110,34,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,115,116,100,46,106,111,105,110,40,91,34,44,92,110,34,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,91,91,110,101,119,95,105,110,100,101,110,116,32,43,32,97,117,120,40,118,91,105,93,44,32,112,97,116,104,32,43,32,91,105,93,44,32,110,101,119,95,105,110,100,101,110,116,41,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,105,32,105,110,32,114,97,110,103,101,93,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,91,34,92,110,34,32,43,32,99,105,110,100,101,110,116,32,43,32,34,93,34,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,34,44,32,108,105,110,101,115,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,118,41,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,105,110,101,115,32,61,32,91,34,123,92,110,34,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,115,116,100,46,106,111,105,110,40,91,34,44,92,110,34,93,44,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,91,91,99,105,110,100,101,110,116,32,43,32,105,110,100,101,110,116,32,43,32,34,92,34,34,32,43,32,107,32,43,32,34,92,34,58,32,34,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,97,117,120,40,118,91,107,93,44,32,112,97,116,104,32,43,32,91,107,93,44,32,99,105,110,100,101,110,116,32,43,32,105,110,100,101,110,116,41,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,107,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,118,41,93,41,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,43,32,91,34,92,110,34,32,43,32,99,105,110,100,101,110,116,32,43,32,34,125,34,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,34,44,32,108,105,110,101,115,41,59,10,32,32,32,32,32,32,32,32,97,117,120,40,118,97,108,117,101,44,32,91,93,44,32,34,34,41,44,10,10,32,32,32,32,109,97,110,105,102,101,115,116,89,97,109,108,83,116,114,101,97,109,40,118,97,108,117,101,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,118,97,108,117,101,41,32,33,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,109,97,110,105,102,101,115,116,89,97,109,108,83,116,114,101,97,109,32,111,110,108,121,32,116,97,107,101,115,32,97,114,114,97,121,115,44,32,103,111,116,32,34,32,43,32,115,116,100,46,116,121,112,101,40,118,97,108,117,101,41,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,34,45,45,45,92,110,34,32,43,32,115,116,100,46,106,111,105,110,40,34,92,110,45,45,45,92,110,34,44,32,91,115,116,100,46,109,97,110,105,102,101,115,116,74,115,111,110,40,101,41,32,102,111,114,32,101,32,105,110,32,118,97,108,117,101,93,41,32,43,32,39,92,110,46,46,46,92,110,39,44,10,10,10,32,32,32,32,109,97,110,105,102,101,115,116,80,121,116,104,111,110,40,111,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,111,41,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,105,101,108,100,115,32,61,32,91,34,37,115,58,32,37,115,34,32,37,32,91,115,116,100,46,101,115,99,97,112,101,83,116,114,105,110,103,80,121,116,104,111,110,40,107,41,44,32,115,116,100,46,109,97,110,105,102,101,115,116,80,121,116,104,111,110,40,111,91,107,93,41,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,107,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,111,41,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,34,123,37,115,125,34,32,37,32,91,115,116,100,46,106,111,105,110,40,34,44,32,34,44,32,102,105,101,108,100,115,41,93,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,111,41,32,61,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,34,91,37,115,93,34,32,37,32,91,115,116,100,46,106,111,105,110,40,34,44,32,34,44,32,91,115,116,100,46,109,97,110,105,102,101,115,116,80,121,116,104,111,110,40,111,50,41,32,102,111,114,32,111,50,32,105,110,32,111,93,41,93,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,111,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,34,37,115,34,32,37,32,91,115,116,100,46,101,115,99,97,112,101,83,116,114,105,110,103,80,121,116,104,111,110,40,111,41,93,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,111,41,32,61,61,32,34,102,117,110,99,116,105,111,110,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,99,97,110,110,111,116,32,109,97,110,105,102,101,115,116,32,102,117,110,99,116,105,111,110,34,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,116,121,112,101,40,111,41,32,61,61,32,34,110,117,109,98,101,114,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,116,111,83,116,114,105,110,103,40,111,41,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,111,32,61,61,32,116,114,117,101,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,34,84,114,117,101,34,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,111,32,61,61,32,102,97,108,115,101,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,34,70,97,108,115,101,34,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,111,32,61,61,32,110,117,108,108,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,34,78,111,110,101,34,44,10,10,32,32,32,32,109,97,110,105,102,101,115,116,80,121,116,104,111,110,86,97,114,115,40,99,111,110,102,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,118,97,114,115,32,61,32,91,34,37,115,32,61,32,37,115,34,32,37,32,91,107,44,32,115,116,100,46,109,97,110,105,102,101,115,116,80,121,116,104,111,110,40,99,111,110,102,91,107,93,41,93,32,102,111,114,32,107,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,99,111,110,102,41,93,59,10,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,92,110,34,44,32,118,97,114,115,32,43,32,91,34,34,93,41,44,10,10,10,32,32,32,32,108,111,99,97,108,32,98,97,115,101,54,52,95,116,97,98,108,101,32,61,32,34,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47,34,44,10,32,32,32,32,108,111,99,97,108,32,98,97,115,101,54,52,95,105,110,118,32,61,32,123,32,91,98,97,115,101,54,52,95,116,97,98,108,101,91,105,93,93,58,32,105,32,102,111,114,32,105,32,105,110,32,115,116,100,46,114,97,110,103,101,40,48,44,32,54,51,41,32,125,44,10,10,32,32,32,32,98,97,115,101,54,52,40,105,110,112,117,116,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,98,121,116,101,115,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,105,110,112,117,116,41,32,61,61,32,34,115,116,114,105,110,103,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,109,97,112,40,102,117,110,99,116,105,111,110,40,99,41,32,115,116,100,46,99,111,100,101,112,111,105,110,116,40,99,41,44,32,105,110,112,117,116,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,110,112,117,116,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,97,114,114,44,32,105,44,32,114,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,105,32,43,32,49,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,54,32,77,83,66,32,111,102,32,105,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,93,32,38,32,50,53,50,41,32,62,62,32,50,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,50,32,76,83,66,32,111,102,32,105,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,93,32,38,32,51,41,32,60,60,32,52,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,61,61,34,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,105,32,43,32,51,44,32,114,32,43,32,115,116,114,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,105,32,43,32,50,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,54,32,77,83,66,32,111,102,32,105,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,93,32,38,32,50,53,50,41,32,62,62,32,50,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,50,32,76,83,66,32,111,102,32,105,44,32,52,32,77,83,66,32,111,102,32,105,43,49,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,93,32,38,32,51,41,32,60,60,32,52,32,124,32,40,97,114,114,91,105,32,43,32,49,93,32,38,32,50,52,48,41,32,62,62,32,52,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,52,32,76,83,66,32,111,102,32,105,43,49,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,32,43,32,49,93,32,38,32,49,53,41,32,60,60,32,50,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,34,61,34,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,105,32,43,32,51,44,32,114,32,43,32,115,116,114,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,116,114,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,54,32,77,83,66,32,111,102,32,105,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,93,32,38,32,50,53,50,41,32,62,62,32,50,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,50,32,76,83,66,32,111,102,32,105,44,32,52,32,77,83,66,32,111,102,32,105,43,49,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,93,32,38,32,51,41,32,60,60,32,52,32,124,32,40,97,114,114,91,105,32,43,32,49,93,32,38,32,50,52,48,41,32,62,62,32,52,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,52,32,76,83,66,32,111,102,32,105,43,49,44,32,50,32,77,83,66,32,111,102,32,105,43,50,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,32,43,32,49,93,32,38,32,49,53,41,32,60,60,32,50,32,124,32,40,97,114,114,91,105,32,43,32,50,93,32,38,32,49,57,50,41,32,62,62,32,54,93,32,43,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,54,32,76,83,66,32,111,102,32,105,43,50,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,98,97,115,101,54,52,95,116,97,98,108,101,91,40,97,114,114,91,105,32,43,32,50,93,32,38,32,54,51,41,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,114,114,44,32,105,32,43,32,51,44,32,114,32,43,32,115,116,114,41,32,116,97,105,108,115,116,114,105,99,116,59,10,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,115,97,110,105,116,121,32,61,32,115,116,100,46,102,111,108,100,108,40,102,117,110,99,116,105,111,110,40,114,44,32,97,41,32,114,32,38,38,32,40,97,32,60,32,50,53,54,41,44,32,98,121,116,101,115,44,32,116,114,117,101,41,59,10,32,32,32,32,32,32,32,32,105,102,32,33,115,97,110,105,116,121,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,67,97,110,32,111,110,108,121,32,98,97,115,101,54,52,32,101,110,99,111,100,101,32,115,116,114,105,110,103,115,32,47,32,97,114,114,97,121,115,32,111,102,32,115,105,110,103,108,101,32,98,121,116,101,115,46,34,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,98,121,116,101,115,44,32,48,44,32,34,34,41,44,10,10,10,32,32,32,32,98,97,115,101,54,52,68,101,99,111,100,101,66,121,116,101,115,40,115,116,114,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,37,32,52,32,33,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,101,114,114,111,114,32,34,78,111,116,32,97,32,98,97,115,101,54,52,32,101,110,99,111,100,101,100,32,115,116,114,105,110,103,32,92,34,37,115,92,34,34,32,37,32,115,116,114,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,115,116,114,44,32,105,44,32,114,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,115,116,114,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,114,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,97,108,108,32,54,32,98,105,116,115,32,111,102,32,105,44,32,50,32,77,83,66,32,111,102,32,105,43,49,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,49,32,61,32,91,98,97,115,101,54,52,95,105,110,118,91,115,116,114,91,105,93,93,32,60,60,32,50,32,124,32,40,98,97,115,101,54,52,95,105,110,118,91,115,116,114,91,105,32,43,32,49,93,93,32,62,62,32,52,41,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,52,32,76,83,66,32,111,102,32,105,43,49,44,32,52,77,83,66,32,111,102,32,105,43,50,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,50,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,114,91,105,32,43,32,50,93,32,61,61,32,34,61,34,32,116,104,101,110,32,91,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,91,40,98,97,115,101,54,52,95,105,110,118,91,115,116,114,91,105,32,43,32,49,93,93,32,38,32,49,53,41,32,60,60,32,52,32,124,32,40,98,97,115,101,54,52,95,105,110,118,91,115,116,114,91,105,32,43,32,50,93,93,32,62,62,32,50,41,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,47,47,32,50,32,76,83,66,32,111,102,32,105,43,50,44,32,97,108,108,32,54,32,98,105,116,115,32,111,102,32,105,43,51,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,51,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,114,91,105,32,43,32,51,93,32,61,61,32,34,61,34,32,116,104,101,110,32,91,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,91,40,98,97,115,101,54,52,95,105,110,118,91,115,116,114,91,105,32,43,32,50,93,93,32,38,32,51,41,32,60,60,32,54,32,124,32,98,97,115,101,54,52,95,105,110,118,91,115,116,114,91,105,32,43,32,51,93,93,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,105,32,43,32,52,44,32,114,32,43,32,110,49,32,43,32,110,50,32,43,32,110,51,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,115,116,114,44,32,48,44,32,91,93,41,44,10,10,32,32,32,32,98,97,115,101,54,52,68,101,99,111,100,101,40,115,116,114,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,98,121,116,101,115,32,61,32,115,116,100,46,98,97,115,101,54,52,68,101,99,111,100,101,66,121,116,101,115,40,115,116,114,41,59,10,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,34,44,32,115,116,100,46,109,97,112,40,102,117,110,99,116,105,111,110,40,98,41,32,115,116,100,46,99,104,97,114,40,98,41,44,32,98,121,116,101,115,41,41,44,10,10,32,32,32,32,47,47,32,81,117,105,99,107,115,111,114,116,10,32,32,32,32,115,111,114,116,40,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,32,61,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,59,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,61,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,91,93,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,112,105,118,111,116,32,61,32,97,114,114,91,48,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,101,115,116,32,61,32,115,116,100,46,109,97,107,101,65,114,114,97,121,40,108,32,45,32,49,44,32,102,117,110,99,116,105,111,110,40,105,41,32,97,114,114,91,105,32,43,32,49,93,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,101,102,116,32,61,32,115,116,100,46,102,105,108,116,101,114,40,102,117,110,99,116,105,111,110,40,120,41,32,120,32,60,61,32,112,105,118,111,116,44,32,114,101,115,116,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,114,105,103,104,116,32,61,32,115,116,100,46,102,105,108,116,101,114,40,102,117,110,99,116,105,111,110,40,120,41,32,120,32,62,32,112,105,118,111,116,44,32,114,101,115,116,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,115,111,114,116,40,108,101,102,116,41,32,43,32,91,112,105,118,111,116,93,32,43,32,115,116,100,46,115,111,114,116,40,114,105,103,104,116,41,44,10,10,32,32,32,32,117,110,105,113,40,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,40,97,44,32,98,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,108,101,110,103,116,104,40,97,41,32,61,61,32,48,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,91,98,93,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,97,91,115,116,100,46,108,101,110,103,116,104,40,97,41,32,45,32,49,93,32,61,61,32,98,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,32,43,32,91,98,93,59,10,32,32,32,32,32,32,32,32,115,116,100,46,102,111,108,100,108,40,102,44,32,97,114,114,44,32,91,93,41,44,10,10,32,32,32,32,115,101,116,40,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,117,110,105,113,40,115,116,100,46,115,111,114,116,40,97,114,114,41,41,44,10,10,32,32,32,32,115,101,116,77,101,109,98,101,114,40,120,44,32,97,114,114,41,58,58,10,32,32,32,32,32,32,32,32,47,47,32,84,79,68,79,40,100,99,117,110,110,105,110,41,58,32,66,105,110,97,114,121,32,99,104,111,112,32,102,111,114,32,79,40,108,111,103,32,110,41,32,99,111,109,112,108,101,120,105,116,121,10,32,32,32,32,32,32,32,32,115,116,100,46,108,101,110,103,116,104,40,115,116,100,46,115,101,116,73,110,116,101,114,40,91,120,93,44,32,97,114,114,41,41,32,62,32,48,44,10,10,32,32,32,32,115,101,116,85,110,105,111,110,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,115,101,116,40,97,32,43,32,98,41,44,10,10,32,32,32,32,115,101,116,73,110,116,101,114,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,97,44,32,98,44,32,105,44,32,106,44,32,97,99,99,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,41,32,124,124,32,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,98,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,99,99,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,97,91,105,93,32,61,61,32,98,91,106,93,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,44,32,106,32,43,32,49,44,32,97,99,99,32,43,32,91,97,91,105,93,93,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,97,91,105,93,32,60,32,98,91,106,93,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,44,32,106,44,32,97,99,99,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,44,32,106,32,43,32,49,44,32,97,99,99,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,48,44,32,48,44,32,91,93,41,32,116,97,105,108,115,116,114,105,99,116,44,10,10,32,32,32,32,115,101,116,68,105,102,102,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,97,44,32,98,44,32,105,44,32,106,44,32,97,99,99,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,97,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,99,99,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,106,32,62,61,32,115,116,100,46,108,101,110,103,116,104,40,98,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,44,32,106,44,32,97,99,99,32,43,32,91,97,91,105,93,93,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,97,91,105,93,32,61,61,32,98,91,106,93,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,44,32,106,32,43,32,49,44,32,97,99,99,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,97,91,105,93,32,60,32,98,91,106,93,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,44,32,106,44,32,97,99,99,32,43,32,91,97,91,105,93,93,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,44,32,106,32,43,32,49,44,32,97,99,99,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,48,44,32,48,44,32,91,93,41,32,116,97,105,108,115,116,114,105,99,116,44,10,10,32,32,32,32,109,101,114,103,101,80,97,116,99,104,40,116,97,114,103,101,116,44,32,112,97,116,99,104,41,58,58,10,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,112,97,116,99,104,41,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,97,114,103,101,116,95,111,98,106,101,99,116,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,116,97,114,103,101,116,41,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,32,116,97,114,103,101,116,32,101,108,115,101,32,123,125,59,10,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,97,114,103,101,116,95,102,105,101,108,100,115,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,116,121,112,101,40,116,97,114,103,101,116,95,111,98,106,101,99,116,41,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,116,97,114,103,101,116,95,111,98,106,101,99,116,41,32,101,108,115,101,32,91,93,59,10,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,110,117,108,108,95,102,105,101,108,100,115,32,61,32,91,107,32,102,111,114,32,107,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,112,97,116,99,104,41,32,105,102,32,112,97,116,99,104,91,107,93,32,61,61,32,110,117,108,108,93,59,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,98,111,116,104,95,102,105,101,108,100,115,32,61,32,115,116,100,46,115,101,116,85,110,105,111,110,40,116,97,114,103,101,116,95,102,105,101,108,100,115,44,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,112,97,116,99,104,41,41,59,10,10,32,32,32,32,32,32,32,32,32,32,32,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,91,107,93,58,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,33,115,116,100,46,111,98,106,101,99,116,72,97,115,40,112,97,116,99,104,44,32,107,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,97,114,103,101,116,95,111,98,106,101,99,116,91,107,93,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,33,115,116,100,46,111,98,106,101,99,116,72,97,115,40,116,97,114,103,101,116,95,111,98,106,101,99,116,44,32,107,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,109,101,114,103,101,80,97,116,99,104,40,110,117,108,108,44,32,112,97,116,99,104,91,107,93,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,109,101,114,103,101,80,97,116,99,104,40,116,97,114,103,101,116,95,111,98,106,101,99,116,91,107,93,44,32,112,97,116,99,104,91,107,93,41,32,116,97,105,108,115,116,114,105,99,116,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,107,32,105,110,32,115,116,100,46,115,101,116,68,105,102,102,40,98,111,116,104,95,102,105,101,108,100,115,44,32,110,117,108,108,95,102,105,101,108,100,115,41,10,32,32,32,32,32,32,32,32,32,32,32,32,125,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,112,97,116,99,104,44,10,10,32,32,32,32,111,98,106,101,99,116,70,105,101,108,100,115,40,111,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,69,120,40,111,44,32,102,97,108,115,101,41,44,10,10,32,32,32,32,111,98,106,101,99,116,70,105,101,108,100,115,65,108,108,40,111,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,69,120,40,111,44,32,116,114,117,101,41,44,10,10,32,32,32,32,111,98,106,101,99,116,72,97,115,40,111,44,32,102,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,111,98,106,101,99,116,72,97,115,69,120,40,111,44,32,102,44,32,102,97,108,115,101,41,44,10,10,32,32,32,32,111,98,106,101,99,116,72,97,115,65,108,108,40,111,44,32,102,41,58,58,10,32,32,32,32,32,32,32,32,115,116,100,46,111,98,106,101,99,116,72,97,115,69,120,40,111,44,32,102,44,32,116,114,117,101,41,44,10,10,32,32,32,32,101,113,117,97,108,115,40,97,44,32,98,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,97,32,61,32,115,116,100,46,116,121,112,101,40,97,41,59,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,98,32,61,32,115,116,100,46,116,121,112,101,40,98,41,59,10,32,32,32,32,32,32,32,32,105,102,32,33,115,116,100,46,112,114,105,109,105,116,105,118,101,69,113,117,97,108,115,40,116,97,44,32,116,98,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,115,116,100,46,112,114,105,109,105,116,105,118,101,69,113,117,97,108,115,40,116,97,44,32,34,97,114,114,97,121,34,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,97,32,61,32,115,116,100,46,108,101,110,103,116,104,40,97,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,33,115,116,100,46,112,114,105,109,105,116,105,118,101,69,113,117,97,108,115,40,108,97,44,32,115,116,100,46,108,101,110,103,116,104,40,98,41,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,97,44,32,98,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,108,97,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,114,117,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,97,91,105,93,32,33,61,32,98,91,105,93,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,48,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,115,116,100,46,112,114,105,109,105,116,105,118,101,69,113,117,97,108,115,40,116,97,44,32,34,111,98,106,101,99,116,34,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,102,105,101,108,100,115,32,61,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,97,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,108,102,105,101,108,100,115,32,61,32,115,116,100,46,108,101,110,103,116,104,40,102,105,101,108,100,115,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,102,105,101,108,100,115,32,33,61,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,98,41,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,117,120,40,97,44,32,98,44,32,105,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,105,32,62,61,32,108,102,105,101,108,100,115,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,114,117,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,108,111,99,97,108,32,102,32,61,32,102,105,101,108,100,115,91,105,93,59,32,97,91,102,93,32,33,61,32,98,91,102,93,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,105,32,43,32,49,41,32,116,97,105,108,115,116,114,105,99,116,59,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,97,117,120,40,97,44,32,98,44,32,48,41,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,112,114,105,109,105,116,105,118,101,69,113,117,97,108,115,40,97,44,32,98,41,44,10,10,10,32,32,32,32,114,101,115,111,108,118,101,80,97,116,104,40,102,44,32,114,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,97,114,114,32,61,32,115,116,100,46,115,112,108,105,116,40,102,44,32,34,47,34,41,59,10,32,32,32,32,32,32,32,32,115,116,100,46,106,111,105,110,40,34,47,34,44,32,115,116,100,46,109,97,107,101,65,114,114,97,121,40,115,116,100,46,108,101,110,103,116,104,40,97,114,114,41,32,45,32,49,44,32,102,117,110,99,116,105,111,110,40,105,41,32,97,114,114,91,105,93,41,32,43,32,91,114,93,41,44,10,10,32,32,32,32,112,114,117,110,101,40,97,41,58,58,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,105,115,67,111,110,116,101,110,116,40,98,41,32,61,10,32,32,32,32,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,32,61,32,115,116,100,46,116,121,112,101,40,98,41,59,10,32,32,32,32,32,32,32,32,32,32,32,32,105,102,32,98,32,61,61,32,110,117,108,108,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,102,97,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,116,32,61,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,108,101,110,103,116,104,40,98,41,32,62,32,48,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,116,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,115,116,100,46,108,101,110,103,116,104,40,98,41,32,62,32,48,10,32,32,32,32,32,32,32,32,32,32,32,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,116,114,117,101,59,10,32,32,32,32,32,32,32,32,108,111,99,97,108,32,116,32,61,32,115,116,100,46,116,121,112,101,40,97,41,59,10,32,32,32,32,32,32,32,32,105,102,32,116,61,61,32,34,97,114,114,97,121,34,32,116,104,101,110,10,32,32,32,32,32,32,32,32,32,32,32,32,91,32,115,116,100,46,112,114,117,110,101,40,120,41,32,102,111,114,32,120,32,105,110,32,97,32,105,102,32,105,115,67,111,110,116,101,110,116,40,36,46,112,114,117,110,101,40,120,41,41,32,93,10,32,32,32,32,32,32,32,32,101,108,115,101,32,105,102,32,116,32,61,61,32,34,111,98,106,101,99,116,34,32,116,104,101,110,32,123,10,32,32,32,32,32,32,32,32,32,32,32,32,91,120,93,58,32,36,46,112,114,117,110,101,40,97,91,120,93,41,10,32,32,32,32,32,32,32,32,32,32,32,32,102,111,114,32,120,32,105,110,32,115,116,100,46,111,98,106,101,99,116,70,105,101,108,100,115,40,97,41,32,105,102,32,105,115,67,111,110,116,101,110,116,40,115,116,100,46,112,114,117,110,101,40,97,91,120,93,41,41,10,32,32,32,32,32,32,32,32,125,32,101,108,115,101,10,32,32,32,32,32,32,32,32,32,32,32,32,97,44,10,125,10,0 - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/string_utils.cpp b/vendor/github.com/strickyak/jsonnet_cgo/string_utils.cpp deleted file mode 100644 index da5fb6580fb7ec4261f316cbb52620a174e8ba04..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/string_utils.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <iomanip> - -#include "string_utils.h" -#include "static_error.h" - -UString jsonnet_string_unparse(const UString &str, bool single) -{ - UStringStream ss; - ss << (single ? U'\'' : U'\"'); - ss << jsonnet_string_escape(str, single); - ss << (single ? U'\'' : U'\"'); - return ss.str(); -} - -UString jsonnet_string_escape(const UString &str, bool single) -{ - UStringStream ss; - for (std::size_t i=0 ; i<str.length() ; ++i) { - char32_t c = str[i]; - switch (c) { - case U'\"': ss << (single ? U"\"" : U"\\\""); break; - case U'\'': ss << (single ? U"\\\'" : U"\'"); break; - case U'\\': ss << U"\\\\"; break; - case U'\b': ss << U"\\b"; break; - case U'\f': ss << U"\\f"; break; - case U'\n': ss << U"\\n"; break; - case U'\r': ss << U"\\r"; break; - case U'\t': ss << U"\\t"; break; - case U'\0': ss << U"\\u0000"; break; - default: { - if (c < 0x20 || (c >= 0x7f && c <= 0x9f)) { - //Unprintable, use \u - std::stringstream ss8; - ss8 << "\\u" << std::hex << std::setfill('0') << std::setw(4) - << (unsigned long)(c); - ss << decode_utf8(ss8.str()); - } else { - // Printable, write verbatim - ss << c; - } - } - } - } - return ss.str(); -} - - -UString jsonnet_string_unescape(const LocationRange &loc, const UString &s) -{ - UString r; - const char32_t *s_ptr = s.c_str(); - for (const char32_t *c = s_ptr; *c != U'\0' ; ++c) { - switch (*c) { - case '\\': - switch (*(++c)) { - case '"': - case '\'': - r += *c; - break; - - case '\\': - r += *c; - break; - - case '/': - r += *c; - break; - - case 'b': - r += '\b'; - break; - - case 'f': - r += '\f'; - break; - - case 'n': - r += '\n'; - break; - - case 'r': - r += '\r'; - break; - - case 't': - r += '\t'; - break; - - case 'u': { - ++c; // Consume the 'u'. - unsigned long codepoint = 0; - // Expect 4 hex digits. - for (unsigned i=0 ; i<4 ; ++i) { - auto x = (unsigned char)(c[i]); - unsigned digit; - if (x == '\0') { - auto msg = "Truncated unicode escape sequence in string literal."; - throw StaticError(loc, msg); - } else if (x >= '0' && x <= '9') { - digit = x - '0'; - } else if (x >= 'a' && x <= 'f') { - digit = x - 'a' + 10; - } else if (x >= 'A' && x <= 'F') { - digit = x - 'A' + 10; - } else { - std::stringstream ss; - ss << "Malformed unicode escape character, " - << "should be hex: '" << x << "'"; - throw StaticError(loc, ss.str()); - } - codepoint *= 16; - codepoint += digit; - } - - r += codepoint; - - // Leave us on the last char, ready for the ++c at - // the outer for loop. - c += 3; - } - break; - - case '\0': { - auto msg = "Truncated escape sequence in string literal."; - throw StaticError(loc, msg); - } - - default: { - std::stringstream ss; - std::string utf8; - encode_utf8(*c, utf8); - ss << "Unknown escape sequence in string literal: '" << utf8 << "'"; - throw StaticError(loc, ss.str()); - } - } - break; - - default: - // Just a regular letter. - r += *c; - } - } - return r; -} - - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/string_utils.h b/vendor/github.com/strickyak/jsonnet_cgo/string_utils.h deleted file mode 100644 index fd9d7731c1a1a4edf97a8e642d9e3dcde01f5f78..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/string_utils.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_STRING_H -#define JSONNET_STRING_H - -#include "lexer.h" - -/** Unparse the string. */ -UString jsonnet_string_unparse(const UString &str, bool single); - -/** Escape special characters. */ -UString jsonnet_string_escape(const UString &str, bool single); - -/** Resolve escape chracters in the string. */ -UString jsonnet_string_unescape(const LocationRange &loc, const UString &s); - -#endif diff --git a/vendor/github.com/strickyak/jsonnet_cgo/test1.j b/vendor/github.com/strickyak/jsonnet_cgo/test1.j deleted file mode 100644 index 6b4508aac5b0d347c0c1f45522a93f01e1dc9411..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/test1.j +++ /dev/null @@ -1,4 +0,0 @@ -{ - shell: "/bin/sh", - awk: "/usr/bin/awk", -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/test2.j b/vendor/github.com/strickyak/jsonnet_cgo/test2.j deleted file mode 100644 index dd1aec39d11616f302488835472e552e97e45371..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/test2.j +++ /dev/null @@ -1,5 +0,0 @@ -local test1 = import "test1.j"; - -test1 { - shell: "/bin/csh", -} diff --git a/vendor/github.com/strickyak/jsonnet_cgo/unicode.h b/vendor/github.com/strickyak/jsonnet_cgo/unicode.h deleted file mode 100644 index f2125d1b3adbfc9d52a347a0db3e7a9e781e4ca4..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/unicode.h +++ /dev/null @@ -1,166 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_UNICODE_H -#define JSONNET_UNICODE_H - -/** Substituted when a unicode translation format encoding error is encountered. */ -#define JSONNET_CODEPOINT_ERROR 0xfffd -#define JSONNET_CODEPOINT_MAX 0x110000 - -/** Convert a unicode codepoint to UTF8. - * - * \param x The unicode codepoint. - * \param s The UTF-8 string to append to. - * \returns The number of characters appended. - */ -static inline int encode_utf8(char32_t x, std::string &s) -{ - if (x >= JSONNET_CODEPOINT_MAX) - x = JSONNET_CODEPOINT_ERROR; - - // 00ZZZzzz 00zzYYYY 00Yyyyxx 00xxxxxx - long bytes = ((x & 0x1C0000) << 6) | ((x & 0x03F000) << 4) | ((x & 0x0FC0) << 2) | (x & 0x3F); - - if (x < 0x80) { - s.push_back((char)x); - return 1; - } else if (x < 0x800) { // note that capital 'Y' bits must be 0 - bytes |= 0xC080; - s.push_back((bytes >> 8) & 0xFF); - s.push_back((bytes >> 0) & 0xFF); - return 2; - } else if (x < 0x10000) { // note that 'z' bits must be 0 - bytes |= 0xE08080; - s.push_back((bytes >> 16) & 0xFF); - s.push_back((bytes >> 8) & 0xFF); - s.push_back((bytes >> 0) & 0xFF); - return 3; - } else if (x < 0x110000) { // note that capital 'Z' bits must be 0 - bytes |= 0xF0808080; - s.push_back((bytes >> 24) & 0xFF); - s.push_back((bytes >> 16) & 0xFF); - s.push_back((bytes >> 8) & 0xFF); - s.push_back((bytes >> 0) & 0xFF); - return 4; - } else { - std::cerr << "Should never get here." << std::endl; - abort(); - } -} - -/** Convert the UTF8 byte sequence in the given string to a unicode code point. - * - * \param str The string. - * \param i The index of the string from which to start decoding and returns the index of the last - * byte of the encoded codepoint. - * \returns The decoded unicode codepoint. - */ -static inline char32_t decode_utf8(const std::string &str, size_t &i) -{ - char c0 = str[i]; - if ((c0 & 0x80) == 0) { //0xxxxxxx - return c0; - } else if ((c0 & 0xE0) == 0xC0) { //110yyyxx 10xxxxxx - if (i+1 >= str.length()) { - return JSONNET_CODEPOINT_ERROR; - } - char c1 = str[++i]; - if ((c1 & 0xC0) != 0x80) { - return JSONNET_CODEPOINT_ERROR; - } - return ((c0 & 0x1F) << 6ul) | (c1 & 0x3F); - } else if ((c0 & 0xF0) == 0xE0) { //1110yyyy 10yyyyxx 10xxxxxx - if (i+2 >= str.length()) { - return JSONNET_CODEPOINT_ERROR; - } - char c1 = str[++i]; - if ((c1 & 0xC0) != 0x80) { - return JSONNET_CODEPOINT_ERROR; - } - char c2 = str[++i]; - if ((c2 & 0xC0) != 0x80) { - return JSONNET_CODEPOINT_ERROR; - } - return ((c0 & 0xF) << 12ul) | ((c1 & 0x3F) << 6) | (c2 & 0x3F); - } else if ((c0 & 0xF8) == 0xF0) { //11110zzz 10zzyyyy 10yyyyxx 10xxxxxx - if (i+3 >= str.length()) { - return JSONNET_CODEPOINT_ERROR; - } - char c1 = str[++i]; - if ((c1 & 0xC0) != 0x80) { - return JSONNET_CODEPOINT_ERROR; - } - char c2 = str[++i]; - if ((c2 & 0xC0) != 0x80) { - return JSONNET_CODEPOINT_ERROR; - } - char c3 = str[++i]; - if ((c3 & 0xC0) != 0x80) { - return JSONNET_CODEPOINT_ERROR; - } - return ((c0 & 0x7) << 24ul) | ((c1 & 0x3F) << 12ul) | ((c2 & 0x3F) << 6) | (c3 & 0x3F); - } else { - return JSONNET_CODEPOINT_ERROR; - } -} - -/** A string class capable of holding unicode codepoints. */ -typedef std::basic_string<char32_t> UString; - - -static inline void encode_utf8(const UString &s, std::string &r) -{ - for (char32_t cp : s) - encode_utf8(cp, r); -} - -static inline std::string encode_utf8(const UString &s) -{ - std::string r; - encode_utf8(s, r); - return r; -} - -static inline UString decode_utf8(const std::string &s) -{ - UString r; - for (size_t i = 0; i < s.length(); ++i) - r.push_back(decode_utf8(s, i)); - return r; -} - -/** A stringstream-like class capable of holding unicode codepoints. - * The C++ standard does not support std::basic_stringstream<char32_t. - */ -class UStringStream { - UString buf; - public: - UStringStream &operator << (const UString &s) { buf.append(s); return *this; } - UStringStream &operator << (const char32_t *s) { buf.append(s); return *this; } - UStringStream &operator << (char32_t c) { buf.push_back(c); return *this; } - template<class T> UStringStream &operator << (T c) - { - std::stringstream ss; - ss << c; - for (char c : ss.str()) - buf.push_back(char32_t(c)); - return *this; - } - UString str() { return buf; } -}; - -#endif // JSONNET_UNICODE_H diff --git a/vendor/github.com/strickyak/jsonnet_cgo/vm.cpp b/vendor/github.com/strickyak/jsonnet_cgo/vm.cpp deleted file mode 100644 index 58568df167c134d3194931de106294dd31b1f27e..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/vm.cpp +++ /dev/null @@ -1,2811 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include <cassert> -#include <cmath> - -#include <memory> -#include <set> -#include <string> - - -#include "desugarer.h" -#include "json.h" -#include "md5.h" -#include "parser.h" -#include "state.h" -#include "static_analysis.h" -#include "string_utils.h" -#include "vm.h" - -namespace { - -/** Turn a path e.g. "/a/b/c" into a dir, e.g. "/a/b/". If there is no path returns "". - */ -std::string dir_name(const std::string &path) -{ - size_t last_slash = path.rfind('/'); - if (last_slash != std::string::npos) { - return path.substr(0, last_slash+1); - } - return ""; -} - -/** Stack frames. - * - * Of these, FRAME_CALL is the most special, as it is the only frame the stack - * trace (for errors) displays. - */ -enum FrameKind { - FRAME_APPLY_TARGET, // e in e(...) - FRAME_BINARY_LEFT, // a in a + b - FRAME_BINARY_RIGHT, // b in a + b - FRAME_BUILTIN_FILTER, // When executing std.filter, used to hold intermediate state. - FRAME_BUILTIN_FORCE_THUNKS, // When forcing builtin args, holds intermediate state. - FRAME_CALL, // Used any time we have switched location in user code. - FRAME_ERROR, // e in error e - FRAME_IF, // e in if e then a else b - FRAME_IN_SUPER_ELEMENT, // e in 'e in super' - FRAME_INDEX_TARGET, // e in e[x] - FRAME_INDEX_INDEX, // e in x[e] - FRAME_INVARIANTS, // Caches the thunks that need to be executed one at a time. - FRAME_LOCAL, // Stores thunk bindings as we execute e in local ...; e - FRAME_OBJECT, // Stores intermediate state as we execute es in { [e]: ..., [e]: ... } - FRAME_OBJECT_COMP_ARRAY, // e in {f:a for x in e] - FRAME_OBJECT_COMP_ELEMENT, // Stores intermediate state when building object - FRAME_STRING_CONCAT, // Stores intermediate state while co-ercing objects - FRAME_SUPER_INDEX, // e in super[e] - FRAME_UNARY, // e in -e -}; - -/** A frame on the stack. - * - * Every time a subterm is evaluated, we first push a new stack frame to - * store the continuation. - * - * The stack frame is a bit like a tagged union, except not as memory - * efficient. The set of member variables that are actually used depends on - * the value of the member varaible kind. - * - * If the stack frame is of kind FRAME_CALL, then it counts towards the - * maximum number of stack frames allowed. Other stack frames are not - * counted. This is because FRAME_CALL exists where there is a branch in - * the code, e.g. the forcing of a thunk, evaluation of a field, calling a - * function, etc. - * - * The stack is used to mark objects during garbage - * collection, so HeapObjects not referred to from the stack may be - * prematurely collected. - */ -struct Frame { - - /** Tag (tagged union). */ - FrameKind kind; - - /** The code we were executing before. */ - const AST *ast; - - /** The location of the code we were executing before. - * - * location == ast->location when ast != nullptr - */ - LocationRange location; - - /** Reuse this stack frame for the purpose of tail call optimization. */ - bool tailCall; - - /** Used for a variety of purposes. */ - Value val; - - /** Used for a variety of purposes. */ - Value val2; - - /** Used for a variety of purposes. */ - DesugaredObject::Fields::const_iterator fit; - - /** Used for a variety of purposes. */ - std::map<const Identifier *, HeapSimpleObject::Field> objectFields; - - /** Used for a variety of purposes. */ - unsigned elementId; - - /** Used for a variety of purposes. */ - std::map<const Identifier *, HeapThunk*> elements; - - /** Used for a variety of purposes. */ - std::vector<HeapThunk*> thunks; - - /** The context is used in error messages to attempt to find a reasonable name for the - * object, function, or thunk value being executed. If it is a thunk, it is filled - * with the value when the frame terminates. - */ - HeapEntity *context; - - /** The lexically nearest object we are in, or nullptr. Note - * that this is not the same as context, because we could be inside a function, - * inside an object and then context would be the function, but self would still point - * to the object. - */ - HeapObject *self; - - /** The "super" level of self. Sometimes, we look upwards in the - * inheritance tree, e.g. via an explicit use of super, or because a given field - * has been inherited. When evaluating a field from one of these super objects, - * we need to bind self to the concrete object (so self must point - * there) but uses of super should be resolved relative to the object whose - * field we are evaluating. Thus, we keep a second field for that. This is - * usually 0, unless we are evaluating a super object's field. - */ - unsigned offset; - - /** A set of variables introduced at this point. */ - BindingFrame bindings; - - Frame(const FrameKind &kind, const AST *ast) - : kind(kind), ast(ast), location(ast->location), tailCall(false), elementId(0), - context(NULL), self(NULL), offset(0) - { - val.t = Value::NULL_TYPE; - val2.t = Value::NULL_TYPE; - } - - Frame(const FrameKind &kind, const LocationRange &location) - : kind(kind), ast(nullptr), location(location), tailCall(false), elementId(0), - context(NULL), self(NULL), offset(0) - { - val.t = Value::NULL_TYPE; - val2.t = Value::NULL_TYPE; - } - - /** Mark everything visible from this frame. */ - void mark(Heap &heap) const - { - heap.markFrom(val); - heap.markFrom(val2); - if (context) heap.markFrom(context); - if (self) heap.markFrom(self); - for (const auto &bind : bindings) - heap.markFrom(bind.second); - for (const auto &el : elements) - heap.markFrom(el.second); - for (const auto &th : thunks) - heap.markFrom(th); - } - - bool isCall(void) const - { - return kind == FRAME_CALL; - } - -}; - -/** The stack holds all the stack frames and manages the stack frame limit. */ -class Stack { - - /** How many call frames are on the stack. */ - unsigned calls; - - /** How many call frames should be allowed before aborting the program. */ - unsigned limit; - - /** The stack frames. */ - std::vector<Frame> stack; - - public: - - Stack(unsigned limit) - : calls(0), limit(limit) - { - } - - ~Stack(void) { } - - unsigned size(void) - { - return stack.size(); - } - - /** Search for the closest variable in scope that matches the given name. */ - HeapThunk *lookUpVar(const Identifier *id) - { - for (int i=stack.size()-1 ; i>=0 ; --i) { - const auto &binds = stack[i].bindings; - auto it = binds.find(id); - if (it != binds.end()) { - return it->second; - } - if (stack[i].isCall()) break; - } - return nullptr; - } - - /** Mark everything visible from the stack (any frame). */ - void mark(Heap &heap) - { - for (const auto &f : stack) { - f.mark(heap); - } - } - - Frame &top(void) - { - return stack.back(); - } - - const Frame &top(void) const - { - return stack.back(); - } - - void pop(void) - { - if (top().isCall()) calls--; - stack.pop_back(); - } - - /** Attempt to find a name for a given heap entity. This may not be possible, but we try - * reasonably hard. We look in the bindings for a variable in the closest scope that - * happens to point at the entity in question. Otherwise, the best we can do is use its - * type. - */ - std::string getName(unsigned from_here, const HeapEntity *e) - { - std::string name; - for (int i=from_here-1 ; i>=0; --i) { - const auto &f = stack[i]; - for (const auto &pair : f.bindings) { - HeapThunk *thunk = pair.second; - if (!thunk->filled) continue; - if (!thunk->content.isHeap()) continue; - if (e != thunk->content.v.h) continue; - name = encode_utf8(pair.first->name); - } - // Do not go into the next call frame, keep local reasoning. - if (f.isCall()) break; - } - - if (name == "") name = "anonymous"; - if (dynamic_cast<const HeapObject*>(e)) { - return "object <" + name + ">"; - } else if (auto *thunk = dynamic_cast<const HeapThunk*>(e)) { - if (thunk->name == nullptr) { - return ""; // Argument of builtin, or root (since top level functions). - } else { - return "thunk <" + encode_utf8(thunk->name->name) + ">"; - } - } else { - const auto *func = static_cast<const HeapClosure *>(e); - if (func->body == nullptr) { - return "builtin function <" + func->builtinName + ">"; - } - return "function <" + name + ">"; - } - } - - /** Dump the stack. - * - * This is useful to help debug the VM in gdb. It is virtual to stop it - * being removed by the compiler. - */ - virtual void dump(void) - { - for (unsigned i=0 ; i<stack.size() ; ++i) { - std::cout << "stack[" << i << "] = " << stack[i].location - << " (" << stack[i].kind << ")" - << std::endl; - } - std::cout << std::endl; - } - - /** Creates the error object for throwing, and also populates it with the stack trace. - */ - RuntimeError makeError(const LocationRange &loc, const std::string &msg) - { - std::vector<TraceFrame> stack_trace; - stack_trace.push_back(TraceFrame(loc)); - for (int i=stack.size()-1 ; i>=0 ; --i) { - const auto &f = stack[i]; - if (f.isCall()) { - if (f.context != nullptr) { - // Give the last line a name. - stack_trace[stack_trace.size()-1].name = getName(i, f.context); - } - if (f.location.isSet() || f.location.file.length() > 0) - stack_trace.push_back(TraceFrame(f.location)); - } - } - return RuntimeError(stack_trace, msg); - } - - /** New (non-call) frame. */ - template <class... Args> void newFrame(Args... args) - { - stack.emplace_back(args...); - } - - /** If there is a tailstrict annotated frame followed by some locals, pop them all. */ - void tailCallTrimStack (void) - { - for (int i=stack.size()-1 ; i>=0 ; --i) { - switch (stack[i].kind) { - case FRAME_CALL: { - if (!stack[i].tailCall || stack[i].thunks.size() > 0) { - return; - } - // Remove all stack frames including this one. - while (stack.size() > unsigned(i)) stack.pop_back(); - calls--; - return; - } break; - - case FRAME_LOCAL: break; - - default: return; - } - } - } - - /** New call frame. */ - void newCall(const LocationRange &loc, HeapEntity *context, HeapObject *self, - unsigned offset, const BindingFrame &up_values) - { - tailCallTrimStack(); - if (calls >= limit) { - throw makeError(loc, "Max stack frames exceeded."); - } - stack.emplace_back(FRAME_CALL, loc); - calls++; - top().context = context; - top().self = self; - top().offset = offset; - top().bindings = up_values; - top().tailCall = false; - - #ifndef NDEBUG - for (const auto &bind : up_values) { - if (bind.second == nullptr) { - std::cerr << "INTERNAL ERROR: No binding for variable " - << encode_utf8(bind.first->name) << std::endl; - std::abort(); - } - } - #endif - } - - /** Look up the stack to find the self binding. */ - void getSelfBinding(HeapObject *&self, unsigned &offset) - { - self = nullptr; - offset = 0; - for (int i=stack.size() - 1 ; i>=0 ; --i) { - if (stack[i].isCall()) { - self = stack[i].self; - offset = stack[i].offset; - return; - } - } - } - - /** Look up the stack to see if we're running assertions for this object. */ - bool alreadyExecutingInvariants(HeapObject *self) - { - for (int i=stack.size() - 1 ; i>=0 ; --i) { - if (stack[i].kind == FRAME_INVARIANTS) { - if (stack[i].self == self) return true; - } - } - return false; - } -}; - -/** Typedef to save some typing. */ -typedef std::map<std::string, VmExt> ExtMap; - -/** Typedef to save some typing. */ -typedef std::map<std::string, std::string> StrMap; - - -class Interpreter; - -typedef const AST *(Interpreter::*BuiltinFunc)(const LocationRange &loc, - const std::vector<Value> &args); - -/** Holds the intermediate state during execution and implements the necessary functions to - * implement the semantics of the language. - * - * The garbage collector used is a simple stop-the-world mark and sweep collector. It runs upon - * memory allocation if the heap is large enough and has grown enough since the last collection. - * All reachable entities have their mark field incremented. Then all entities with the old - * mark are removed from the heap. - */ -class Interpreter { - - /** The heap. */ - Heap heap; - - /** The value last computed. */ - Value scratch; - - /** The stack. */ - Stack stack; - - /** Used to create ASTs if needed. - * - * This is used at import time, and in a few other cases. - */ - Allocator *alloc; - - /** Used to "name" thunks created to cache imports. */ - const Identifier *idImport; - - /** Used to "name" thunks created on the inside of an array. */ - const Identifier *idArrayElement; - - /** Used to "name" thunks created to execute invariants. */ - const Identifier *idInvariant; - - /** Used to "name" thunks created to convert JSON to Jsonnet objects. */ - const Identifier *idJsonObjVar; - - /** Used to refer to idJsonObjVar. */ - const AST *jsonObjVar; - - struct ImportCacheValue { - std::string foundHere; - std::string content; - /** Thunk to store cached result of execution. - * - * Null if this file was only ever successfully imported with importstr. - */ - HeapThunk *thunk; - }; - - /** Cache for imported Jsonnet files. */ - std::map<std::pair<std::string, UString>, ImportCacheValue *> cachedImports; - - /** External variables for std.extVar. */ - ExtMap externalVars; - - /** The callback used for loading imported files. */ - VmNativeCallbackMap nativeCallbacks; - - /** The callback used for loading imported files. */ - JsonnetImportCallback *importCallback; - - /** User context pointer for the import callback. */ - void *importCallbackContext; - - /** Builtin functions by name. */ - typedef std::map<std::string, BuiltinFunc> BuiltinMap; - BuiltinMap builtins; - - RuntimeError makeError(const LocationRange &loc, const std::string &msg) - { - return stack.makeError(loc, msg); - } - - /** Create an object on the heap, maybe collect garbage. - * \param T Something under HeapEntity - * \returns The new object - */ - template <class T, class... Args> T* makeHeap(Args&&... args) - { - T *r = heap.makeEntity<T, Args...>(std::forward<Args>(args)...); - if (heap.checkHeap()) { // Do a GC cycle? - // Avoid the object we just made being collected. - heap.markFrom(r); - - // Mark from the stack. - stack.mark(heap); - - // Mark from the scratch register - heap.markFrom(scratch); - - // Mark from cached imports - for (const auto &pair : cachedImports) { - HeapThunk *thunk = pair.second->thunk; - if (thunk != nullptr) - heap.markFrom(thunk); - } - - // Delete unreachable objects. - heap.sweep(); - } - return r; - } - - Value makeBoolean(bool v) - { - Value r; - r.t = Value::BOOLEAN; - r.v.b = v; - return r; - } - - Value makeDouble(double v) - { - Value r; - r.t = Value::DOUBLE; - r.v.d = v; - return r; - } - - Value makeDoubleCheck(const LocationRange &loc, double v) - { - if (std::isnan(v)) { - throw makeError(loc, "Not a number"); - } - if (std::isinf(v)) { - throw makeError(loc, "Overflow"); - } - return makeDouble(v); - } - - Value makeNull(void) - { - Value r; - r.t = Value::NULL_TYPE; - return r; - } - - Value makeArray(const std::vector<HeapThunk*> &v) - { - Value r; - r.t = Value::ARRAY; - r.v.h = makeHeap<HeapArray>(v); - return r; - } - - Value makeClosure(const BindingFrame &env, - HeapObject *self, - unsigned offset, - const HeapClosure::Params ¶ms, - AST *body) - { - Value r; - r.t = Value::FUNCTION; - r.v.h = makeHeap<HeapClosure>(env, self, offset, params, body, ""); - return r; - } - - Value makeNativeBuiltin(const std::string &name, const std::vector<std::string> ¶ms) - { - HeapClosure::Params hc_params; - for (const auto &p : params) { - hc_params.emplace_back(alloc->makeIdentifier(decode_utf8(p)), nullptr); - } - return makeBuiltin(name, hc_params); - } - - Value makeBuiltin(const std::string &name, const HeapClosure::Params ¶ms) - { - AST *body = nullptr; - Value r; - r.t = Value::FUNCTION; - r.v.h = makeHeap<HeapClosure>(BindingFrame(), nullptr, 0, params, body, name); - return r; - } - - template <class T, class... Args> Value makeObject(Args... args) - { - Value r; - r.t = Value::OBJECT; - r.v.h = makeHeap<T>(args...); - return r; - } - - Value makeString(const UString &v) - { - Value r; - r.t = Value::STRING; - r.v.h = makeHeap<HeapString>(v); - return r; - } - - /** Auxiliary function of objectIndex. - * - * Traverse the object's tree from right to left, looking for an object - * with the given field. Call with offset initially set to 0. - * - * \param f The field we're looking for. - * \param start_from Step over this many leaves first. - * \param counter Return the level of "super" that contained the field. - * \returns The first object with the field, or nullptr if it could not be found. - */ - HeapLeafObject *findObject(const Identifier *f, HeapObject *curr, - unsigned start_from, unsigned &counter) - { - if (auto *ext = dynamic_cast<HeapExtendedObject*>(curr)) { - auto *r = findObject(f, ext->right, start_from, counter); - if (r) return r; - auto *l = findObject(f, ext->left, start_from, counter); - if (l) return l; - } else { - if (counter >= start_from) { - if (auto *simp = dynamic_cast<HeapSimpleObject*>(curr)) { - auto it = simp->fields.find(f); - if (it != simp->fields.end()) { - return simp; - } - } else if (auto *comp = dynamic_cast<HeapComprehensionObject*>(curr)) { - auto it = comp->compValues.find(f); - if (it != comp->compValues.end()) { - return comp; - } - } - } - counter++; - } - return nullptr; - } - - typedef std::map<const Identifier*, ObjectField::Hide> IdHideMap; - - /** Auxiliary function. - */ - IdHideMap objectFieldsAux(const HeapObject *obj_) - { - IdHideMap r; - if (auto *obj = dynamic_cast<const HeapSimpleObject*>(obj_)) { - for (const auto &f : obj->fields) { - r[f.first] = f.second.hide; - } - - } else if (auto *obj = dynamic_cast<const HeapExtendedObject*>(obj_)) { - r = objectFieldsAux(obj->right); - for (const auto &pair : objectFieldsAux(obj->left)) { - auto it = r.find(pair.first); - if (it == r.end()) { - // First time it is seen - r[pair.first] = pair.second; - } else if (it->second == ObjectField::INHERIT) { - // Seen before, but with inherited visibility so use new visibility - r[pair.first] = pair.second; - } - } - - } else if (auto *obj = dynamic_cast<const HeapComprehensionObject*>(obj_)) { - for (const auto &f : obj->compValues) - r[f.first] = ObjectField::VISIBLE; - } - return r; - } - - /** Auxiliary function. - */ - std::set<const Identifier*> objectFields(const HeapObject *obj_, bool manifesting) - { - std::set<const Identifier*> r; - for (const auto &pair : objectFieldsAux(obj_)) { - if (!manifesting || pair.second != ObjectField::HIDDEN) r.insert(pair.first); - } - return r; - } - - /** Import another Jsonnet file. - * - * If the file has already been imported, then use that version. This maintains - * referential transparency in the case of writes to disk during execution. The - * cache holds a thunk in order to cache the resulting value of execution. - * - * \param loc Location of the import statement. - * \param file Path to the filename. - */ - HeapThunk *import(const LocationRange &loc, const LiteralString *file) - { - ImportCacheValue *input = importString(loc, file); - if (input->thunk == nullptr) { - Tokens tokens = jsonnet_lex(input->foundHere, input->content.c_str()); - AST *expr = jsonnet_parse(alloc, tokens); - jsonnet_desugar(alloc, expr, nullptr); - jsonnet_static_analysis(expr); - // If no errors then populate cache. - auto *thunk = makeHeap<HeapThunk>(idImport, nullptr, 0, expr); - input->thunk = thunk; - } - return input->thunk; - } - - /** Import a file as a string. - * - * If the file has already been imported, then use that version. This maintains - * referential transparency in the case of writes to disk during execution. - * - * \param loc Location of the import statement. - * \param file Path to the filename. - * \param found_here If non-null, used to store the actual path of the file - */ - ImportCacheValue *importString(const LocationRange &loc, const LiteralString *file) - { - std::string dir = dir_name(loc.file); - - const UString &path = file->value; - - std::pair<std::string, UString> key(dir, path); - ImportCacheValue *cached_value = cachedImports[key]; - if (cached_value != nullptr) - return cached_value; - - int success = 0; - char *found_here_cptr; - char *content = - importCallback(importCallbackContext, dir.c_str(), encode_utf8(path).c_str(), - &found_here_cptr, &success); - - std::string input(content); - ::free(content); - - if (!success) { - std::string msg = "Couldn't open import \"" + encode_utf8(path) + "\": "; - msg += input; - throw makeError(loc, msg); - } - - auto *input_ptr = new ImportCacheValue(); - input_ptr->foundHere = found_here_cptr; - input_ptr->content = input; - input_ptr->thunk = nullptr; // May be filled in later by import(). - ::free(found_here_cptr); - cachedImports[key] = input_ptr; - return input_ptr; - } - - /** Capture the required variables from the environment. */ - BindingFrame capture(const std::vector<const Identifier*> &free_vars) - { - BindingFrame env; - for (auto fv : free_vars) { - auto *th = stack.lookUpVar(fv); - env[fv] = th; - } - return env; - } - - /** Count the number of leaves in the tree. - * - * \param obj The root of the tree. - * \returns The number of leaves. - */ - unsigned countLeaves(HeapObject *obj) - { - if (auto *ext = dynamic_cast<HeapExtendedObject*>(obj)) { - return countLeaves(ext->left) + countLeaves(ext->right); - } else { - // Must be a HeapLeafObject. - return 1; - } - } - - public: - - /** Create a new interpreter. - * - * \param loc The location range of the file to be executed. - */ - Interpreter( - Allocator *alloc, - const ExtMap &ext_vars, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &native_callbacks, - JsonnetImportCallback *import_callback, - void *import_callback_context) - - : heap(gc_min_objects, gc_growth_trigger), - stack(max_stack), - alloc(alloc), - idImport(alloc->makeIdentifier(U"import")), - idArrayElement(alloc->makeIdentifier(U"array_element")), - idInvariant(alloc->makeIdentifier(U"object_assert")), - idJsonObjVar(alloc->makeIdentifier(U"_")), - jsonObjVar(alloc->make<Var>(LocationRange(), Fodder{}, idJsonObjVar)), - externalVars(ext_vars), - nativeCallbacks(native_callbacks), - importCallback(import_callback), - importCallbackContext(import_callback_context) - { - scratch = makeNull(); - builtins["makeArray"] = &Interpreter::builtinMakeArray; - builtins["pow"] = &Interpreter::builtinPow; - builtins["floor"] = &Interpreter::builtinFloor; - builtins["ceil"] = &Interpreter::builtinCeil; - builtins["sqrt"] = &Interpreter::builtinSqrt; - builtins["sin"] = &Interpreter::builtinSin; - builtins["cos"] = &Interpreter::builtinCos; - builtins["tan"] = &Interpreter::builtinTan; - builtins["asin"] = &Interpreter::builtinAsin; - builtins["acos"] = &Interpreter::builtinAcos; - builtins["atan"] = &Interpreter::builtinAtan; - builtins["type"] = &Interpreter::builtinType; - builtins["filter"] = &Interpreter::builtinFilter; - builtins["objectHasEx"] = &Interpreter::builtinObjectHasEx; - builtins["length"] = &Interpreter::builtinLength; - builtins["objectFieldsEx"] = &Interpreter::builtinObjectFieldsEx; - builtins["codepoint"] = &Interpreter::builtinCodepoint; - builtins["char"] = &Interpreter::builtinChar; - builtins["log"] = &Interpreter::builtinLog; - builtins["exp"] = &Interpreter::builtinExp; - builtins["mantissa"] = &Interpreter::builtinMantissa; - builtins["exponent"] = &Interpreter::builtinExponent; - builtins["modulo"] = &Interpreter::builtinModulo; - builtins["extVar"] = &Interpreter::builtinExtVar; - builtins["primitiveEquals"] = &Interpreter::builtinPrimitiveEquals; - builtins["native"] = &Interpreter::builtinNative; - builtins["md5"] = &Interpreter::builtinMd5; - } - - /** Clean up the heap, stack, stash, and builtin function ASTs. */ - ~Interpreter() - { - for (const auto &pair : cachedImports) { - delete pair.second; - } - } - - const Value &getScratchRegister(void) - { - return scratch; - } - - void setScratchRegister(const Value &v) - { - scratch = v; - } - - - /** Raise an error if the arguments aren't the expected types. */ - void validateBuiltinArgs(const LocationRange &loc, - const std::string &name, - const std::vector<Value> &args, - const std::vector<Value::Type> params) - { - if (args.size() == params.size()) { - for (unsigned i=0 ; i<args.size() ; ++i) { - if (args[i].t != params[i]) goto bad; - } - return; - } - bad:; - std::stringstream ss; - ss << "Builtin function " + name + " expected ("; - const char *prefix = ""; - for (auto p : params) { - ss << prefix << type_str(p); - prefix = ", "; - } - ss << ") but got ("; - prefix = ""; - for (auto a : args) { - ss << prefix << type_str(a); - prefix = ", "; - } - ss << ")"; - throw makeError(loc, ss.str()); - } - - const AST *builtinMakeArray(const LocationRange &loc, const std::vector<Value> &args) - { - Frame &f = stack.top(); - validateBuiltinArgs(loc, "makeArray", args, - {Value::DOUBLE, Value::FUNCTION}); - long sz = long(args[0].v.d); - if (sz < 0) { - std::stringstream ss; - ss << "makeArray requires size >= 0, got " << sz; - throw makeError(loc, ss.str()); - } - auto *func = static_cast<const HeapClosure*>(args[1].v.h); - std::vector<HeapThunk*> elements; - if (func->params.size() != 1) { - std::stringstream ss; - ss << "makeArray function must take 1 param, got: " << func->params.size(); - throw makeError(loc, ss.str()); - } - elements.resize(sz); - for (long i=0 ; i<sz ; ++i) { - auto *th = makeHeap<HeapThunk>(idArrayElement, func->self, func->offset, func->body); - // The next line stops the new thunks from being GCed. - f.thunks.push_back(th); - th->upValues = func->upValues; - - auto *el = makeHeap<HeapThunk>(func->params[0].id, nullptr, 0, nullptr); - el->fill(makeDouble(i)); // i guaranteed not to be inf/NaN - th->upValues[func->params[0].id] = el; - elements[i] = th; - } - scratch = makeArray(elements); - return nullptr; - } - - const AST *builtinPow(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "pow", args, {Value::DOUBLE, Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::pow(args[0].v.d, args[1].v.d)); - return nullptr; - } - - const AST *builtinFloor(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "floor", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::floor(args[0].v.d)); - return nullptr; - } - - const AST *builtinCeil(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "ceil", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::ceil(args[0].v.d)); - return nullptr; - } - - const AST *builtinSqrt(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "sqrt", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::sqrt(args[0].v.d)); - return nullptr; - } - - const AST *builtinSin(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "sin", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::sin(args[0].v.d)); - return nullptr; - } - - const AST *builtinCos(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "cos", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::cos(args[0].v.d)); - return nullptr; - } - - const AST *builtinTan(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "tan", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::tan(args[0].v.d)); - return nullptr; - } - - const AST *builtinAsin(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "asin", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::asin(args[0].v.d)); - return nullptr; - } - - const AST *builtinAcos(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "acos", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::acos(args[0].v.d)); - return nullptr; - } - - const AST *builtinAtan(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "atan", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::atan(args[0].v.d)); - return nullptr; - } - - const AST *builtinType(const LocationRange &, const std::vector<Value> &args) - { - switch (args[0].t) { - case Value::NULL_TYPE: - scratch = makeString(U"null"); - return nullptr; - - case Value::BOOLEAN: - scratch = makeString(U"boolean"); - return nullptr; - - case Value::DOUBLE: - scratch = makeString(U"number"); - return nullptr; - - case Value::ARRAY: - scratch = makeString(U"array"); - return nullptr; - - case Value::FUNCTION: - scratch = makeString(U"function"); - return nullptr; - - case Value::OBJECT: - scratch = makeString(U"object"); - return nullptr; - - case Value::STRING: - scratch = makeString(U"string"); - return nullptr; - } - return nullptr; // Quiet, compiler. - } - - const AST *builtinFilter(const LocationRange &loc, const std::vector<Value> &args) - { - Frame &f = stack.top(); - validateBuiltinArgs(loc, "filter", args, {Value::FUNCTION, Value::ARRAY}); - auto *func = static_cast<HeapClosure*>(args[0].v.h); - auto *arr = static_cast<HeapArray*>(args[1].v.h); - if (func->params.size() != 1) { - throw makeError(loc, "filter function takes 1 parameter."); - } - if (arr->elements.size() == 0) { - scratch = makeArray({}); - } else { - f.kind = FRAME_BUILTIN_FILTER; - f.val = args[0]; - f.val2 = args[1]; - f.thunks.clear(); - f.elementId = 0; - - auto *thunk = arr->elements[f.elementId]; - BindingFrame bindings = func->upValues; - bindings[func->params[0].id] = thunk; - stack.newCall(loc, func, func->self, func->offset, bindings); - return func->body; - } - return nullptr; - } - - const AST *builtinObjectHasEx(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "objectHasEx", args, - {Value::OBJECT, Value::STRING, - Value::BOOLEAN}); - const auto *obj = static_cast<const HeapObject*>(args[0].v.h); - const auto *str = static_cast<const HeapString*>(args[1].v.h); - bool include_hidden = args[2].v.b; - bool found = false; - for (const auto &field : objectFields(obj, !include_hidden)) { - if (field->name == str->value) { - found = true; - break; - } - } - scratch = makeBoolean(found); - return nullptr; - } - - const AST *builtinLength(const LocationRange &loc, const std::vector<Value> &args) - { - if (args.size() != 1) { - throw makeError(loc, "length takes 1 parameter."); - } - HeapEntity *e = args[0].v.h; - switch (args[0].t) { - case Value::OBJECT: { - auto fields = objectFields(static_cast<HeapObject*>(e), true); - scratch = makeDouble(fields.size()); - } break; - - case Value::ARRAY: - scratch = makeDouble(static_cast<HeapArray*>(e)->elements.size()); - break; - - case Value::STRING: - scratch = makeDouble(static_cast<HeapString*>(e)->value.length()); - break; - - case Value::FUNCTION: - scratch = makeDouble(static_cast<HeapClosure*>(e)->params.size()); - break; - - default: - throw makeError(loc, - "length operates on strings, objects, " - "and arrays, got " + type_str(args[0])); - } - return nullptr; - } - - const AST *builtinObjectFieldsEx(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "objectFieldsEx", args, - {Value::OBJECT, Value::BOOLEAN}); - const auto *obj = static_cast<HeapObject*>(args[0].v.h); - bool include_hidden = args[1].v.b; - // Stash in a set first to sort them. - std::set<UString> fields; - for (const auto &field : objectFields(obj, !include_hidden)) { - fields.insert(field->name); - } - scratch = makeArray({}); - auto &elements = static_cast<HeapArray*>(scratch.v.h)->elements; - for (const auto &field : fields) { - auto *th = makeHeap<HeapThunk>(idArrayElement, nullptr, 0, nullptr); - elements.push_back(th); - th->fill(makeString(field)); - } - return nullptr; - } - - const AST *builtinCodepoint(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "codepoint", args, {Value::STRING}); - const UString &str = - static_cast<HeapString*>(args[0].v.h)->value; - if (str.length() != 1) { - std::stringstream ss; - ss << "codepoint takes a string of length 1, got length " - << str.length(); - throw makeError(loc, ss.str()); - } - char32_t c = static_cast<HeapString*>(args[0].v.h)->value[0]; - scratch = makeDouble((unsigned long)(c)); - return nullptr; - } - - const AST *builtinChar(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "char", args, {Value::DOUBLE}); - long l = long(args[0].v.d); - if (l < 0) { - std::stringstream ss; - ss << "Codepoints must be >= 0, got " << l; - throw makeError(loc, ss.str()); - } - if (l >= JSONNET_CODEPOINT_MAX) { - std::stringstream ss; - ss << "Invalid unicode codepoint, got " << l; - throw makeError(loc, ss.str()); - } - char32_t c = l; - scratch = makeString(UString(&c, 1)); - return nullptr; - } - - const AST *builtinLog(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "log", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::log(args[0].v.d)); - return nullptr; - } - - const AST *builtinExp(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "exp", args, {Value::DOUBLE}); - scratch = makeDoubleCheck(loc, std::exp(args[0].v.d)); - return nullptr; - } - - const AST *builtinMantissa(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "mantissa", args, {Value::DOUBLE}); - int exp; - double m = std::frexp(args[0].v.d, &exp); - scratch = makeDoubleCheck(loc, m); - return nullptr; - } - - const AST *builtinExponent(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "exponent", args, {Value::DOUBLE}); - int exp; - std::frexp(args[0].v.d, &exp); - scratch = makeDoubleCheck(loc, exp); - return nullptr; - } - - const AST *builtinModulo(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "modulo", args, {Value::DOUBLE, Value::DOUBLE}); - double a = args[0].v.d; - double b = args[1].v.d; - if (b == 0) - throw makeError(loc, "Division by zero."); - scratch = makeDoubleCheck(loc, std::fmod(a, b)); - return nullptr; - } - - const AST *builtinExtVar(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "extVar", args, {Value::STRING}); - const UString &var = - static_cast<HeapString*>(args[0].v.h)->value; - std::string var8 = encode_utf8(var); - auto it = externalVars.find(var8); - if (it == externalVars.end()) { - std::string msg = "Undefined external variable: " + var8; - throw makeError(loc, msg); - } - const VmExt &ext = it->second; - if (ext.isCode) { - std::string filename = "<extvar:" + var8 + ">"; - Tokens tokens = jsonnet_lex(filename, ext.data.c_str()); - AST *expr = jsonnet_parse(alloc, tokens); - jsonnet_desugar(alloc, expr, nullptr); - jsonnet_static_analysis(expr); - stack.pop(); - return expr; - } else { - scratch = makeString(decode_utf8(ext.data)); - return nullptr; - } - } - - const AST *builtinPrimitiveEquals(const LocationRange &loc, const std::vector<Value> &args) - { - if (args.size() != 2) { - std::stringstream ss; - ss << "primitiveEquals takes 2 parameters, got " << args.size(); - throw makeError(loc, ss.str()); - } - if (args[0].t != args[1].t) { - scratch = makeBoolean(false); - return nullptr; - } - bool r; - switch (args[0].t) { - case Value::BOOLEAN: - r = args[0].v.b == args[1].v.b; - break; - - case Value::DOUBLE: - r = args[0].v.d == args[1].v.d; - break; - - case Value::STRING: - r = static_cast<HeapString*>(args[0].v.h)->value - == static_cast<HeapString*>(args[1].v.h)->value; - break; - - case Value::NULL_TYPE: - r = true; - break; - - case Value::FUNCTION: - throw makeError(loc, "Cannot test equality of functions"); - break; - - default: - throw makeError(loc, - "primitiveEquals operates on primitive " - "types, got " + type_str(args[0])); - } - scratch = makeBoolean(r); - return nullptr; - } - - const AST *builtinNative(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "native", args, {Value::STRING}); - - std::string builtin_name = encode_utf8(static_cast<HeapString*>(args[0].v.h)->value); - - VmNativeCallbackMap::const_iterator nit = nativeCallbacks.find(builtin_name); - if (nit == nativeCallbacks.end()) { - throw makeError(loc, "Unrecognized native function name: " + builtin_name); - } - - const VmNativeCallback &cb = nit->second; - scratch = makeNativeBuiltin(builtin_name, cb.params); - return nullptr; - } - - const AST *builtinMd5(const LocationRange &loc, const std::vector<Value> &args) - { - validateBuiltinArgs(loc, "md5", args, {Value::STRING}); - - std::string value = encode_utf8(static_cast<HeapString*>(args[0].v.h)->value); - - scratch = makeString(decode_utf8(md5(value))); - return nullptr; - } - - void jsonToHeap(const std::unique_ptr<JsonnetJsonValue> &v, bool &filled, Value &attach) - { - // In order to not anger the garbage collector, assign to attach immediately after - // making the heap object. - switch (v->kind) { - case JsonnetJsonValue::STRING: - attach = makeString(decode_utf8(v->string)); - filled = true; - break; - - case JsonnetJsonValue::BOOL: - attach = makeBoolean(v->number != 0.0); - filled = true; - break; - - case JsonnetJsonValue::NUMBER: - attach = makeDouble(v->number); - filled = true; - break; - - case JsonnetJsonValue::NULL_KIND: - attach = makeNull(); - filled = true; - break; - - case JsonnetJsonValue::ARRAY: { - attach = makeArray(std::vector<HeapThunk*>{}); - filled = true; - auto *arr = static_cast<HeapArray*>(attach.v.h); - for (size_t i = 0; i < v->elements.size() ; ++i) { - arr->elements.push_back( - makeHeap<HeapThunk>(idArrayElement, nullptr, 0, nullptr)); - jsonToHeap(v->elements[i], arr->elements[i]->filled, arr->elements[i]->content); - } - } break; - - case JsonnetJsonValue::OBJECT: { - attach = makeObject<HeapComprehensionObject>( - BindingFrame{}, jsonObjVar, idJsonObjVar, BindingFrame{}); - filled = true; - auto *obj = static_cast<HeapComprehensionObject*>(attach.v.h); - for (const auto &pair : v->fields) { - auto *thunk = makeHeap<HeapThunk>(idJsonObjVar, nullptr, 0, nullptr); - obj->compValues[alloc->makeIdentifier(decode_utf8(pair.first))] = thunk; - jsonToHeap(pair.second, thunk->filled, thunk->content); - } - } break; - } - } - - - UString toString(const LocationRange &loc) - { - return manifestJson(loc, false, U""); - } - - - - /** Recursively collect an object's invariants. - * - * \param curr - * \param self - * \param offset - * \param thunks - */ - void objectInvariants(HeapObject *curr, HeapObject *self, - unsigned &counter, std::vector<HeapThunk*> &thunks) - { - if (auto *ext = dynamic_cast<HeapExtendedObject*>(curr)) { - objectInvariants(ext->right, self, counter, thunks); - objectInvariants(ext->left, self, counter, thunks); - } else { - if (auto *simp = dynamic_cast<HeapSimpleObject*>(curr)) { - for (AST *assert : simp->asserts) { - auto *el_th = makeHeap<HeapThunk>(idInvariant, self, counter, assert); - el_th->upValues = simp->upValues; - thunks.push_back(el_th); - } - } - counter++; - } - } - - /** Index an object's field. - * - * \param loc Location where the e.f occured. - * \param obj The target - * \param f The field - */ - const AST *objectIndex(const LocationRange &loc, HeapObject *obj, - const Identifier *f, unsigned offset) - { - unsigned found_at = 0; - HeapObject *self = obj; - HeapLeafObject *found = findObject(f, obj, offset, found_at); - if (found == nullptr) { - throw makeError(loc, "Field does not exist: " + encode_utf8(f->name)); - } - if (auto *simp = dynamic_cast<HeapSimpleObject*>(found)) { - auto it = simp->fields.find(f); - const AST *body = it->second.body; - - stack.newCall(loc, simp, self, found_at, simp->upValues); - return body; - } else { - // If a HeapLeafObject is not HeapSimpleObject, it must be HeapComprehensionObject. - auto *comp = static_cast<HeapComprehensionObject*>(found); - auto it = comp->compValues.find(f); - auto *th = it->second; - BindingFrame binds = comp->upValues; - binds[comp->id] = th; - stack.newCall(loc, comp, self, found_at, binds); - return comp->value; - } - } - - void runInvariants(const LocationRange &loc, HeapObject *self) - { - if (stack.alreadyExecutingInvariants(self)) return; - - unsigned counter = 0; - unsigned initial_stack_size = stack.size(); - stack.newFrame(FRAME_INVARIANTS, loc); - std::vector<HeapThunk*> &thunks = stack.top().thunks; - objectInvariants(self, self, counter, thunks); - if (thunks.size() == 0) { - stack.pop(); - return; - } - HeapThunk *thunk = thunks[0]; - stack.top().elementId = 1; - stack.top().self = self; - stack.newCall(loc, thunk, thunk->self, thunk->offset, thunk->upValues); - evaluate(thunk->body, initial_stack_size); - } - - /** Evaluate the given AST to a value. - * - * Rather than call itself recursively, this function maintains a separate stack of - * partially-evaluated constructs. First, the AST is handled depending on its type. If - * this cannot be completed without evaluating another AST (e.g. a sub expression) then a - * frame is pushed onto the stack containing the partial state, and the code jumps back to - * the beginning of this function. Once there are no more ASTs to evaluate, the code - * executes the second part of the function to unwind the stack. If the stack cannot be - * completely unwound without evaluating an AST then it jumps back to the beginning of the - * function again. The process terminates when the AST has been processed and the stack is - * the same size it was at the beginning of the call to evaluate. - */ - void evaluate(const AST *ast_, unsigned initial_stack_size) - { - recurse: - - switch (ast_->type) { - case AST_APPLY: { - const auto &ast = *static_cast<const Apply*>(ast_); - stack.newFrame(FRAME_APPLY_TARGET, ast_); - ast_ = ast.target; - goto recurse; - } break; - - case AST_ARRAY: { - const auto &ast = *static_cast<const Array*>(ast_); - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - scratch = makeArray({}); - auto &elements = static_cast<HeapArray*>(scratch.v.h)->elements; - for (const auto &el : ast.elements) { - auto *el_th = makeHeap<HeapThunk>(idArrayElement, self, offset, el.expr); - el_th->upValues = capture(el.expr->freeVariables); - elements.push_back(el_th); - } - } break; - - case AST_BINARY: { - const auto &ast = *static_cast<const Binary*>(ast_); - stack.newFrame(FRAME_BINARY_LEFT, ast_); - ast_ = ast.left; - goto recurse; - } break; - - case AST_BUILTIN_FUNCTION: { - const auto &ast = *static_cast<const BuiltinFunction*>(ast_); - HeapClosure::Params params; - params.reserve(ast.params.size()); - for (const auto &p : ast.params) { - // None of the builtins have default args. - params.emplace_back(p, nullptr); - } - scratch = makeBuiltin(ast.name, params); - } break; - - case AST_CONDITIONAL: { - const auto &ast = *static_cast<const Conditional*>(ast_); - stack.newFrame(FRAME_IF, ast_); - ast_ = ast.cond; - goto recurse; - } break; - - case AST_ERROR: { - const auto &ast = *static_cast<const Error*>(ast_); - stack.newFrame(FRAME_ERROR, ast_); - ast_ = ast.expr; - goto recurse; - } break; - - case AST_FUNCTION: { - const auto &ast = *static_cast<const Function*>(ast_); - auto env = capture(ast.freeVariables); - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - HeapClosure::Params params; - params.reserve(ast.params.size()); - for (const auto &p : ast.params) { - params.emplace_back(p.id, p.expr); - } - scratch = makeClosure(env, self, offset, params, ast.body); - } break; - - case AST_IMPORT: { - const auto &ast = *static_cast<const Import*>(ast_); - HeapThunk *thunk = import(ast.location, ast.file); - if (thunk->filled) { - scratch = thunk->content; - } else { - stack.newCall(ast.location, thunk, thunk->self, thunk->offset, thunk->upValues); - ast_ = thunk->body; - goto recurse; - } - } break; - - case AST_IMPORTSTR: { - const auto &ast = *static_cast<const Importstr*>(ast_); - const ImportCacheValue *value = importString(ast.location, ast.file); - scratch = makeString(decode_utf8(value->content)); - } break; - - case AST_IN_SUPER: { - const auto &ast = *static_cast<const InSuper*>(ast_); - stack.newFrame(FRAME_IN_SUPER_ELEMENT, ast_); - ast_ = ast.element; - goto recurse; - } break; - - case AST_INDEX: { - const auto &ast = *static_cast<const Index*>(ast_); - stack.newFrame(FRAME_INDEX_TARGET, ast_); - ast_ = ast.target; - goto recurse; - } break; - - case AST_LOCAL: { - const auto &ast = *static_cast<const Local*>(ast_); - stack.newFrame(FRAME_LOCAL, ast_); - Frame &f = stack.top(); - // First build all the thunks and bind them. - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - for (const auto &bind : ast.binds) { - // Note that these 2 lines must remain separate to avoid the GC running - // when bindings has a nullptr for key bind.first. - auto *th = makeHeap<HeapThunk>(bind.var, self, offset, bind.body); - f.bindings[bind.var] = th; - } - // Now capture the environment (including the new thunks, to make cycles). - for (const auto &bind : ast.binds) { - auto *thunk = f.bindings[bind.var]; - thunk->upValues = capture(bind.body->freeVariables); - } - ast_ = ast.body; - goto recurse; - } break; - - case AST_LITERAL_BOOLEAN: { - const auto &ast = *static_cast<const LiteralBoolean*>(ast_); - scratch = makeBoolean(ast.value); - } break; - - case AST_LITERAL_NUMBER: { - const auto &ast = *static_cast<const LiteralNumber*>(ast_); - scratch = makeDoubleCheck(ast_->location, ast.value); - } break; - - case AST_LITERAL_STRING: { - const auto &ast = *static_cast<const LiteralString*>(ast_); - scratch = makeString(ast.value); - } break; - - case AST_LITERAL_NULL: { - scratch = makeNull(); - } break; - - case AST_DESUGARED_OBJECT: { - const auto &ast = *static_cast<const DesugaredObject*>(ast_); - if (ast.fields.empty()) { - auto env = capture(ast.freeVariables); - std::map<const Identifier *, HeapSimpleObject::Field> fields; - scratch = makeObject<HeapSimpleObject>(env, fields, ast.asserts); - } else { - auto env = capture(ast.freeVariables); - stack.newFrame(FRAME_OBJECT, ast_); - auto fit = ast.fields.begin(); - stack.top().fit = fit; - ast_ = fit->name; - goto recurse; - } - } break; - - case AST_OBJECT_COMPREHENSION_SIMPLE: { - const auto &ast = *static_cast<const ObjectComprehensionSimple*>(ast_); - stack.newFrame(FRAME_OBJECT_COMP_ARRAY, ast_); - ast_ = ast.array; - goto recurse; - } break; - - case AST_SELF: { - scratch.t = Value::OBJECT; - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - scratch.v.h = self; - } break; - - case AST_SUPER_INDEX: { - const auto &ast = *static_cast<const SuperIndex*>(ast_); - stack.newFrame(FRAME_SUPER_INDEX, ast_); - ast_ = ast.index; - goto recurse; - } break; - - case AST_UNARY: { - const auto &ast = *static_cast<const Unary*>(ast_); - stack.newFrame(FRAME_UNARY, ast_); - ast_ = ast.expr; - goto recurse; - } break; - - case AST_VAR: { - const auto &ast = *static_cast<const Var*>(ast_); - auto *thunk = stack.lookUpVar(ast.id); - if (thunk == nullptr) { - std::cerr << "INTERNAL ERROR: Could not bind variable: " - << encode_utf8(ast.id->name) << std::endl; - std::abort(); - } - if (thunk->filled) { - scratch = thunk->content; - } else { - stack.newCall(ast.location, thunk, thunk->self, thunk->offset, thunk->upValues); - ast_ = thunk->body; - goto recurse; - } - } break; - - default: - std::cerr << "INTERNAL ERROR: Unknown AST: " << ast_->type << std::endl; - std::abort(); - } - - // To evaluate another AST, set ast to it, then goto recurse. - // To pop, exit the switch or goto popframe - // To change the frame and re-enter the switch, goto replaceframe - while (stack.size() > initial_stack_size) { - Frame &f = stack.top(); - switch (f.kind) { - case FRAME_APPLY_TARGET: { - const auto &ast = *static_cast<const Apply*>(f.ast); - if (scratch.t != Value::FUNCTION) { - throw makeError(ast.location, - "Only functions can be called, got " - + type_str(scratch)); - } - auto *func = static_cast<HeapClosure*>(scratch.v.h); - - std::set<const Identifier *> params_needed; - for (const auto ¶m : func->params) { - params_needed.insert(param.id); - } - - // Create thunks for arguments. - std::vector<HeapThunk*> positional_args; - BindingFrame args; - bool got_named = false; - for (unsigned i=0 ; i<ast.args.size() ; ++i) { - const auto &arg = ast.args[i]; - - const Identifier *name; - if (arg.id != nullptr) { - got_named = true; - name = arg.id; - } else { - if (got_named) { - std::stringstream ss; - ss << "Internal error: got positional param after named at index " - << i; - throw makeError(ast.location, ss.str()); - } - if (i >= func->params.size()) { - std::stringstream ss; - ss << "Too many args, function has " << func->params.size() - << " parameter(s)"; - throw makeError(ast.location, ss.str()); - } - name = func->params[i].id; - } - // Special case for builtin functions -- leave identifier blank for - // them in the thunk. This removes the thunk frame from the stacktrace. - const Identifier *name_ = func->body == nullptr ? nullptr : name; - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - auto *thunk = makeHeap<HeapThunk>(name_, self, offset, arg.expr); - thunk->upValues = capture(arg.expr->freeVariables); - // While making the thunks, keep them in a frame to avoid premature garbage - // collection. - f.thunks.push_back(thunk); - if (args.find(name) != args.end()) { - std::stringstream ss; - ss << "Binding parameter a second time: " << encode_utf8(name->name); - throw makeError(ast.location, ss.str()); - } - args[name] = thunk; - if (params_needed.find(name) == params_needed.end()) { - std::stringstream ss; - ss << "Function has no parameter " << encode_utf8(name->name); - throw makeError(ast.location, ss.str()); - } - } - - // For any func params for which there was no arg, create a thunk for those and - // bind the default argument. Allow default thunks to see other params. If no - // default argument than raise an error. - - // Raise errors for unbound params, create thunks (but don't fill in upvalues). - // This is a subset of f.thunks, so will not get garbage collected. - std::vector<HeapThunk*> def_arg_thunks; - for (const auto ¶m : func->params) { - if (args.find(param.id) != args.end()) continue; - if (param.def == nullptr) { - std::stringstream ss; - ss << "Function parameter " << encode_utf8(param.id->name) << - " not bound in call."; - throw makeError(ast.location, ss.str()); - } - - // Special case for builtin functions -- leave identifier blank for - // them in the thunk. This removes the thunk frame from the stacktrace. - const Identifier *name_ = func->body == nullptr ? nullptr : param.id; - auto *thunk = makeHeap<HeapThunk>(name_, func->self, func->offset, - param.def); - f.thunks.push_back(thunk); - def_arg_thunks.push_back(thunk); - args[param.id] = thunk; - } - - BindingFrame up_values = func->upValues; - up_values.insert(args.begin(), args.end()); - - // Fill in upvalues - for (HeapThunk *thunk : def_arg_thunks) { - thunk->upValues = up_values; - } - - // Cache these, because pop will invalidate them. - std::vector<HeapThunk*> thunks_copy = f.thunks; - - stack.pop(); - - if (func->body == nullptr) { - // Built-in function. - // Give nullptr for self because noone looking at this frame will - // attempt to bind to self (it's native code). - stack.newFrame(FRAME_BUILTIN_FORCE_THUNKS, f.ast); - stack.top().thunks = thunks_copy; - stack.top().val = scratch; - goto replaceframe; - } else { - // User defined function. - stack.newCall(ast.location, func, func->self, func->offset, up_values); - if (ast.tailstrict) { - stack.top().tailCall = true; - if (thunks_copy.size() == 0) { - // No need to force thunks, proceed straight to body. - ast_ = func->body; - goto recurse; - } else { - // The check for args.size() > 0 - stack.top().thunks = thunks_copy; - stack.top().val = scratch; - goto replaceframe; - } - } else { - ast_ = func->body; - goto recurse; - } - } - } break; - - case FRAME_BINARY_LEFT: { - const auto &ast = *static_cast<const Binary*>(f.ast); - const Value &lhs = scratch; - if (lhs.t == Value::BOOLEAN) { - // Handle short-cut semantics - switch (ast.op) { - case BOP_AND: { - if (!lhs.v.b) { - scratch = makeBoolean(false); - goto popframe; - } - } break; - - case BOP_OR: { - if (lhs.v.b) { - scratch = makeBoolean(true); - goto popframe; - } - } break; - - default:; - } - } - stack.top().kind = FRAME_BINARY_RIGHT; - stack.top().val = lhs; - ast_ = ast.right; - goto recurse; - } break; - - case FRAME_BINARY_RIGHT: { - const auto &ast = *static_cast<const Binary*>(f.ast); - const Value &lhs = stack.top().val; - const Value &rhs = scratch; - - // Handle cases where the LHS and RHS are not the same type. - if (lhs.t == Value::STRING || rhs.t == Value::STRING) { - if (ast.op == BOP_PLUS) { - // Handle co-ercions for string processing. - stack.top().kind = FRAME_STRING_CONCAT; - stack.top().val2 = rhs; - goto replaceframe; - } - } - switch (ast.op) { - // Equality can be used when the types don't match. - case BOP_MANIFEST_EQUAL: - std::cerr << "INTERNAL ERROR: Equals not desugared" << std::endl; - abort(); - - // Equality can be used when the types don't match. - case BOP_MANIFEST_UNEQUAL: - std::cerr << "INTERNAL ERROR: Notequals not desugared" << std::endl; - abort(); - - // e in e - case BOP_IN: { - if (lhs.t != Value::STRING) { - throw makeError(ast.location, - "The left hand side of the 'in' operator should be " - "a string, got " + type_str(lhs)); - } - auto *field = static_cast<HeapString*>(lhs.v.h); - switch (rhs.t) { - case Value::OBJECT: { - auto *obj = static_cast<HeapObject*>(rhs.v.h); - auto *fid = alloc->makeIdentifier(field->value); - unsigned unused_found_at = 0; - bool in = findObject(fid, obj, 0, unused_found_at); - scratch = makeBoolean(in); - } break; - - default: - throw makeError(ast.location, - "The right hand side of the 'in' operator should be" - " an object, got " + type_str(rhs)); - } - goto popframe; - } - - default:; - } - // Everything else requires matching types. - if (lhs.t != rhs.t) { - throw makeError(ast.location, - "Binary operator " + bop_string(ast.op) + " requires " - "matching types, got " + type_str(lhs) + " and " + - type_str(rhs) + "."); - } - switch (lhs.t) { - case Value::ARRAY: - if (ast.op == BOP_PLUS) { - auto *arr_l = static_cast<HeapArray*>(lhs.v.h); - auto *arr_r = static_cast<HeapArray*>(rhs.v.h); - std::vector<HeapThunk*> elements; - for (auto *el : arr_l->elements) - elements.push_back(el); - for (auto *el : arr_r->elements) - elements.push_back(el); - scratch = makeArray(elements); - } else { - throw makeError(ast.location, - "Binary operator " + bop_string(ast.op) - + " does not operate on arrays."); - } - break; - - case Value::BOOLEAN: - switch (ast.op) { - case BOP_AND: - scratch = makeBoolean(lhs.v.b && rhs.v.b); - break; - - case BOP_OR: - scratch = makeBoolean(lhs.v.b || rhs.v.b); - break; - - default: - throw makeError(ast.location, - "Binary operator " + bop_string(ast.op) - + " does not operate on booleans."); - } - break; - - case Value::DOUBLE: - switch (ast.op) { - case BOP_PLUS: - scratch = makeDoubleCheck(ast.location, lhs.v.d + rhs.v.d); - break; - - case BOP_MINUS: - scratch = makeDoubleCheck(ast.location, lhs.v.d - rhs.v.d); - break; - - case BOP_MULT: - scratch = makeDoubleCheck(ast.location, lhs.v.d * rhs.v.d); - break; - - case BOP_DIV: - if (rhs.v.d == 0) - throw makeError(ast.location, "Division by zero."); - scratch = makeDoubleCheck(ast.location, lhs.v.d / rhs.v.d); - break; - - // No need to check doubles made from longs - - case BOP_SHIFT_L: { - long long_l = lhs.v.d; - long long_r = rhs.v.d; - scratch = makeDouble(long_l << long_r); - } break; - - case BOP_SHIFT_R: { - long long_l = lhs.v.d; - long long_r = rhs.v.d; - scratch = makeDouble(long_l >> long_r); - } break; - - case BOP_BITWISE_AND: { - long long_l = lhs.v.d; - long long_r = rhs.v.d; - scratch = makeDouble(long_l & long_r); - } break; - - case BOP_BITWISE_XOR: { - long long_l = lhs.v.d; - long long_r = rhs.v.d; - scratch = makeDouble(long_l ^ long_r); - } break; - - case BOP_BITWISE_OR: { - long long_l = lhs.v.d; - long long_r = rhs.v.d; - scratch = makeDouble(long_l | long_r); - } break; - - case BOP_LESS_EQ: - scratch = makeBoolean(lhs.v.d <= rhs.v.d); - break; - - case BOP_GREATER_EQ: - scratch = makeBoolean(lhs.v.d >= rhs.v.d); - break; - - case BOP_LESS: - scratch = makeBoolean(lhs.v.d < rhs.v.d); - break; - - case BOP_GREATER: - scratch = makeBoolean(lhs.v.d > rhs.v.d); - break; - - default: - throw makeError(ast.location, - "Binary operator " + bop_string(ast.op) - + " does not operate on numbers."); - } - break; - - case Value::FUNCTION: - throw makeError(ast.location, "Binary operator " + bop_string(ast.op) + - " does not operate on functions."); - - case Value::NULL_TYPE: - throw makeError(ast.location, "Binary operator " + bop_string(ast.op) + - " does not operate on null."); - - case Value::OBJECT: { - if (ast.op != BOP_PLUS) { - throw makeError(ast.location, - "Binary operator " + bop_string(ast.op) + - " does not operate on objects."); - } - auto *lhs_obj = static_cast<HeapObject*>(lhs.v.h); - auto *rhs_obj = static_cast<HeapObject*>(rhs.v.h); - scratch = makeObject<HeapExtendedObject>(lhs_obj, rhs_obj); - } - break; - - case Value::STRING: { - const UString &lhs_str = - static_cast<HeapString*>(lhs.v.h)->value; - const UString &rhs_str = - static_cast<HeapString*>(rhs.v.h)->value; - switch (ast.op) { - case BOP_PLUS: - scratch = makeString(lhs_str + rhs_str); - break; - - case BOP_LESS_EQ: - scratch = makeBoolean(lhs_str <= rhs_str); - break; - - case BOP_GREATER_EQ: - scratch = makeBoolean(lhs_str >= rhs_str); - break; - - case BOP_LESS: - scratch = makeBoolean(lhs_str < rhs_str); - break; - - case BOP_GREATER: - scratch = makeBoolean(lhs_str > rhs_str); - break; - - default: - throw makeError(ast.location, - "Binary operator " + bop_string(ast.op) - + " does not operate on strings."); - } - } - break; - } - } break; - - case FRAME_BUILTIN_FILTER: { - const auto &ast = *static_cast<const Apply*>(f.ast); - auto *func = static_cast<HeapClosure*>(f.val.v.h); - auto *arr = static_cast<HeapArray*>(f.val2.v.h); - if (scratch.t != Value::BOOLEAN) { - throw makeError(ast.location, - "filter function must return boolean, got: " - + type_str(scratch)); - } - if (scratch.v.b) f.thunks.push_back(arr->elements[f.elementId]); - f.elementId++; - // Iterate through arr, calling the function on each. - if (f.elementId == arr->elements.size()) { - scratch = makeArray(f.thunks); - } else { - auto *thunk = arr->elements[f.elementId]; - BindingFrame bindings = func->upValues; - bindings[func->params[0].id] = thunk; - stack.newCall(ast.location, func, func->self, func->offset, bindings); - ast_ = func->body; - goto recurse; - } - } break; - - case FRAME_BUILTIN_FORCE_THUNKS: { - const auto &ast = *static_cast<const Apply*>(f.ast); - auto *func = static_cast<HeapClosure*>(f.val.v.h); - if (f.elementId == f.thunks.size()) { - // All thunks forced, now the builtin implementations. - const LocationRange &loc = ast.location; - const std::string &builtin_name = func->builtinName; - std::vector<Value> args; - for (auto *th : f.thunks) { - args.push_back(th->content); - } - BuiltinMap::const_iterator bit = builtins.find(builtin_name); - if (bit != builtins.end()) { - const AST *new_ast = (this->*bit->second)(loc, args); - if (new_ast != nullptr) { - ast_ = new_ast; - goto recurse; - } - break; - } - VmNativeCallbackMap::const_iterator nit = - nativeCallbacks.find(builtin_name); - // TODO(dcunnin): Support arrays. - // TODO(dcunnin): Support objects. - std::vector<JsonnetJsonValue> args2; - for (const Value &arg : args) { - switch (arg.t) { - case Value::STRING: - args2.push_back(JsonnetJsonValue{ - JsonnetJsonValue::STRING, - encode_utf8(static_cast<HeapString*>(arg.v.h)->value), - 0, - std::vector<std::unique_ptr<JsonnetJsonValue>>{}, - std::map<std::string, std::unique_ptr<JsonnetJsonValue>>{}, - }); - break; - - case Value::BOOLEAN: - args2.push_back(JsonnetJsonValue{ - JsonnetJsonValue::BOOL, - "", - arg.v.b ? 1.0 : 0.0, - std::vector<std::unique_ptr<JsonnetJsonValue>>{}, - std::map<std::string, std::unique_ptr<JsonnetJsonValue>>{}, - }); - break; - - case Value::DOUBLE: - args2.push_back(JsonnetJsonValue{ - JsonnetJsonValue::NUMBER, - "", - arg.v.d, - std::vector<std::unique_ptr<JsonnetJsonValue>>{}, - std::map<std::string, std::unique_ptr<JsonnetJsonValue>>{}, - }); - break; - - case Value::NULL_TYPE: - args2.push_back(JsonnetJsonValue{ - JsonnetJsonValue::NULL_KIND, - "", - 0, - std::vector<std::unique_ptr<JsonnetJsonValue>>{}, - std::map<std::string, std::unique_ptr<JsonnetJsonValue>>{}, - }); - break; - - default: - throw makeError(ast.location, - "Native extensions can only take primitives."); - } - - } - std::vector<const JsonnetJsonValue*> args3; - for (size_t i = 0; i < args2.size() ; ++i) { - args3.push_back(&args2[i]); - } - if (nit == nativeCallbacks.end()) { - throw makeError(ast.location, - "Unrecognized builtin name: " + builtin_name); - } - const VmNativeCallback &cb = nit->second; - - int succ; - std::unique_ptr<JsonnetJsonValue> r(cb.cb(cb.ctx, &args3[0], &succ)); - - if (succ) { - bool unused; - jsonToHeap(r, unused, scratch); - } else { - if (r->kind != JsonnetJsonValue::STRING) { - throw makeError( - ast.location, - "Native extension returned an error that was not a string."); - } - std::string rs = r->string; - throw makeError(ast.location, rs); - } - - } else { - // Not all arguments forced yet. - HeapThunk *th = f.thunks[f.elementId++]; - if (!th->filled) { - stack.newCall(ast.location, th, th->self, th->offset, th->upValues); - ast_ = th->body; - goto recurse; - } - } - } break; - - case FRAME_CALL: { - if (auto *thunk = dynamic_cast<HeapThunk*>(f.context)) { - // If we called a thunk, cache result. - thunk->fill(scratch); - } else if (auto *closure = dynamic_cast<HeapClosure*>(f.context)) { - if (f.elementId < f.thunks.size()) { - // If tailstrict, force thunks - HeapThunk *th = f.thunks[f.elementId++]; - if (!th->filled) { - stack.newCall(f.location, th, - th->self, th->offset, th->upValues); - ast_ = th->body; - goto recurse; - } - } else if (f.thunks.size() == 0) { - // Body has now been executed - } else { - // Execute the body - f.thunks.clear(); - f.elementId = 0; - ast_ = closure->body; - goto recurse; - } - } - // Result of call is in scratch, just pop. - } break; - - case FRAME_ERROR: { - const auto &ast = *static_cast<const Error*>(f.ast); - UString msg; - if (scratch.t == Value::STRING) { - msg = static_cast<HeapString*>(scratch.v.h)->value; - } else { - msg = toString(ast.location); - } - throw makeError(ast.location, encode_utf8(msg)); - } break; - - case FRAME_IF: { - const auto &ast = *static_cast<const Conditional*>(f.ast); - if (scratch.t != Value::BOOLEAN) { - throw makeError(ast.location, "Condition must be boolean, got " + - type_str(scratch) + "."); - } - ast_ = scratch.v.b ? ast.branchTrue : ast.branchFalse; - stack.pop(); - goto recurse; - } break; - - case FRAME_SUPER_INDEX: { - const auto &ast = *static_cast<const SuperIndex*>(f.ast); - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - offset++; - if (offset >= countLeaves(self)) { - throw makeError(ast.location, - "Attempt to use super when there is no super class."); - } - if (scratch.t != Value::STRING) { - throw makeError(ast.location, - "Super index must be string, got " - + type_str(scratch) + "."); - } - - const UString &index_name = - static_cast<HeapString*>(scratch.v.h)->value; - auto *fid = alloc->makeIdentifier(index_name); - stack.pop(); - ast_ = objectIndex(ast.location, self, fid, offset); - goto recurse; - } break; - - case FRAME_IN_SUPER_ELEMENT: { - const auto &ast = *static_cast<const InSuper*>(f.ast); - HeapObject *self; - unsigned offset; - stack.getSelfBinding(self, offset); - offset++; - if (scratch.t != Value::STRING) { - throw makeError(ast.location, - "Left hand side of e in super must be string, got " - + type_str(scratch) + "."); - } - if (offset >= countLeaves(self)) { - // There is no super object. - scratch = makeBoolean(false); - } else { - const UString &element_name = - static_cast<HeapString*>(scratch.v.h)->value; - auto *fid = alloc->makeIdentifier(element_name); - unsigned unused_found_at = 0; - bool in = findObject(fid, self, offset, unused_found_at); - scratch = makeBoolean(in); - } - } break; - - case FRAME_INDEX_INDEX: { - const auto &ast = *static_cast<const Index*>(f.ast); - const Value &target = f.val; - if (target.t == Value::ARRAY) { - const auto *array = static_cast<HeapArray*>(target.v.h); - if (scratch.t != Value::DOUBLE) { - throw makeError(ast.location, "Array index must be number, got " - + type_str(scratch) + "."); - } - long i = long(scratch.v.d); - long sz = array->elements.size(); - if (i < 0 || i >= sz) { - std::stringstream ss; - ss << "Array bounds error: " << i - << " not within [0, " << sz << ")"; - throw makeError(ast.location, ss.str()); - } - auto *thunk = array->elements[i]; - if (thunk->filled) { - scratch = thunk->content; - } else { - stack.pop(); - stack.newCall(ast.location, thunk, - thunk->self, thunk->offset, thunk->upValues); - ast_ = thunk->body; - goto recurse; - } - } else if (target.t == Value::OBJECT) { - auto *obj = static_cast<HeapObject*>(target.v.h); - assert(obj != nullptr); - if (scratch.t != Value::STRING) { - throw makeError(ast.location, - "Object index must be string, got " - + type_str(scratch) + "."); - } - const UString &index_name = - static_cast<HeapString*>(scratch.v.h)->value; - auto *fid = alloc->makeIdentifier(index_name); - stack.pop(); - ast_ = objectIndex(ast.location, obj, fid, 0); - goto recurse; - } else if (target.t == Value::STRING) { - auto *obj = static_cast<HeapString*>(target.v.h); - assert(obj != nullptr); - if (scratch.t != Value::DOUBLE) { - throw makeError(ast.location, - "UString index must be a number, got " - + type_str(scratch) + "."); - } - long sz = obj->value.length(); - long i = (long)scratch.v.d; - if (i < 0 || i >= sz) { - std::stringstream ss; - ss << "UString bounds error: " << i - << " not within [0, " << sz << ")"; - throw makeError(ast.location, ss.str()); - } - char32_t ch[] = {obj->value[i], U'\0'}; - scratch = makeString(ch); - } else { - std::cerr << "INTERNAL ERROR: Not object / array / string." << std::endl; - abort(); - } - } break; - - case FRAME_INDEX_TARGET: { - const auto &ast = *static_cast<const Index*>(f.ast); - if (scratch.t != Value::ARRAY - && scratch.t != Value::OBJECT - && scratch.t != Value::STRING) { - throw makeError(ast.location, - "Can only index objects, strings, and arrays, got " - + type_str(scratch) + "."); - } - f.val = scratch; - f.kind = FRAME_INDEX_INDEX; - if (scratch.t == Value::OBJECT) { - auto *self = static_cast<HeapObject*>(scratch.v.h); - if (!stack.alreadyExecutingInvariants(self)) { - stack.newFrame(FRAME_INVARIANTS, ast.location); - Frame &f2 = stack.top(); - f2.self = self; - unsigned counter = 0; - objectInvariants(self, self, counter, f2.thunks); - if (f2.thunks.size() > 0) { - auto *thunk = f2.thunks[0]; - f2.elementId = 1; - stack.newCall(ast.location, thunk, - thunk->self, thunk->offset, thunk->upValues); - ast_ = thunk->body; - goto recurse; - } - } - } - ast_ = ast.index; - goto recurse; - } break; - - case FRAME_INVARIANTS: { - if (f.elementId >= f.thunks.size()) { - if (stack.size() == initial_stack_size + 1) { - // Just pop, evaluate was invoked by runInvariants. - break; - } - stack.pop(); - Frame &f2 = stack.top(); - const auto &ast = *static_cast<const Index*>(f2.ast); - ast_ = ast.index; - goto recurse; - } - auto *thunk = f.thunks[f.elementId++]; - stack.newCall(f.location, thunk, - thunk->self, thunk->offset, thunk->upValues); - ast_ = thunk->body; - goto recurse; - } break; - - case FRAME_LOCAL: { - // Result of execution is in scratch already. - } break; - - case FRAME_OBJECT: { - const auto &ast = *static_cast<const DesugaredObject*>(f.ast); - if (scratch.t != Value::NULL_TYPE) { - if (scratch.t != Value::STRING) { - throw makeError(ast.location, "Field name was not a string."); - } - const auto &fname = static_cast<const HeapString*>(scratch.v.h)->value; - const Identifier *fid = alloc->makeIdentifier(fname); - if (f.objectFields.find(fid) != f.objectFields.end()) { - std::string msg = "Duplicate field name: \"" - + encode_utf8(fname) + "\""; - throw makeError(ast.location, msg); - } - f.objectFields[fid].hide = f.fit->hide; - f.objectFields[fid].body = f.fit->body; - } - f.fit++; - if (f.fit != ast.fields.end()) { - ast_ = f.fit->name; - goto recurse; - } else { - auto env = capture(ast.freeVariables); - scratch = makeObject<HeapSimpleObject>(env, f.objectFields, ast.asserts); - } - } break; - - case FRAME_OBJECT_COMP_ARRAY: { - const auto &ast = *static_cast<const ObjectComprehensionSimple*>(f.ast); - const Value &arr_v = scratch; - if (scratch.t != Value::ARRAY) { - throw makeError(ast.location, - "Object comprehension needs array, got " - + type_str(arr_v)); - } - const auto *arr = static_cast<const HeapArray*>(arr_v.v.h); - if (arr->elements.size() == 0) { - // Degenerate case. Just create the object now. - scratch = makeObject<HeapComprehensionObject>(BindingFrame{}, ast.value, - ast.id, BindingFrame{}); - } else { - f.kind = FRAME_OBJECT_COMP_ELEMENT; - f.val = scratch; - f.bindings[ast.id] = arr->elements[0]; - f.elementId = 0; - ast_ = ast.field; - goto recurse; - } - } break; - - case FRAME_OBJECT_COMP_ELEMENT: { - const auto &ast = *static_cast<const ObjectComprehensionSimple*>(f.ast); - const auto *arr = static_cast<const HeapArray*>(f.val.v.h); - if (scratch.t != Value::STRING) { - std::stringstream ss; - ss << "field must be string, got: " << type_str(scratch); - throw makeError(ast.location, ss.str()); - } - const auto &fname = static_cast<const HeapString*>(scratch.v.h)->value; - const Identifier *fid = alloc->makeIdentifier(fname); - if (f.elements.find(fid) != f.elements.end()) { - throw makeError(ast.location, - "Duplicate field name: \"" + encode_utf8(fname) + "\""); - } - f.elements[fid] = arr->elements[f.elementId]; - f.elementId++; - - if (f.elementId == arr->elements.size()) { - auto env = capture(ast.freeVariables); - scratch = makeObject<HeapComprehensionObject>(env, ast.value, - ast.id, f.elements); - } else { - f.bindings[ast.id] = arr->elements[f.elementId]; - ast_ = ast.field; - goto recurse; - } - } break; - - case FRAME_STRING_CONCAT: { - const auto &ast = *static_cast<const Binary*>(f.ast); - const Value &lhs = stack.top().val; - const Value &rhs = stack.top().val2; - UString output; - if (lhs.t == Value::STRING) { - output.append(static_cast<const HeapString*>(lhs.v.h)->value); - } else { - scratch = lhs; - output.append(toString(ast.left->location)); - } - if (rhs.t == Value::STRING) { - output.append(static_cast<const HeapString*>(rhs.v.h)->value); - } else { - scratch = rhs; - output.append(toString(ast.right->location)); - } - scratch = makeString(output); - } break; - - case FRAME_UNARY: { - const auto &ast = *static_cast<const Unary*>(f.ast); - switch (scratch.t) { - - case Value::BOOLEAN: - if (ast.op == UOP_NOT) { - scratch = makeBoolean(!scratch.v.b); - } else { - throw makeError(ast.location, - "Unary operator " + uop_string(ast.op) - + " does not operate on booleans."); - } - break; - - case Value::DOUBLE: - switch (ast.op) { - case UOP_PLUS: - break; - - case UOP_MINUS: - scratch = makeDouble(-scratch.v.d); - break; - - case UOP_BITWISE_NOT: - scratch = makeDouble(~(long)(scratch.v.d)); - break; - - default: - throw makeError(ast.location, - "Unary operator " + uop_string(ast.op) - + " does not operate on numbers."); - } - break; - - default: - throw makeError(ast.location, - "Unary operator " + uop_string(ast.op) + - " does not operate on type " + type_str(scratch)); - } - } break; - - default: - std::cerr << "INTERNAL ERROR: Unknown FrameKind: " << f.kind << std::endl; - std::abort(); - } - - popframe:; - - stack.pop(); - - replaceframe:; - } - } - - /** Manifest the scratch value by evaluating any remaining fields, and then convert to JSON. - * - * This can trigger a garbage collection cycle. Be sure to stash any objects that aren't - * reachable via the stack or heap. - * - * \param multiline If true, will print objects and arrays in an indented fashion. - */ - UString manifestJson(const LocationRange &loc, bool multiline, const UString &indent) - { - // Printing fields means evaluating and binding them, which can trigger - // garbage collection. - - UStringStream ss; - switch (scratch.t) { - case Value::ARRAY: { - HeapArray *arr = static_cast<HeapArray*>(scratch.v.h); - if (arr->elements.size() == 0) { - ss << U"[ ]"; - } else { - const char32_t *prefix = multiline ? U"[\n" : U"["; - UString indent2 = multiline ? indent + U" " : indent; - for (auto *thunk : arr->elements) { - LocationRange tloc = thunk->body == nullptr - ? loc - : thunk->body->location; - if (thunk->filled) { - stack.newCall(loc, thunk, nullptr, 0, BindingFrame{}); - // Keep arr alive when scratch is overwritten - stack.top().val = scratch; - scratch = thunk->content; - } else { - stack.newCall(loc, thunk, thunk->self, thunk->offset, thunk->upValues); - // Keep arr alive when scratch is overwritten - stack.top().val = scratch; - evaluate(thunk->body, stack.size()); - } - auto element = manifestJson(tloc, multiline, indent2); - // Restore scratch - scratch = stack.top().val; - stack.pop(); - ss << prefix << indent2 << element; - prefix = multiline ? U",\n" : U", "; - } - ss << (multiline ? U"\n" : U"") << indent << U"]"; - } - } - break; - - case Value::BOOLEAN: - ss << (scratch.v.b ? U"true" : U"false"); - break; - - case Value::DOUBLE: - ss << decode_utf8(jsonnet_unparse_number(scratch.v.d)); - break; - - case Value::FUNCTION: - throw makeError(loc, "Couldn't manifest function in JSON output."); - - case Value::NULL_TYPE: - ss << U"null"; - break; - - case Value::OBJECT: { - auto *obj = static_cast<HeapObject*>(scratch.v.h); - runInvariants(loc, obj); - // Using std::map has the useful side-effect of ordering the fields - // alphabetically. - std::map<UString, const Identifier*> fields; - for (const auto &f : objectFields(obj, true)) { - fields[f->name] = f; - } - if (fields.size() == 0) { - ss << U"{ }"; - } else { - UString indent2 = multiline ? indent + U" " : indent; - const char32_t *prefix = multiline ? U"{\n" : U"{"; - for (const auto &f : fields) { - // pushes FRAME_CALL - const AST *body = objectIndex(loc, obj, f.second, 0); - stack.top().val = scratch; - evaluate(body, stack.size()); - auto vstr = manifestJson(body->location, multiline, indent2); - // Reset scratch so that the object we're manifesting doesn't - // get GC'd. - scratch = stack.top().val; - stack.pop(); - ss << prefix << indent2 << jsonnet_string_unparse(f.first, false) - << U": " << vstr; - prefix = multiline ? U",\n" : U", "; - } - ss << (multiline ? U"\n" : U"") << indent << U"}"; - } - } - break; - - case Value::STRING: { - const UString &str = static_cast<HeapString*>(scratch.v.h)->value; - ss << jsonnet_string_unparse(str, false); - } - break; - } - return ss.str(); - } - - UString manifestString(const LocationRange &loc) - { - if (scratch.t != Value::STRING) { - std::stringstream ss; - ss << "Expected string result, got: " << type_str(scratch.t); - throw makeError(loc, ss.str()); - } - return static_cast<HeapString*>(scratch.v.h)->value; - } - - StrMap manifestMulti(bool string) - { - StrMap r; - LocationRange loc("During manifestation"); - if (scratch.t != Value::OBJECT) { - std::stringstream ss; - ss << "Multi mode: Top-level object was a " << type_str(scratch.t) << ", " - << "should be an object whose keys are filenames and values hold " - << "the JSON for that file."; - throw makeError(loc, ss.str()); - } - auto *obj = static_cast<HeapObject*>(scratch.v.h); - runInvariants(loc, obj); - std::map<UString, const Identifier*> fields; - for (const auto &f : objectFields(obj, true)) { - fields[f->name] = f; - } - for (const auto &f : fields) { - // pushes FRAME_CALL - const AST *body = objectIndex(loc, obj, f.second, 0); - stack.top().val = scratch; - evaluate(body, stack.size()); - auto vstr = string ? manifestString(body->location) - : manifestJson(body->location, true, U""); - // Reset scratch so that the object we're manifesting doesn't - // get GC'd. - scratch = stack.top().val; - stack.pop(); - r[encode_utf8(f.first)] = encode_utf8(vstr); - } - return r; - } - - std::vector<std::string> manifestStream(void) - { - std::vector<std::string> r; - LocationRange loc("During manifestation"); - if (scratch.t != Value::ARRAY) { - std::stringstream ss; - ss << "Stream mode: Top-level object was a " << type_str(scratch.t) << ", " - << "should be an array whose elements hold " - << "the JSON for each document in the stream."; - throw makeError(loc, ss.str()); - } - auto *arr = static_cast<HeapArray*>(scratch.v.h); - for (auto *thunk : arr->elements) { - LocationRange tloc = thunk->body == nullptr - ? loc - : thunk->body->location; - if (thunk->filled) { - stack.newCall(loc, thunk, nullptr, 0, BindingFrame{}); - // Keep arr alive when scratch is overwritten - stack.top().val = scratch; - scratch = thunk->content; - } else { - stack.newCall(loc, thunk, thunk->self, thunk->offset, thunk->upValues); - // Keep arr alive when scratch is overwritten - stack.top().val = scratch; - evaluate(thunk->body, stack.size()); - } - UString element = manifestJson(tloc, true, U""); - scratch = stack.top().val; - stack.pop(); - r.push_back(encode_utf8(element)); - } - return r; - } - -}; - -} // namespace - -std::string jsonnet_vm_execute( - Allocator *alloc, - const AST *ast, - const ExtMap &ext_vars, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &natives, - JsonnetImportCallback *import_callback, - void *ctx, - bool string_output) -{ - Interpreter vm(alloc, ext_vars, max_stack, gc_min_objects, gc_growth_trigger, - natives, import_callback, ctx); - vm.evaluate(ast, 0); - if (string_output) { - return encode_utf8(vm.manifestString(LocationRange("During manifestation"))); - } else { - return encode_utf8(vm.manifestJson(LocationRange("During manifestation"), true, U"")); - } -} - -StrMap jsonnet_vm_execute_multi( - Allocator *alloc, - const AST *ast, - const ExtMap &ext_vars, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &natives, - JsonnetImportCallback *import_callback, - void *ctx, - bool string_output) -{ - Interpreter vm(alloc, ext_vars, max_stack, gc_min_objects, gc_growth_trigger, - natives, import_callback, ctx); - vm.evaluate(ast, 0); - return vm.manifestMulti(string_output); -} - -std::vector<std::string> jsonnet_vm_execute_stream( - Allocator *alloc, - const AST *ast, - const ExtMap &ext_vars, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &natives, - JsonnetImportCallback *import_callback, - void *ctx) -{ - Interpreter vm(alloc, ext_vars, max_stack, gc_min_objects, gc_growth_trigger, - natives, import_callback, ctx); - vm.evaluate(ast, 0); - return vm.manifestStream(); -} - - diff --git a/vendor/github.com/strickyak/jsonnet_cgo/vm.h b/vendor/github.com/strickyak/jsonnet_cgo/vm.h deleted file mode 100644 index 2f6f7bd7587aa1e128deffea68fe1eebc7c0faaf..0000000000000000000000000000000000000000 --- a/vendor/github.com/strickyak/jsonnet_cgo/vm.h +++ /dev/null @@ -1,148 +0,0 @@ -/* -Copyright 2015 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#ifndef JSONNET_VM_H -#define JSONNET_VM_H - -#include <libjsonnet.h> - -#include "ast.h" - -/** A single line of a stack trace from a runtime error. - */ -struct TraceFrame { - LocationRange location; - std::string name; - TraceFrame(const LocationRange &location, const std::string &name="") - : location(location), name(name) - { } -}; - -/** Exception that is thrown by the interpreter when it reaches an error construct, or divide by - * zero, array bounds error, dynamic type error, etc. - */ -struct RuntimeError { - std::vector<TraceFrame> stackTrace; - std::string msg; - RuntimeError(const std::vector<TraceFrame> stack_trace, const std::string &msg) - : stackTrace(stack_trace), msg(msg) - { } -}; - -/** Holds native callback and context. */ -struct VmNativeCallback { - JsonnetNativeCallback *cb; - void *ctx; - std::vector<std::string> params; -}; - -typedef std::map<std::string, VmNativeCallback> VmNativeCallbackMap; - -/** Stores external values / code. */ -struct VmExt { - std::string data; - bool isCode; - VmExt() : isCode(false) { } - VmExt(const std::string &data, bool is_code) - : data(data), isCode(is_code) - { } -}; - - -/** Execute the program and return the value as a JSON string. - * - * \param alloc The allocator used to create the ast. - * \param ast The program to execute. - * \param ext The external vars / code. - * \param max_stack Recursion beyond this level gives an error. - * \param gc_min_objects The garbage collector does not run when the heap is this small. - * \param gc_growth_trigger Growth since last garbage collection cycle to trigger a new cycle. - * \param import_callback A callback to handle imports - * \param import_callback_ctx Context param for the import callback. - * \param output_string Whether to expect a string and output it without JSON encoding - * \throws RuntimeError reports runtime errors in the program. - * \returns The JSON result in string form. - */ -std::string jsonnet_vm_execute( - Allocator *alloc, const AST *ast, - const std::map<std::string, VmExt> &ext, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &natives, - JsonnetImportCallback *import_callback, - void *import_callback_ctx, - bool string_output); - -/** Execute the program and return the value as a number of named JSON files. - * - * This assumes the given program yields an object whose keys are filenames. - * - * \param alloc The allocator used to create the ast. - * \param ast The program to execute. - * \param ext The external vars / code. - * \param tla The top-level arguments (strings or code). - * \param max_stack Recursion beyond this level gives an error. - * \param gc_min_objects The garbage collector does not run when the heap is this small. - * \param gc_growth_trigger Growth since last garbage collection cycle to trigger a new cycle. - * \param import_callback A callback to handle imports - * \param import_callback_ctx Context param for the import callback. - * \param output_string Whether to expect a string and output it without JSON encoding - * \throws RuntimeError reports runtime errors in the program. - * \returns A mapping from filename to the JSON strings for that file. - */ -std::map<std::string, std::string> jsonnet_vm_execute_multi( - Allocator *alloc, - const AST *ast, - const std::map<std::string, VmExt> &ext, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &natives, - JsonnetImportCallback *import_callback, - void *import_callback_ctx, - bool string_output); - -/** Execute the program and return the value as a stream of JSON files. - * - * This assumes the given program yields an array whose elements are individual - * JSON files. - * - * \param alloc The allocator used to create the ast. - * \param ast The program to execute. - * \param ext The external vars / code. - * \param tla The top-level arguments (strings or code). - * \param max_stack Recursion beyond this level gives an error. - * \param gc_min_objects The garbage collector does not run when the heap is this small. - * \param gc_growth_trigger Growth since last garbage collection cycle to trigger a new cycle. - * \param import_callback A callback to handle imports - * \param import_callback_ctx Context param for the import callback. - * \param output_string Whether to expect a string and output it without JSON encoding - * \throws RuntimeError reports runtime errors in the program. - * \returns A mapping from filename to the JSON strings for that file. - */ -std::vector<std::string> jsonnet_vm_execute_stream( - Allocator *alloc, - const AST *ast, - const std::map<std::string, VmExt> &ext, - unsigned max_stack, - double gc_min_objects, - double gc_growth_trigger, - const VmNativeCallbackMap &natives, - JsonnetImportCallback *import_callback, - void *import_callback_ctx); - -#endif diff --git a/vendor/google.golang.org/appengine/CONTRIBUTING.md b/vendor/google.golang.org/appengine/CONTRIBUTING.md deleted file mode 100644 index ffc298520856c81429f7731cacdf0cf08314cad8..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/CONTRIBUTING.md +++ /dev/null @@ -1,90 +0,0 @@ -# Contributing - -1. Sign one of the contributor license agreements below. -1. Get the package: - - `go get -d google.golang.org/appengine` -1. Change into the checked out source: - - `cd $GOPATH/src/google.golang.org/appengine` -1. Fork the repo. -1. Set your fork as a remote: - - `git remote add fork git@github.com:GITHUB_USERNAME/appengine.git` -1. Make changes, commit to your fork. -1. Send a pull request with your changes. - The first line of your commit message is conventionally a one-line summary of the change, prefixed by the primary affected package, and is used as the title of your pull request. - -# Testing - -## Running system tests - -Download and install the [Go App Engine SDK](https://cloud.google.com/appengine/docs/go/download). Make sure the `go_appengine` dir is in your `PATH`. - -Set the `APPENGINE_DEV_APPSERVER` environment variable to `/path/to/go_appengine/dev_appserver.py`. - -Run tests with `goapp test`: - -``` -goapp test -v google.golang.org/appengine/... -``` - -## Contributor License Agreements - -Before we can accept your pull requests you'll need to sign a Contributor -License Agreement (CLA): - -- **If you are an individual writing original source code** and **you own the -intellectual property**, then you'll need to sign an [individual CLA][indvcla]. -- **If you work for a company that wants to allow you to contribute your work**, -then you'll need to sign a [corporate CLA][corpcla]. - -You can sign these electronically (just scroll to the bottom). After that, -we'll be able to accept your pull requests. - -## Contributor Code of Conduct - -As contributors and maintainers of this project, -and in the interest of fostering an open and welcoming community, -we pledge to respect all people who contribute through reporting issues, -posting feature requests, updating documentation, -submitting pull requests or patches, and other activities. - -We are committed to making participation in this project -a harassment-free experience for everyone, -regardless of level of experience, gender, gender identity and expression, -sexual orientation, disability, personal appearance, -body size, race, ethnicity, age, religion, or nationality. - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery -* Personal attacks -* Trolling or insulting/derogatory comments -* Public or private harassment -* Publishing other's private information, -such as physical or electronic -addresses, without explicit permission -* Other unethical or unprofessional conduct. - -Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct. -By adopting this Code of Conduct, -project maintainers commit themselves to fairly and consistently -applying these principles to every aspect of managing this project. -Project maintainers who do not follow or enforce the Code of Conduct -may be permanently removed from the project team. - -This code of conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior -may be reported by opening an issue -or contacting one or more of the project maintainers. - -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, -available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) - -[indvcla]: https://developers.google.com/open-source/cla/individual -[corpcla]: https://developers.google.com/open-source/cla/corporate diff --git a/vendor/google.golang.org/appengine/LICENSE b/vendor/google.golang.org/appengine/LICENSE deleted file mode 100644 index d645695673349e3947e8e5ae42332d0ac3164cd7..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/google.golang.org/appengine/README.md b/vendor/google.golang.org/appengine/README.md deleted file mode 100644 index d86768a2c665b7a299f5e74c7f1bd69f79d308ae..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# Go App Engine packages - -[](https://travis-ci.org/golang/appengine) - -This repository supports the Go runtime on *App Engine standard*. -It provides APIs for interacting with App Engine services. -Its canonical import path is `google.golang.org/appengine`. - -See https://cloud.google.com/appengine/docs/go/ -for more information. - -File issue reports and feature requests on the [GitHub's issue -tracker](https://github.com/golang/appengine/issues). - -## Upgrading an App Engine app to the flexible environment - -This package does not work on *App Engine flexible*. - -There are many differences between the App Engine standard environment and -the flexible environment. - -See the [documentation on upgrading to the flexible environment](https://cloud.google.com/appengine/docs/flexible/go/upgrading). - -## Directory structure - -The top level directory of this repository is the `appengine` package. It -contains the -basic APIs (e.g. `appengine.NewContext`) that apply across APIs. Specific API -packages are in subdirectories (e.g. `datastore`). - -There is an `internal` subdirectory that contains service protocol buffers, -plus packages required for connectivity to make API calls. App Engine apps -should not directly import any package under `internal`. - -## Updating from legacy (`import "appengine"`) packages - -If you're currently using the bare `appengine` packages -(that is, not these ones, imported via `google.golang.org/appengine`), -then you can use the `aefix` tool to help automate an upgrade to these packages. - -Run `go get google.golang.org/appengine/cmd/aefix` to install it. - -### 1. Update import paths - -The import paths for App Engine packages are now fully qualified, based at `google.golang.org/appengine`. -You will need to update your code to use import paths starting with that; for instance, -code importing `appengine/datastore` will now need to import `google.golang.org/appengine/datastore`. - -### 2. Update code using deprecated, removed or modified APIs - -Most App Engine services are available with exactly the same API. -A few APIs were cleaned up, and there are some differences: - -* `appengine.Context` has been replaced with the `Context` type from `golang.org/x/net/context`. -* Logging methods that were on `appengine.Context` are now functions in `google.golang.org/appengine/log`. -* `appengine.Timeout` has been removed. Use `context.WithTimeout` instead. -* `appengine.Datacenter` now takes a `context.Context` argument. -* `datastore.PropertyLoadSaver` has been simplified to use slices in place of channels. -* `delay.Call` now returns an error. -* `search.FieldLoadSaver` now handles document metadata. -* `urlfetch.Transport` no longer has a Deadline field; set a deadline on the - `context.Context` instead. -* `aetest` no longer declares its own Context type, and uses the standard one instead. -* `taskqueue.QueueStats` no longer takes a maxTasks argument. That argument has been - deprecated and unused for a long time. -* `appengine.BackendHostname` and `appengine.BackendInstance` were for the deprecated backends feature. - Use `appengine.ModuleHostname`and `appengine.ModuleName` instead. -* Most of `appengine/file` and parts of `appengine/blobstore` are deprecated. - Use [Google Cloud Storage](https://godoc.org/cloud.google.com/go/storage) if the - feature you require is not present in the new - [blobstore package](https://google.golang.org/appengine/blobstore). -* `appengine/socket` is not required on App Engine flexible environment / Managed VMs. - Use the standard `net` package instead. diff --git a/vendor/google.golang.org/appengine/appengine.go b/vendor/google.golang.org/appengine/appengine.go deleted file mode 100644 index d4f808442b7a735816ab36a987a705352d70eac5..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/appengine.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// Package appengine provides basic functionality for Google App Engine. -// -// For more information on how to write Go apps for Google App Engine, see: -// https://cloud.google.com/appengine/docs/go/ -package appengine // import "google.golang.org/appengine" - -import ( - "net/http" - - "github.com/golang/protobuf/proto" - "golang.org/x/net/context" - - "google.golang.org/appengine/internal" -) - -// The gophers party all night; the rabbits provide the beats. - -// Main is the principal entry point for an app running in App Engine. -// -// On App Engine Flexible it installs a trivial health checker if one isn't -// already registered, and starts listening on port 8080 (overridden by the -// $PORT environment variable). -// -// See https://cloud.google.com/appengine/docs/flexible/custom-runtimes#health_check_requests -// for details on how to do your own health checking. -// -// On App Engine Standard it ensures the server has started and is prepared to -// receive requests. -// -// Main never returns. -// -// Main is designed so that the app's main package looks like this: -// -// package main -// -// import ( -// "google.golang.org/appengine" -// -// _ "myapp/package0" -// _ "myapp/package1" -// ) -// -// func main() { -// appengine.Main() -// } -// -// The "myapp/packageX" packages are expected to register HTTP handlers -// in their init functions. -func Main() { - internal.Main() -} - -// IsDevAppServer reports whether the App Engine app is running in the -// development App Server. -func IsDevAppServer() bool { - return internal.IsDevAppServer() -} - -// NewContext returns a context for an in-flight HTTP request. -// This function is cheap. -func NewContext(req *http.Request) context.Context { - return WithContext(context.Background(), req) -} - -// WithContext returns a copy of the parent context -// and associates it with an in-flight HTTP request. -// This function is cheap. -func WithContext(parent context.Context, req *http.Request) context.Context { - return internal.WithContext(parent, req) -} - -// TODO(dsymonds): Add a Call function here? Otherwise other packages can't access internal.Call. - -// BlobKey is a key for a blobstore blob. -// -// Conceptually, this type belongs in the blobstore package, but it lives in -// the appengine package to avoid a circular dependency: blobstore depends on -// datastore, and datastore needs to refer to the BlobKey type. -type BlobKey string - -// GeoPoint represents a location as latitude/longitude in degrees. -type GeoPoint struct { - Lat, Lng float64 -} - -// Valid returns whether a GeoPoint is within [-90, 90] latitude and [-180, 180] longitude. -func (g GeoPoint) Valid() bool { - return -90 <= g.Lat && g.Lat <= 90 && -180 <= g.Lng && g.Lng <= 180 -} - -// APICallFunc defines a function type for handling an API call. -// See WithCallOverride. -type APICallFunc func(ctx context.Context, service, method string, in, out proto.Message) error - -// WithAPICallFunc returns a copy of the parent context -// that will cause API calls to invoke f instead of their normal operation. -// -// This is intended for advanced users only. -func WithAPICallFunc(ctx context.Context, f APICallFunc) context.Context { - return internal.WithCallOverride(ctx, internal.CallOverrideFunc(f)) -} - -// APICall performs an API call. -// -// This is not intended for general use; it is exported for use in conjunction -// with WithAPICallFunc. -func APICall(ctx context.Context, service, method string, in, out proto.Message) error { - return internal.Call(ctx, service, method, in, out) -} diff --git a/vendor/google.golang.org/appengine/appengine_vm.go b/vendor/google.golang.org/appengine/appengine_vm.go deleted file mode 100644 index f4b645aad3bec2253adcceb962d661ad87b4e298..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/appengine_vm.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// +build !appengine - -package appengine - -import ( - "golang.org/x/net/context" - - "google.golang.org/appengine/internal" -) - -// BackgroundContext returns a context not associated with a request. -// This should only be used when not servicing a request. -// This only works in App Engine "flexible environment". -func BackgroundContext() context.Context { - return internal.BackgroundContext() -} diff --git a/vendor/google.golang.org/appengine/errors.go b/vendor/google.golang.org/appengine/errors.go deleted file mode 100644 index 16d0772e2a46b834472dd984aa515a6a05699b90..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/errors.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// This file provides error functions for common API failure modes. - -package appengine - -import ( - "fmt" - - "google.golang.org/appengine/internal" -) - -// IsOverQuota reports whether err represents an API call failure -// due to insufficient available quota. -func IsOverQuota(err error) bool { - callErr, ok := err.(*internal.CallError) - return ok && callErr.Code == 4 -} - -// MultiError is returned by batch operations when there are errors with -// particular elements. Errors will be in a one-to-one correspondence with -// the input elements; successful elements will have a nil entry. -type MultiError []error - -func (m MultiError) Error() string { - s, n := "", 0 - for _, e := range m { - if e != nil { - if n == 0 { - s = e.Error() - } - n++ - } - } - switch n { - case 0: - return "(0 errors)" - case 1: - return s - case 2: - return s + " (and 1 other error)" - } - return fmt.Sprintf("%s (and %d other errors)", s, n-1) -} diff --git a/vendor/google.golang.org/appengine/identity.go b/vendor/google.golang.org/appengine/identity.go deleted file mode 100644 index b8dcf8f361989d2e89aee584ab8b79088c918fe4..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/identity.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package appengine - -import ( - "time" - - "golang.org/x/net/context" - - "google.golang.org/appengine/internal" - pb "google.golang.org/appengine/internal/app_identity" - modpb "google.golang.org/appengine/internal/modules" -) - -// AppID returns the application ID for the current application. -// The string will be a plain application ID (e.g. "appid"), with a -// domain prefix for custom domain deployments (e.g. "example.com:appid"). -func AppID(c context.Context) string { return internal.AppID(c) } - -// DefaultVersionHostname returns the standard hostname of the default version -// of the current application (e.g. "my-app.appspot.com"). This is suitable for -// use in constructing URLs. -func DefaultVersionHostname(c context.Context) string { - return internal.DefaultVersionHostname(c) -} - -// ModuleName returns the module name of the current instance. -func ModuleName(c context.Context) string { - return internal.ModuleName(c) -} - -// ModuleHostname returns a hostname of a module instance. -// If module is the empty string, it refers to the module of the current instance. -// If version is empty, it refers to the version of the current instance if valid, -// or the default version of the module of the current instance. -// If instance is empty, ModuleHostname returns the load-balancing hostname. -func ModuleHostname(c context.Context, module, version, instance string) (string, error) { - req := &modpb.GetHostnameRequest{} - if module != "" { - req.Module = &module - } - if version != "" { - req.Version = &version - } - if instance != "" { - req.Instance = &instance - } - res := &modpb.GetHostnameResponse{} - if err := internal.Call(c, "modules", "GetHostname", req, res); err != nil { - return "", err - } - return *res.Hostname, nil -} - -// VersionID returns the version ID for the current application. -// It will be of the form "X.Y", where X is specified in app.yaml, -// and Y is a number generated when each version of the app is uploaded. -// It does not include a module name. -func VersionID(c context.Context) string { return internal.VersionID(c) } - -// InstanceID returns a mostly-unique identifier for this instance. -func InstanceID() string { return internal.InstanceID() } - -// Datacenter returns an identifier for the datacenter that the instance is running in. -func Datacenter(c context.Context) string { return internal.Datacenter(c) } - -// ServerSoftware returns the App Engine release version. -// In production, it looks like "Google App Engine/X.Y.Z". -// In the development appserver, it looks like "Development/X.Y". -func ServerSoftware() string { return internal.ServerSoftware() } - -// RequestID returns a string that uniquely identifies the request. -func RequestID(c context.Context) string { return internal.RequestID(c) } - -// AccessToken generates an OAuth2 access token for the specified scopes on -// behalf of service account of this application. This token will expire after -// the returned time. -func AccessToken(c context.Context, scopes ...string) (token string, expiry time.Time, err error) { - req := &pb.GetAccessTokenRequest{Scope: scopes} - res := &pb.GetAccessTokenResponse{} - - err = internal.Call(c, "app_identity_service", "GetAccessToken", req, res) - if err != nil { - return "", time.Time{}, err - } - return res.GetAccessToken(), time.Unix(res.GetExpirationTime(), 0), nil -} - -// Certificate represents a public certificate for the app. -type Certificate struct { - KeyName string - Data []byte // PEM-encoded X.509 certificate -} - -// PublicCertificates retrieves the public certificates for the app. -// They can be used to verify a signature returned by SignBytes. -func PublicCertificates(c context.Context) ([]Certificate, error) { - req := &pb.GetPublicCertificateForAppRequest{} - res := &pb.GetPublicCertificateForAppResponse{} - if err := internal.Call(c, "app_identity_service", "GetPublicCertificatesForApp", req, res); err != nil { - return nil, err - } - var cs []Certificate - for _, pc := range res.PublicCertificateList { - cs = append(cs, Certificate{ - KeyName: pc.GetKeyName(), - Data: []byte(pc.GetX509CertificatePem()), - }) - } - return cs, nil -} - -// ServiceAccount returns a string representing the service account name, in -// the form of an email address (typically app_id@appspot.gserviceaccount.com). -func ServiceAccount(c context.Context) (string, error) { - req := &pb.GetServiceAccountNameRequest{} - res := &pb.GetServiceAccountNameResponse{} - - err := internal.Call(c, "app_identity_service", "GetServiceAccountName", req, res) - if err != nil { - return "", err - } - return res.GetServiceAccountName(), err -} - -// SignBytes signs bytes using a private key unique to your application. -func SignBytes(c context.Context, bytes []byte) (keyName string, signature []byte, err error) { - req := &pb.SignForAppRequest{BytesToSign: bytes} - res := &pb.SignForAppResponse{} - - if err := internal.Call(c, "app_identity_service", "SignForApp", req, res); err != nil { - return "", nil, err - } - return res.GetKeyName(), res.GetSignatureBytes(), nil -} - -func init() { - internal.RegisterErrorCodeMap("app_identity_service", pb.AppIdentityServiceError_ErrorCode_name) - internal.RegisterErrorCodeMap("modules", modpb.ModulesServiceError_ErrorCode_name) -} diff --git a/vendor/google.golang.org/appengine/internal/api.go b/vendor/google.golang.org/appengine/internal/api.go deleted file mode 100644 index efee06090fc0d0e6776ba97c4541618626ae2601..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/api.go +++ /dev/null @@ -1,677 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// +build !appengine - -package internal - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "log" - "net" - "net/http" - "net/url" - "os" - "runtime" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" - - "github.com/golang/protobuf/proto" - netcontext "golang.org/x/net/context" - - basepb "google.golang.org/appengine/internal/base" - logpb "google.golang.org/appengine/internal/log" - remotepb "google.golang.org/appengine/internal/remote_api" -) - -const ( - apiPath = "/rpc_http" - defaultTicketSuffix = "/default.20150612t184001.0" -) - -var ( - // Incoming headers. - ticketHeader = http.CanonicalHeaderKey("X-AppEngine-API-Ticket") - dapperHeader = http.CanonicalHeaderKey("X-Google-DapperTraceInfo") - traceHeader = http.CanonicalHeaderKey("X-Cloud-Trace-Context") - curNamespaceHeader = http.CanonicalHeaderKey("X-AppEngine-Current-Namespace") - userIPHeader = http.CanonicalHeaderKey("X-AppEngine-User-IP") - remoteAddrHeader = http.CanonicalHeaderKey("X-AppEngine-Remote-Addr") - - // Outgoing headers. - apiEndpointHeader = http.CanonicalHeaderKey("X-Google-RPC-Service-Endpoint") - apiEndpointHeaderValue = []string{"app-engine-apis"} - apiMethodHeader = http.CanonicalHeaderKey("X-Google-RPC-Service-Method") - apiMethodHeaderValue = []string{"/VMRemoteAPI.CallRemoteAPI"} - apiDeadlineHeader = http.CanonicalHeaderKey("X-Google-RPC-Service-Deadline") - apiContentType = http.CanonicalHeaderKey("Content-Type") - apiContentTypeValue = []string{"application/octet-stream"} - logFlushHeader = http.CanonicalHeaderKey("X-AppEngine-Log-Flush-Count") - - apiHTTPClient = &http.Client{ - Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: limitDial, - }, - } - - defaultTicketOnce sync.Once - defaultTicket string -) - -func apiURL() *url.URL { - host, port := "appengine.googleapis.internal", "10001" - if h := os.Getenv("API_HOST"); h != "" { - host = h - } - if p := os.Getenv("API_PORT"); p != "" { - port = p - } - return &url.URL{ - Scheme: "http", - Host: host + ":" + port, - Path: apiPath, - } -} - -func handleHTTP(w http.ResponseWriter, r *http.Request) { - c := &context{ - req: r, - outHeader: w.Header(), - apiURL: apiURL(), - } - stopFlushing := make(chan int) - - ctxs.Lock() - ctxs.m[r] = c - ctxs.Unlock() - defer func() { - ctxs.Lock() - delete(ctxs.m, r) - ctxs.Unlock() - }() - - // Patch up RemoteAddr so it looks reasonable. - if addr := r.Header.Get(userIPHeader); addr != "" { - r.RemoteAddr = addr - } else if addr = r.Header.Get(remoteAddrHeader); addr != "" { - r.RemoteAddr = addr - } else { - // Should not normally reach here, but pick a sensible default anyway. - r.RemoteAddr = "127.0.0.1" - } - // The address in the headers will most likely be of these forms: - // 123.123.123.123 - // 2001:db8::1 - // net/http.Request.RemoteAddr is specified to be in "IP:port" form. - if _, _, err := net.SplitHostPort(r.RemoteAddr); err != nil { - // Assume the remote address is only a host; add a default port. - r.RemoteAddr = net.JoinHostPort(r.RemoteAddr, "80") - } - - // Start goroutine responsible for flushing app logs. - // This is done after adding c to ctx.m (and stopped before removing it) - // because flushing logs requires making an API call. - go c.logFlusher(stopFlushing) - - executeRequestSafely(c, r) - c.outHeader = nil // make sure header changes aren't respected any more - - stopFlushing <- 1 // any logging beyond this point will be dropped - - // Flush any pending logs asynchronously. - c.pendingLogs.Lock() - flushes := c.pendingLogs.flushes - if len(c.pendingLogs.lines) > 0 { - flushes++ - } - c.pendingLogs.Unlock() - go c.flushLog(false) - w.Header().Set(logFlushHeader, strconv.Itoa(flushes)) - - // Avoid nil Write call if c.Write is never called. - if c.outCode != 0 { - w.WriteHeader(c.outCode) - } - if c.outBody != nil { - w.Write(c.outBody) - } -} - -func executeRequestSafely(c *context, r *http.Request) { - defer func() { - if x := recover(); x != nil { - logf(c, 4, "%s", renderPanic(x)) // 4 == critical - c.outCode = 500 - } - }() - - http.DefaultServeMux.ServeHTTP(c, r) -} - -func renderPanic(x interface{}) string { - buf := make([]byte, 16<<10) // 16 KB should be plenty - buf = buf[:runtime.Stack(buf, false)] - - // Remove the first few stack frames: - // this func - // the recover closure in the caller - // That will root the stack trace at the site of the panic. - const ( - skipStart = "internal.renderPanic" - skipFrames = 2 - ) - start := bytes.Index(buf, []byte(skipStart)) - p := start - for i := 0; i < skipFrames*2 && p+1 < len(buf); i++ { - p = bytes.IndexByte(buf[p+1:], '\n') + p + 1 - if p < 0 { - break - } - } - if p >= 0 { - // buf[start:p+1] is the block to remove. - // Copy buf[p+1:] over buf[start:] and shrink buf. - copy(buf[start:], buf[p+1:]) - buf = buf[:len(buf)-(p+1-start)] - } - - // Add panic heading. - head := fmt.Sprintf("panic: %v\n\n", x) - if len(head) > len(buf) { - // Extremely unlikely to happen. - return head - } - copy(buf[len(head):], buf) - copy(buf, head) - - return string(buf) -} - -var ctxs = struct { - sync.Mutex - m map[*http.Request]*context - bg *context // background context, lazily initialized - // dec is used by tests to decorate the netcontext.Context returned - // for a given request. This allows tests to add overrides (such as - // WithAppIDOverride) to the context. The map is nil outside tests. - dec map[*http.Request]func(netcontext.Context) netcontext.Context -}{ - m: make(map[*http.Request]*context), -} - -// context represents the context of an in-flight HTTP request. -// It implements the appengine.Context and http.ResponseWriter interfaces. -type context struct { - req *http.Request - - outCode int - outHeader http.Header - outBody []byte - - pendingLogs struct { - sync.Mutex - lines []*logpb.UserAppLogLine - flushes int - } - - apiURL *url.URL -} - -var contextKey = "holds a *context" - -// fromContext returns the App Engine context or nil if ctx is not -// derived from an App Engine context. -func fromContext(ctx netcontext.Context) *context { - c, _ := ctx.Value(&contextKey).(*context) - return c -} - -func withContext(parent netcontext.Context, c *context) netcontext.Context { - ctx := netcontext.WithValue(parent, &contextKey, c) - if ns := c.req.Header.Get(curNamespaceHeader); ns != "" { - ctx = withNamespace(ctx, ns) - } - return ctx -} - -func toContext(c *context) netcontext.Context { - return withContext(netcontext.Background(), c) -} - -func IncomingHeaders(ctx netcontext.Context) http.Header { - if c := fromContext(ctx); c != nil { - return c.req.Header - } - return nil -} - -func WithContext(parent netcontext.Context, req *http.Request) netcontext.Context { - ctxs.Lock() - c := ctxs.m[req] - d := ctxs.dec[req] - ctxs.Unlock() - - if d != nil { - parent = d(parent) - } - - if c == nil { - // Someone passed in an http.Request that is not in-flight. - // We panic here rather than panicking at a later point - // so that stack traces will be more sensible. - log.Panic("appengine: NewContext passed an unknown http.Request") - } - return withContext(parent, c) -} - -// DefaultTicket returns a ticket used for background context or dev_appserver. -func DefaultTicket() string { - defaultTicketOnce.Do(func() { - if IsDevAppServer() { - defaultTicket = "testapp" + defaultTicketSuffix - return - } - appID := partitionlessAppID() - escAppID := strings.Replace(strings.Replace(appID, ":", "_", -1), ".", "_", -1) - majVersion := VersionID(nil) - if i := strings.Index(majVersion, "."); i > 0 { - majVersion = majVersion[:i] - } - defaultTicket = fmt.Sprintf("%s/%s.%s.%s", escAppID, ModuleName(nil), majVersion, InstanceID()) - }) - return defaultTicket -} - -func BackgroundContext() netcontext.Context { - ctxs.Lock() - defer ctxs.Unlock() - - if ctxs.bg != nil { - return toContext(ctxs.bg) - } - - // Compute background security ticket. - ticket := DefaultTicket() - - ctxs.bg = &context{ - req: &http.Request{ - Header: http.Header{ - ticketHeader: []string{ticket}, - }, - }, - apiURL: apiURL(), - } - - // TODO(dsymonds): Wire up the shutdown handler to do a final flush. - go ctxs.bg.logFlusher(make(chan int)) - - return toContext(ctxs.bg) -} - -// RegisterTestRequest registers the HTTP request req for testing, such that -// any API calls are sent to the provided URL. It returns a closure to delete -// the registration. -// It should only be used by aetest package. -func RegisterTestRequest(req *http.Request, apiURL *url.URL, decorate func(netcontext.Context) netcontext.Context) func() { - c := &context{ - req: req, - apiURL: apiURL, - } - ctxs.Lock() - defer ctxs.Unlock() - if _, ok := ctxs.m[req]; ok { - log.Panic("req already associated with context") - } - if _, ok := ctxs.dec[req]; ok { - log.Panic("req already associated with context") - } - if ctxs.dec == nil { - ctxs.dec = make(map[*http.Request]func(netcontext.Context) netcontext.Context) - } - ctxs.m[req] = c - ctxs.dec[req] = decorate - - return func() { - ctxs.Lock() - delete(ctxs.m, req) - delete(ctxs.dec, req) - ctxs.Unlock() - } -} - -var errTimeout = &CallError{ - Detail: "Deadline exceeded", - Code: int32(remotepb.RpcError_CANCELLED), - Timeout: true, -} - -func (c *context) Header() http.Header { return c.outHeader } - -// Copied from $GOROOT/src/pkg/net/http/transfer.go. Some response status -// codes do not permit a response body (nor response entity headers such as -// Content-Length, Content-Type, etc). -func bodyAllowedForStatus(status int) bool { - switch { - case status >= 100 && status <= 199: - return false - case status == 204: - return false - case status == 304: - return false - } - return true -} - -func (c *context) Write(b []byte) (int, error) { - if c.outCode == 0 { - c.WriteHeader(http.StatusOK) - } - if len(b) > 0 && !bodyAllowedForStatus(c.outCode) { - return 0, http.ErrBodyNotAllowed - } - c.outBody = append(c.outBody, b...) - return len(b), nil -} - -func (c *context) WriteHeader(code int) { - if c.outCode != 0 { - logf(c, 3, "WriteHeader called multiple times on request.") // error level - return - } - c.outCode = code -} - -func (c *context) post(body []byte, timeout time.Duration) (b []byte, err error) { - hreq := &http.Request{ - Method: "POST", - URL: c.apiURL, - Header: http.Header{ - apiEndpointHeader: apiEndpointHeaderValue, - apiMethodHeader: apiMethodHeaderValue, - apiContentType: apiContentTypeValue, - apiDeadlineHeader: []string{strconv.FormatFloat(timeout.Seconds(), 'f', -1, 64)}, - }, - Body: ioutil.NopCloser(bytes.NewReader(body)), - ContentLength: int64(len(body)), - Host: c.apiURL.Host, - } - if info := c.req.Header.Get(dapperHeader); info != "" { - hreq.Header.Set(dapperHeader, info) - } - if info := c.req.Header.Get(traceHeader); info != "" { - hreq.Header.Set(traceHeader, info) - } - - tr := apiHTTPClient.Transport.(*http.Transport) - - var timedOut int32 // atomic; set to 1 if timed out - t := time.AfterFunc(timeout, func() { - atomic.StoreInt32(&timedOut, 1) - tr.CancelRequest(hreq) - }) - defer t.Stop() - defer func() { - // Check if timeout was exceeded. - if atomic.LoadInt32(&timedOut) != 0 { - err = errTimeout - } - }() - - hresp, err := apiHTTPClient.Do(hreq) - if err != nil { - return nil, &CallError{ - Detail: fmt.Sprintf("service bridge HTTP failed: %v", err), - Code: int32(remotepb.RpcError_UNKNOWN), - } - } - defer hresp.Body.Close() - hrespBody, err := ioutil.ReadAll(hresp.Body) - if hresp.StatusCode != 200 { - return nil, &CallError{ - Detail: fmt.Sprintf("service bridge returned HTTP %d (%q)", hresp.StatusCode, hrespBody), - Code: int32(remotepb.RpcError_UNKNOWN), - } - } - if err != nil { - return nil, &CallError{ - Detail: fmt.Sprintf("service bridge response bad: %v", err), - Code: int32(remotepb.RpcError_UNKNOWN), - } - } - return hrespBody, nil -} - -func Call(ctx netcontext.Context, service, method string, in, out proto.Message) error { - if ns := NamespaceFromContext(ctx); ns != "" { - if fn, ok := NamespaceMods[service]; ok { - fn(in, ns) - } - } - - if f, ctx, ok := callOverrideFromContext(ctx); ok { - return f(ctx, service, method, in, out) - } - - // Handle already-done contexts quickly. - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - - c := fromContext(ctx) - if c == nil { - // Give a good error message rather than a panic lower down. - return errNotAppEngineContext - } - - // Apply transaction modifications if we're in a transaction. - if t := transactionFromContext(ctx); t != nil { - if t.finished { - return errors.New("transaction context has expired") - } - applyTransaction(in, &t.transaction) - } - - // Default RPC timeout is 60s. - timeout := 60 * time.Second - if deadline, ok := ctx.Deadline(); ok { - timeout = deadline.Sub(time.Now()) - } - - data, err := proto.Marshal(in) - if err != nil { - return err - } - - ticket := c.req.Header.Get(ticketHeader) - // Use a test ticket under test environment. - if ticket == "" { - if appid := ctx.Value(&appIDOverrideKey); appid != nil { - ticket = appid.(string) + defaultTicketSuffix - } - } - // Fall back to use background ticket when the request ticket is not available in Flex or dev_appserver. - if ticket == "" { - ticket = DefaultTicket() - } - req := &remotepb.Request{ - ServiceName: &service, - Method: &method, - Request: data, - RequestId: &ticket, - } - hreqBody, err := proto.Marshal(req) - if err != nil { - return err - } - - hrespBody, err := c.post(hreqBody, timeout) - if err != nil { - return err - } - - res := &remotepb.Response{} - if err := proto.Unmarshal(hrespBody, res); err != nil { - return err - } - if res.RpcError != nil { - ce := &CallError{ - Detail: res.RpcError.GetDetail(), - Code: *res.RpcError.Code, - } - switch remotepb.RpcError_ErrorCode(ce.Code) { - case remotepb.RpcError_CANCELLED, remotepb.RpcError_DEADLINE_EXCEEDED: - ce.Timeout = true - } - return ce - } - if res.ApplicationError != nil { - return &APIError{ - Service: *req.ServiceName, - Detail: res.ApplicationError.GetDetail(), - Code: *res.ApplicationError.Code, - } - } - if res.Exception != nil || res.JavaException != nil { - // This shouldn't happen, but let's be defensive. - return &CallError{ - Detail: "service bridge returned exception", - Code: int32(remotepb.RpcError_UNKNOWN), - } - } - return proto.Unmarshal(res.Response, out) -} - -func (c *context) Request() *http.Request { - return c.req -} - -func (c *context) addLogLine(ll *logpb.UserAppLogLine) { - // Truncate long log lines. - // TODO(dsymonds): Check if this is still necessary. - const lim = 8 << 10 - if len(*ll.Message) > lim { - suffix := fmt.Sprintf("...(length %d)", len(*ll.Message)) - ll.Message = proto.String((*ll.Message)[:lim-len(suffix)] + suffix) - } - - c.pendingLogs.Lock() - c.pendingLogs.lines = append(c.pendingLogs.lines, ll) - c.pendingLogs.Unlock() -} - -var logLevelName = map[int64]string{ - 0: "DEBUG", - 1: "INFO", - 2: "WARNING", - 3: "ERROR", - 4: "CRITICAL", -} - -func logf(c *context, level int64, format string, args ...interface{}) { - if c == nil { - panic("not an App Engine context") - } - s := fmt.Sprintf(format, args...) - s = strings.TrimRight(s, "\n") // Remove any trailing newline characters. - c.addLogLine(&logpb.UserAppLogLine{ - TimestampUsec: proto.Int64(time.Now().UnixNano() / 1e3), - Level: &level, - Message: &s, - }) - log.Print(logLevelName[level] + ": " + s) -} - -// flushLog attempts to flush any pending logs to the appserver. -// It should not be called concurrently. -func (c *context) flushLog(force bool) (flushed bool) { - c.pendingLogs.Lock() - // Grab up to 30 MB. We can get away with up to 32 MB, but let's be cautious. - n, rem := 0, 30<<20 - for ; n < len(c.pendingLogs.lines); n++ { - ll := c.pendingLogs.lines[n] - // Each log line will require about 3 bytes of overhead. - nb := proto.Size(ll) + 3 - if nb > rem { - break - } - rem -= nb - } - lines := c.pendingLogs.lines[:n] - c.pendingLogs.lines = c.pendingLogs.lines[n:] - c.pendingLogs.Unlock() - - if len(lines) == 0 && !force { - // Nothing to flush. - return false - } - - rescueLogs := false - defer func() { - if rescueLogs { - c.pendingLogs.Lock() - c.pendingLogs.lines = append(lines, c.pendingLogs.lines...) - c.pendingLogs.Unlock() - } - }() - - buf, err := proto.Marshal(&logpb.UserAppLogGroup{ - LogLine: lines, - }) - if err != nil { - log.Printf("internal.flushLog: marshaling UserAppLogGroup: %v", err) - rescueLogs = true - return false - } - - req := &logpb.FlushRequest{ - Logs: buf, - } - res := &basepb.VoidProto{} - c.pendingLogs.Lock() - c.pendingLogs.flushes++ - c.pendingLogs.Unlock() - if err := Call(toContext(c), "logservice", "Flush", req, res); err != nil { - log.Printf("internal.flushLog: Flush RPC: %v", err) - rescueLogs = true - return false - } - return true -} - -const ( - // Log flushing parameters. - flushInterval = 1 * time.Second - forceFlushInterval = 60 * time.Second -) - -func (c *context) logFlusher(stop <-chan int) { - lastFlush := time.Now() - tick := time.NewTicker(flushInterval) - for { - select { - case <-stop: - // Request finished. - tick.Stop() - return - case <-tick.C: - force := time.Now().Sub(lastFlush) > forceFlushInterval - if c.flushLog(force) { - lastFlush = time.Now() - } - } - } -} - -func ContextForTesting(req *http.Request) netcontext.Context { - return toContext(&context{req: req}) -} diff --git a/vendor/google.golang.org/appengine/internal/api_common.go b/vendor/google.golang.org/appengine/internal/api_common.go deleted file mode 100644 index e0c0b214b724212071f072eadd289c73af3d154b..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/api_common.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2015 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package internal - -import ( - "errors" - "os" - - "github.com/golang/protobuf/proto" - netcontext "golang.org/x/net/context" -) - -var errNotAppEngineContext = errors.New("not an App Engine context") - -type CallOverrideFunc func(ctx netcontext.Context, service, method string, in, out proto.Message) error - -var callOverrideKey = "holds []CallOverrideFunc" - -func WithCallOverride(ctx netcontext.Context, f CallOverrideFunc) netcontext.Context { - // We avoid appending to any existing call override - // so we don't risk overwriting a popped stack below. - var cofs []CallOverrideFunc - if uf, ok := ctx.Value(&callOverrideKey).([]CallOverrideFunc); ok { - cofs = append(cofs, uf...) - } - cofs = append(cofs, f) - return netcontext.WithValue(ctx, &callOverrideKey, cofs) -} - -func callOverrideFromContext(ctx netcontext.Context) (CallOverrideFunc, netcontext.Context, bool) { - cofs, _ := ctx.Value(&callOverrideKey).([]CallOverrideFunc) - if len(cofs) == 0 { - return nil, nil, false - } - // We found a list of overrides; grab the last, and reconstitute a - // context that will hide it. - f := cofs[len(cofs)-1] - ctx = netcontext.WithValue(ctx, &callOverrideKey, cofs[:len(cofs)-1]) - return f, ctx, true -} - -type logOverrideFunc func(level int64, format string, args ...interface{}) - -var logOverrideKey = "holds a logOverrideFunc" - -func WithLogOverride(ctx netcontext.Context, f logOverrideFunc) netcontext.Context { - return netcontext.WithValue(ctx, &logOverrideKey, f) -} - -var appIDOverrideKey = "holds a string, being the full app ID" - -func WithAppIDOverride(ctx netcontext.Context, appID string) netcontext.Context { - return netcontext.WithValue(ctx, &appIDOverrideKey, appID) -} - -var namespaceKey = "holds the namespace string" - -func withNamespace(ctx netcontext.Context, ns string) netcontext.Context { - return netcontext.WithValue(ctx, &namespaceKey, ns) -} - -func NamespaceFromContext(ctx netcontext.Context) string { - // If there's no namespace, return the empty string. - ns, _ := ctx.Value(&namespaceKey).(string) - return ns -} - -// FullyQualifiedAppID returns the fully-qualified application ID. -// This may contain a partition prefix (e.g. "s~" for High Replication apps), -// or a domain prefix (e.g. "example.com:"). -func FullyQualifiedAppID(ctx netcontext.Context) string { - if id, ok := ctx.Value(&appIDOverrideKey).(string); ok { - return id - } - return fullyQualifiedAppID(ctx) -} - -func Logf(ctx netcontext.Context, level int64, format string, args ...interface{}) { - if f, ok := ctx.Value(&logOverrideKey).(logOverrideFunc); ok { - f(level, format, args...) - return - } - c := fromContext(ctx) - if c == nil { - panic(errNotAppEngineContext) - } - logf(c, level, format, args...) -} - -// NamespacedContext wraps a Context to support namespaces. -func NamespacedContext(ctx netcontext.Context, namespace string) netcontext.Context { - return withNamespace(ctx, namespace) -} - -// SetTestEnv sets the env variables for testing background ticket in Flex. -func SetTestEnv() func() { - var environ = []struct { - key, value string - }{ - {"GAE_LONG_APP_ID", "my-app-id"}, - {"GAE_MINOR_VERSION", "067924799508853122"}, - {"GAE_MODULE_INSTANCE", "0"}, - {"GAE_MODULE_NAME", "default"}, - {"GAE_MODULE_VERSION", "20150612t184001"}, - } - - for _, v := range environ { - old := os.Getenv(v.key) - os.Setenv(v.key, v.value) - v.value = old - } - return func() { // Restore old environment after the test completes. - for _, v := range environ { - if v.value == "" { - os.Unsetenv(v.key) - continue - } - os.Setenv(v.key, v.value) - } - } -} diff --git a/vendor/google.golang.org/appengine/internal/app_id.go b/vendor/google.golang.org/appengine/internal/app_id.go deleted file mode 100644 index 11df8c07b53863dc159518a47ee5b906bdc7c4f1..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/app_id.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package internal - -import ( - "strings" -) - -func parseFullAppID(appid string) (partition, domain, displayID string) { - if i := strings.Index(appid, "~"); i != -1 { - partition, appid = appid[:i], appid[i+1:] - } - if i := strings.Index(appid, ":"); i != -1 { - domain, appid = appid[:i], appid[i+1:] - } - return partition, domain, appid -} - -// appID returns "appid" or "domain.com:appid". -func appID(fullAppID string) string { - _, dom, dis := parseFullAppID(fullAppID) - if dom != "" { - return dom + ":" + dis - } - return dis -} diff --git a/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.pb.go b/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.pb.go deleted file mode 100644 index 87d9701b8df951453734099ac31f6c49f0a08d08..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.pb.go +++ /dev/null @@ -1,296 +0,0 @@ -// Code generated by protoc-gen-go. -// source: google.golang.org/appengine/internal/app_identity/app_identity_service.proto -// DO NOT EDIT! - -/* -Package app_identity is a generated protocol buffer package. - -It is generated from these files: - google.golang.org/appengine/internal/app_identity/app_identity_service.proto - -It has these top-level messages: - AppIdentityServiceError - SignForAppRequest - SignForAppResponse - GetPublicCertificateForAppRequest - PublicCertificate - GetPublicCertificateForAppResponse - GetServiceAccountNameRequest - GetServiceAccountNameResponse - GetAccessTokenRequest - GetAccessTokenResponse - GetDefaultGcsBucketNameRequest - GetDefaultGcsBucketNameResponse -*/ -package app_identity - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type AppIdentityServiceError_ErrorCode int32 - -const ( - AppIdentityServiceError_SUCCESS AppIdentityServiceError_ErrorCode = 0 - AppIdentityServiceError_UNKNOWN_SCOPE AppIdentityServiceError_ErrorCode = 9 - AppIdentityServiceError_BLOB_TOO_LARGE AppIdentityServiceError_ErrorCode = 1000 - AppIdentityServiceError_DEADLINE_EXCEEDED AppIdentityServiceError_ErrorCode = 1001 - AppIdentityServiceError_NOT_A_VALID_APP AppIdentityServiceError_ErrorCode = 1002 - AppIdentityServiceError_UNKNOWN_ERROR AppIdentityServiceError_ErrorCode = 1003 - AppIdentityServiceError_NOT_ALLOWED AppIdentityServiceError_ErrorCode = 1005 - AppIdentityServiceError_NOT_IMPLEMENTED AppIdentityServiceError_ErrorCode = 1006 -) - -var AppIdentityServiceError_ErrorCode_name = map[int32]string{ - 0: "SUCCESS", - 9: "UNKNOWN_SCOPE", - 1000: "BLOB_TOO_LARGE", - 1001: "DEADLINE_EXCEEDED", - 1002: "NOT_A_VALID_APP", - 1003: "UNKNOWN_ERROR", - 1005: "NOT_ALLOWED", - 1006: "NOT_IMPLEMENTED", -} -var AppIdentityServiceError_ErrorCode_value = map[string]int32{ - "SUCCESS": 0, - "UNKNOWN_SCOPE": 9, - "BLOB_TOO_LARGE": 1000, - "DEADLINE_EXCEEDED": 1001, - "NOT_A_VALID_APP": 1002, - "UNKNOWN_ERROR": 1003, - "NOT_ALLOWED": 1005, - "NOT_IMPLEMENTED": 1006, -} - -func (x AppIdentityServiceError_ErrorCode) Enum() *AppIdentityServiceError_ErrorCode { - p := new(AppIdentityServiceError_ErrorCode) - *p = x - return p -} -func (x AppIdentityServiceError_ErrorCode) String() string { - return proto.EnumName(AppIdentityServiceError_ErrorCode_name, int32(x)) -} -func (x *AppIdentityServiceError_ErrorCode) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(AppIdentityServiceError_ErrorCode_value, data, "AppIdentityServiceError_ErrorCode") - if err != nil { - return err - } - *x = AppIdentityServiceError_ErrorCode(value) - return nil -} - -type AppIdentityServiceError struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *AppIdentityServiceError) Reset() { *m = AppIdentityServiceError{} } -func (m *AppIdentityServiceError) String() string { return proto.CompactTextString(m) } -func (*AppIdentityServiceError) ProtoMessage() {} - -type SignForAppRequest struct { - BytesToSign []byte `protobuf:"bytes,1,opt,name=bytes_to_sign" json:"bytes_to_sign,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *SignForAppRequest) Reset() { *m = SignForAppRequest{} } -func (m *SignForAppRequest) String() string { return proto.CompactTextString(m) } -func (*SignForAppRequest) ProtoMessage() {} - -func (m *SignForAppRequest) GetBytesToSign() []byte { - if m != nil { - return m.BytesToSign - } - return nil -} - -type SignForAppResponse struct { - KeyName *string `protobuf:"bytes,1,opt,name=key_name" json:"key_name,omitempty"` - SignatureBytes []byte `protobuf:"bytes,2,opt,name=signature_bytes" json:"signature_bytes,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *SignForAppResponse) Reset() { *m = SignForAppResponse{} } -func (m *SignForAppResponse) String() string { return proto.CompactTextString(m) } -func (*SignForAppResponse) ProtoMessage() {} - -func (m *SignForAppResponse) GetKeyName() string { - if m != nil && m.KeyName != nil { - return *m.KeyName - } - return "" -} - -func (m *SignForAppResponse) GetSignatureBytes() []byte { - if m != nil { - return m.SignatureBytes - } - return nil -} - -type GetPublicCertificateForAppRequest struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetPublicCertificateForAppRequest) Reset() { *m = GetPublicCertificateForAppRequest{} } -func (m *GetPublicCertificateForAppRequest) String() string { return proto.CompactTextString(m) } -func (*GetPublicCertificateForAppRequest) ProtoMessage() {} - -type PublicCertificate struct { - KeyName *string `protobuf:"bytes,1,opt,name=key_name" json:"key_name,omitempty"` - X509CertificatePem *string `protobuf:"bytes,2,opt,name=x509_certificate_pem" json:"x509_certificate_pem,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PublicCertificate) Reset() { *m = PublicCertificate{} } -func (m *PublicCertificate) String() string { return proto.CompactTextString(m) } -func (*PublicCertificate) ProtoMessage() {} - -func (m *PublicCertificate) GetKeyName() string { - if m != nil && m.KeyName != nil { - return *m.KeyName - } - return "" -} - -func (m *PublicCertificate) GetX509CertificatePem() string { - if m != nil && m.X509CertificatePem != nil { - return *m.X509CertificatePem - } - return "" -} - -type GetPublicCertificateForAppResponse struct { - PublicCertificateList []*PublicCertificate `protobuf:"bytes,1,rep,name=public_certificate_list" json:"public_certificate_list,omitempty"` - MaxClientCacheTimeInSecond *int64 `protobuf:"varint,2,opt,name=max_client_cache_time_in_second" json:"max_client_cache_time_in_second,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetPublicCertificateForAppResponse) Reset() { *m = GetPublicCertificateForAppResponse{} } -func (m *GetPublicCertificateForAppResponse) String() string { return proto.CompactTextString(m) } -func (*GetPublicCertificateForAppResponse) ProtoMessage() {} - -func (m *GetPublicCertificateForAppResponse) GetPublicCertificateList() []*PublicCertificate { - if m != nil { - return m.PublicCertificateList - } - return nil -} - -func (m *GetPublicCertificateForAppResponse) GetMaxClientCacheTimeInSecond() int64 { - if m != nil && m.MaxClientCacheTimeInSecond != nil { - return *m.MaxClientCacheTimeInSecond - } - return 0 -} - -type GetServiceAccountNameRequest struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetServiceAccountNameRequest) Reset() { *m = GetServiceAccountNameRequest{} } -func (m *GetServiceAccountNameRequest) String() string { return proto.CompactTextString(m) } -func (*GetServiceAccountNameRequest) ProtoMessage() {} - -type GetServiceAccountNameResponse struct { - ServiceAccountName *string `protobuf:"bytes,1,opt,name=service_account_name" json:"service_account_name,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetServiceAccountNameResponse) Reset() { *m = GetServiceAccountNameResponse{} } -func (m *GetServiceAccountNameResponse) String() string { return proto.CompactTextString(m) } -func (*GetServiceAccountNameResponse) ProtoMessage() {} - -func (m *GetServiceAccountNameResponse) GetServiceAccountName() string { - if m != nil && m.ServiceAccountName != nil { - return *m.ServiceAccountName - } - return "" -} - -type GetAccessTokenRequest struct { - Scope []string `protobuf:"bytes,1,rep,name=scope" json:"scope,omitempty"` - ServiceAccountId *int64 `protobuf:"varint,2,opt,name=service_account_id" json:"service_account_id,omitempty"` - ServiceAccountName *string `protobuf:"bytes,3,opt,name=service_account_name" json:"service_account_name,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetAccessTokenRequest) Reset() { *m = GetAccessTokenRequest{} } -func (m *GetAccessTokenRequest) String() string { return proto.CompactTextString(m) } -func (*GetAccessTokenRequest) ProtoMessage() {} - -func (m *GetAccessTokenRequest) GetScope() []string { - if m != nil { - return m.Scope - } - return nil -} - -func (m *GetAccessTokenRequest) GetServiceAccountId() int64 { - if m != nil && m.ServiceAccountId != nil { - return *m.ServiceAccountId - } - return 0 -} - -func (m *GetAccessTokenRequest) GetServiceAccountName() string { - if m != nil && m.ServiceAccountName != nil { - return *m.ServiceAccountName - } - return "" -} - -type GetAccessTokenResponse struct { - AccessToken *string `protobuf:"bytes,1,opt,name=access_token" json:"access_token,omitempty"` - ExpirationTime *int64 `protobuf:"varint,2,opt,name=expiration_time" json:"expiration_time,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetAccessTokenResponse) Reset() { *m = GetAccessTokenResponse{} } -func (m *GetAccessTokenResponse) String() string { return proto.CompactTextString(m) } -func (*GetAccessTokenResponse) ProtoMessage() {} - -func (m *GetAccessTokenResponse) GetAccessToken() string { - if m != nil && m.AccessToken != nil { - return *m.AccessToken - } - return "" -} - -func (m *GetAccessTokenResponse) GetExpirationTime() int64 { - if m != nil && m.ExpirationTime != nil { - return *m.ExpirationTime - } - return 0 -} - -type GetDefaultGcsBucketNameRequest struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetDefaultGcsBucketNameRequest) Reset() { *m = GetDefaultGcsBucketNameRequest{} } -func (m *GetDefaultGcsBucketNameRequest) String() string { return proto.CompactTextString(m) } -func (*GetDefaultGcsBucketNameRequest) ProtoMessage() {} - -type GetDefaultGcsBucketNameResponse struct { - DefaultGcsBucketName *string `protobuf:"bytes,1,opt,name=default_gcs_bucket_name" json:"default_gcs_bucket_name,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetDefaultGcsBucketNameResponse) Reset() { *m = GetDefaultGcsBucketNameResponse{} } -func (m *GetDefaultGcsBucketNameResponse) String() string { return proto.CompactTextString(m) } -func (*GetDefaultGcsBucketNameResponse) ProtoMessage() {} - -func (m *GetDefaultGcsBucketNameResponse) GetDefaultGcsBucketName() string { - if m != nil && m.DefaultGcsBucketName != nil { - return *m.DefaultGcsBucketName - } - return "" -} - -func init() { -} diff --git a/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.proto b/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.proto deleted file mode 100644 index 19610ca5b753fb4ff69a8c6a565fa192827b571c..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/app_identity/app_identity_service.proto +++ /dev/null @@ -1,64 +0,0 @@ -syntax = "proto2"; -option go_package = "app_identity"; - -package appengine; - -message AppIdentityServiceError { - enum ErrorCode { - SUCCESS = 0; - UNKNOWN_SCOPE = 9; - BLOB_TOO_LARGE = 1000; - DEADLINE_EXCEEDED = 1001; - NOT_A_VALID_APP = 1002; - UNKNOWN_ERROR = 1003; - NOT_ALLOWED = 1005; - NOT_IMPLEMENTED = 1006; - } -} - -message SignForAppRequest { - optional bytes bytes_to_sign = 1; -} - -message SignForAppResponse { - optional string key_name = 1; - optional bytes signature_bytes = 2; -} - -message GetPublicCertificateForAppRequest { -} - -message PublicCertificate { - optional string key_name = 1; - optional string x509_certificate_pem = 2; -} - -message GetPublicCertificateForAppResponse { - repeated PublicCertificate public_certificate_list = 1; - optional int64 max_client_cache_time_in_second = 2; -} - -message GetServiceAccountNameRequest { -} - -message GetServiceAccountNameResponse { - optional string service_account_name = 1; -} - -message GetAccessTokenRequest { - repeated string scope = 1; - optional int64 service_account_id = 2; - optional string service_account_name = 3; -} - -message GetAccessTokenResponse { - optional string access_token = 1; - optional int64 expiration_time = 2; -} - -message GetDefaultGcsBucketNameRequest { -} - -message GetDefaultGcsBucketNameResponse { - optional string default_gcs_bucket_name = 1; -} diff --git a/vendor/google.golang.org/appengine/internal/base/api_base.pb.go b/vendor/google.golang.org/appengine/internal/base/api_base.pb.go deleted file mode 100644 index 36a195650a951d8f604737cfb71af716a533f2ef..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/base/api_base.pb.go +++ /dev/null @@ -1,133 +0,0 @@ -// Code generated by protoc-gen-go. -// source: google.golang.org/appengine/internal/base/api_base.proto -// DO NOT EDIT! - -/* -Package base is a generated protocol buffer package. - -It is generated from these files: - google.golang.org/appengine/internal/base/api_base.proto - -It has these top-level messages: - StringProto - Integer32Proto - Integer64Proto - BoolProto - DoubleProto - BytesProto - VoidProto -*/ -package base - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type StringProto struct { - Value *string `protobuf:"bytes,1,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *StringProto) Reset() { *m = StringProto{} } -func (m *StringProto) String() string { return proto.CompactTextString(m) } -func (*StringProto) ProtoMessage() {} - -func (m *StringProto) GetValue() string { - if m != nil && m.Value != nil { - return *m.Value - } - return "" -} - -type Integer32Proto struct { - Value *int32 `protobuf:"varint,1,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Integer32Proto) Reset() { *m = Integer32Proto{} } -func (m *Integer32Proto) String() string { return proto.CompactTextString(m) } -func (*Integer32Proto) ProtoMessage() {} - -func (m *Integer32Proto) GetValue() int32 { - if m != nil && m.Value != nil { - return *m.Value - } - return 0 -} - -type Integer64Proto struct { - Value *int64 `protobuf:"varint,1,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Integer64Proto) Reset() { *m = Integer64Proto{} } -func (m *Integer64Proto) String() string { return proto.CompactTextString(m) } -func (*Integer64Proto) ProtoMessage() {} - -func (m *Integer64Proto) GetValue() int64 { - if m != nil && m.Value != nil { - return *m.Value - } - return 0 -} - -type BoolProto struct { - Value *bool `protobuf:"varint,1,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *BoolProto) Reset() { *m = BoolProto{} } -func (m *BoolProto) String() string { return proto.CompactTextString(m) } -func (*BoolProto) ProtoMessage() {} - -func (m *BoolProto) GetValue() bool { - if m != nil && m.Value != nil { - return *m.Value - } - return false -} - -type DoubleProto struct { - Value *float64 `protobuf:"fixed64,1,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *DoubleProto) Reset() { *m = DoubleProto{} } -func (m *DoubleProto) String() string { return proto.CompactTextString(m) } -func (*DoubleProto) ProtoMessage() {} - -func (m *DoubleProto) GetValue() float64 { - if m != nil && m.Value != nil { - return *m.Value - } - return 0 -} - -type BytesProto struct { - Value []byte `protobuf:"bytes,1,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *BytesProto) Reset() { *m = BytesProto{} } -func (m *BytesProto) String() string { return proto.CompactTextString(m) } -func (*BytesProto) ProtoMessage() {} - -func (m *BytesProto) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type VoidProto struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *VoidProto) Reset() { *m = VoidProto{} } -func (m *VoidProto) String() string { return proto.CompactTextString(m) } -func (*VoidProto) ProtoMessage() {} diff --git a/vendor/google.golang.org/appengine/internal/base/api_base.proto b/vendor/google.golang.org/appengine/internal/base/api_base.proto deleted file mode 100644 index 56cd7a3cad05e290f84a97ce8d55ffd4d1a6e299..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/base/api_base.proto +++ /dev/null @@ -1,33 +0,0 @@ -// Built-in base types for API calls. Primarily useful as return types. - -syntax = "proto2"; -option go_package = "base"; - -package appengine.base; - -message StringProto { - required string value = 1; -} - -message Integer32Proto { - required int32 value = 1; -} - -message Integer64Proto { - required int64 value = 1; -} - -message BoolProto { - required bool value = 1; -} - -message DoubleProto { - required double value = 1; -} - -message BytesProto { - required bytes value = 1 [ctype=CORD]; -} - -message VoidProto { -} diff --git a/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go b/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go deleted file mode 100644 index 8613cb7311af8dc3faf23755caacab8b1a66ed9c..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go +++ /dev/null @@ -1,2778 +0,0 @@ -// Code generated by protoc-gen-go. -// source: google.golang.org/appengine/internal/datastore/datastore_v3.proto -// DO NOT EDIT! - -/* -Package datastore is a generated protocol buffer package. - -It is generated from these files: - google.golang.org/appengine/internal/datastore/datastore_v3.proto - -It has these top-level messages: - Action - PropertyValue - Property - Path - Reference - User - EntityProto - CompositeProperty - Index - CompositeIndex - IndexPostfix - IndexPosition - Snapshot - InternalHeader - Transaction - Query - CompiledQuery - CompiledCursor - Cursor - Error - Cost - GetRequest - GetResponse - PutRequest - PutResponse - TouchRequest - TouchResponse - DeleteRequest - DeleteResponse - NextRequest - QueryResult - AllocateIdsRequest - AllocateIdsResponse - CompositeIndices - AddActionsRequest - AddActionsResponse - BeginTransactionRequest - CommitResponse -*/ -package datastore - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type Property_Meaning int32 - -const ( - Property_NO_MEANING Property_Meaning = 0 - Property_BLOB Property_Meaning = 14 - Property_TEXT Property_Meaning = 15 - Property_BYTESTRING Property_Meaning = 16 - Property_ATOM_CATEGORY Property_Meaning = 1 - Property_ATOM_LINK Property_Meaning = 2 - Property_ATOM_TITLE Property_Meaning = 3 - Property_ATOM_CONTENT Property_Meaning = 4 - Property_ATOM_SUMMARY Property_Meaning = 5 - Property_ATOM_AUTHOR Property_Meaning = 6 - Property_GD_WHEN Property_Meaning = 7 - Property_GD_EMAIL Property_Meaning = 8 - Property_GEORSS_POINT Property_Meaning = 9 - Property_GD_IM Property_Meaning = 10 - Property_GD_PHONENUMBER Property_Meaning = 11 - Property_GD_POSTALADDRESS Property_Meaning = 12 - Property_GD_RATING Property_Meaning = 13 - Property_BLOBKEY Property_Meaning = 17 - Property_ENTITY_PROTO Property_Meaning = 19 - Property_INDEX_VALUE Property_Meaning = 18 -) - -var Property_Meaning_name = map[int32]string{ - 0: "NO_MEANING", - 14: "BLOB", - 15: "TEXT", - 16: "BYTESTRING", - 1: "ATOM_CATEGORY", - 2: "ATOM_LINK", - 3: "ATOM_TITLE", - 4: "ATOM_CONTENT", - 5: "ATOM_SUMMARY", - 6: "ATOM_AUTHOR", - 7: "GD_WHEN", - 8: "GD_EMAIL", - 9: "GEORSS_POINT", - 10: "GD_IM", - 11: "GD_PHONENUMBER", - 12: "GD_POSTALADDRESS", - 13: "GD_RATING", - 17: "BLOBKEY", - 19: "ENTITY_PROTO", - 18: "INDEX_VALUE", -} -var Property_Meaning_value = map[string]int32{ - "NO_MEANING": 0, - "BLOB": 14, - "TEXT": 15, - "BYTESTRING": 16, - "ATOM_CATEGORY": 1, - "ATOM_LINK": 2, - "ATOM_TITLE": 3, - "ATOM_CONTENT": 4, - "ATOM_SUMMARY": 5, - "ATOM_AUTHOR": 6, - "GD_WHEN": 7, - "GD_EMAIL": 8, - "GEORSS_POINT": 9, - "GD_IM": 10, - "GD_PHONENUMBER": 11, - "GD_POSTALADDRESS": 12, - "GD_RATING": 13, - "BLOBKEY": 17, - "ENTITY_PROTO": 19, - "INDEX_VALUE": 18, -} - -func (x Property_Meaning) Enum() *Property_Meaning { - p := new(Property_Meaning) - *p = x - return p -} -func (x Property_Meaning) String() string { - return proto.EnumName(Property_Meaning_name, int32(x)) -} -func (x *Property_Meaning) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Property_Meaning_value, data, "Property_Meaning") - if err != nil { - return err - } - *x = Property_Meaning(value) - return nil -} - -type Property_FtsTokenizationOption int32 - -const ( - Property_HTML Property_FtsTokenizationOption = 1 - Property_ATOM Property_FtsTokenizationOption = 2 -) - -var Property_FtsTokenizationOption_name = map[int32]string{ - 1: "HTML", - 2: "ATOM", -} -var Property_FtsTokenizationOption_value = map[string]int32{ - "HTML": 1, - "ATOM": 2, -} - -func (x Property_FtsTokenizationOption) Enum() *Property_FtsTokenizationOption { - p := new(Property_FtsTokenizationOption) - *p = x - return p -} -func (x Property_FtsTokenizationOption) String() string { - return proto.EnumName(Property_FtsTokenizationOption_name, int32(x)) -} -func (x *Property_FtsTokenizationOption) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Property_FtsTokenizationOption_value, data, "Property_FtsTokenizationOption") - if err != nil { - return err - } - *x = Property_FtsTokenizationOption(value) - return nil -} - -type EntityProto_Kind int32 - -const ( - EntityProto_GD_CONTACT EntityProto_Kind = 1 - EntityProto_GD_EVENT EntityProto_Kind = 2 - EntityProto_GD_MESSAGE EntityProto_Kind = 3 -) - -var EntityProto_Kind_name = map[int32]string{ - 1: "GD_CONTACT", - 2: "GD_EVENT", - 3: "GD_MESSAGE", -} -var EntityProto_Kind_value = map[string]int32{ - "GD_CONTACT": 1, - "GD_EVENT": 2, - "GD_MESSAGE": 3, -} - -func (x EntityProto_Kind) Enum() *EntityProto_Kind { - p := new(EntityProto_Kind) - *p = x - return p -} -func (x EntityProto_Kind) String() string { - return proto.EnumName(EntityProto_Kind_name, int32(x)) -} -func (x *EntityProto_Kind) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(EntityProto_Kind_value, data, "EntityProto_Kind") - if err != nil { - return err - } - *x = EntityProto_Kind(value) - return nil -} - -type Index_Property_Direction int32 - -const ( - Index_Property_ASCENDING Index_Property_Direction = 1 - Index_Property_DESCENDING Index_Property_Direction = 2 -) - -var Index_Property_Direction_name = map[int32]string{ - 1: "ASCENDING", - 2: "DESCENDING", -} -var Index_Property_Direction_value = map[string]int32{ - "ASCENDING": 1, - "DESCENDING": 2, -} - -func (x Index_Property_Direction) Enum() *Index_Property_Direction { - p := new(Index_Property_Direction) - *p = x - return p -} -func (x Index_Property_Direction) String() string { - return proto.EnumName(Index_Property_Direction_name, int32(x)) -} -func (x *Index_Property_Direction) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Index_Property_Direction_value, data, "Index_Property_Direction") - if err != nil { - return err - } - *x = Index_Property_Direction(value) - return nil -} - -type CompositeIndex_State int32 - -const ( - CompositeIndex_WRITE_ONLY CompositeIndex_State = 1 - CompositeIndex_READ_WRITE CompositeIndex_State = 2 - CompositeIndex_DELETED CompositeIndex_State = 3 - CompositeIndex_ERROR CompositeIndex_State = 4 -) - -var CompositeIndex_State_name = map[int32]string{ - 1: "WRITE_ONLY", - 2: "READ_WRITE", - 3: "DELETED", - 4: "ERROR", -} -var CompositeIndex_State_value = map[string]int32{ - "WRITE_ONLY": 1, - "READ_WRITE": 2, - "DELETED": 3, - "ERROR": 4, -} - -func (x CompositeIndex_State) Enum() *CompositeIndex_State { - p := new(CompositeIndex_State) - *p = x - return p -} -func (x CompositeIndex_State) String() string { - return proto.EnumName(CompositeIndex_State_name, int32(x)) -} -func (x *CompositeIndex_State) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(CompositeIndex_State_value, data, "CompositeIndex_State") - if err != nil { - return err - } - *x = CompositeIndex_State(value) - return nil -} - -type Snapshot_Status int32 - -const ( - Snapshot_INACTIVE Snapshot_Status = 0 - Snapshot_ACTIVE Snapshot_Status = 1 -) - -var Snapshot_Status_name = map[int32]string{ - 0: "INACTIVE", - 1: "ACTIVE", -} -var Snapshot_Status_value = map[string]int32{ - "INACTIVE": 0, - "ACTIVE": 1, -} - -func (x Snapshot_Status) Enum() *Snapshot_Status { - p := new(Snapshot_Status) - *p = x - return p -} -func (x Snapshot_Status) String() string { - return proto.EnumName(Snapshot_Status_name, int32(x)) -} -func (x *Snapshot_Status) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Snapshot_Status_value, data, "Snapshot_Status") - if err != nil { - return err - } - *x = Snapshot_Status(value) - return nil -} - -type Query_Hint int32 - -const ( - Query_ORDER_FIRST Query_Hint = 1 - Query_ANCESTOR_FIRST Query_Hint = 2 - Query_FILTER_FIRST Query_Hint = 3 -) - -var Query_Hint_name = map[int32]string{ - 1: "ORDER_FIRST", - 2: "ANCESTOR_FIRST", - 3: "FILTER_FIRST", -} -var Query_Hint_value = map[string]int32{ - "ORDER_FIRST": 1, - "ANCESTOR_FIRST": 2, - "FILTER_FIRST": 3, -} - -func (x Query_Hint) Enum() *Query_Hint { - p := new(Query_Hint) - *p = x - return p -} -func (x Query_Hint) String() string { - return proto.EnumName(Query_Hint_name, int32(x)) -} -func (x *Query_Hint) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Query_Hint_value, data, "Query_Hint") - if err != nil { - return err - } - *x = Query_Hint(value) - return nil -} - -type Query_Filter_Operator int32 - -const ( - Query_Filter_LESS_THAN Query_Filter_Operator = 1 - Query_Filter_LESS_THAN_OR_EQUAL Query_Filter_Operator = 2 - Query_Filter_GREATER_THAN Query_Filter_Operator = 3 - Query_Filter_GREATER_THAN_OR_EQUAL Query_Filter_Operator = 4 - Query_Filter_EQUAL Query_Filter_Operator = 5 - Query_Filter_IN Query_Filter_Operator = 6 - Query_Filter_EXISTS Query_Filter_Operator = 7 -) - -var Query_Filter_Operator_name = map[int32]string{ - 1: "LESS_THAN", - 2: "LESS_THAN_OR_EQUAL", - 3: "GREATER_THAN", - 4: "GREATER_THAN_OR_EQUAL", - 5: "EQUAL", - 6: "IN", - 7: "EXISTS", -} -var Query_Filter_Operator_value = map[string]int32{ - "LESS_THAN": 1, - "LESS_THAN_OR_EQUAL": 2, - "GREATER_THAN": 3, - "GREATER_THAN_OR_EQUAL": 4, - "EQUAL": 5, - "IN": 6, - "EXISTS": 7, -} - -func (x Query_Filter_Operator) Enum() *Query_Filter_Operator { - p := new(Query_Filter_Operator) - *p = x - return p -} -func (x Query_Filter_Operator) String() string { - return proto.EnumName(Query_Filter_Operator_name, int32(x)) -} -func (x *Query_Filter_Operator) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Query_Filter_Operator_value, data, "Query_Filter_Operator") - if err != nil { - return err - } - *x = Query_Filter_Operator(value) - return nil -} - -type Query_Order_Direction int32 - -const ( - Query_Order_ASCENDING Query_Order_Direction = 1 - Query_Order_DESCENDING Query_Order_Direction = 2 -) - -var Query_Order_Direction_name = map[int32]string{ - 1: "ASCENDING", - 2: "DESCENDING", -} -var Query_Order_Direction_value = map[string]int32{ - "ASCENDING": 1, - "DESCENDING": 2, -} - -func (x Query_Order_Direction) Enum() *Query_Order_Direction { - p := new(Query_Order_Direction) - *p = x - return p -} -func (x Query_Order_Direction) String() string { - return proto.EnumName(Query_Order_Direction_name, int32(x)) -} -func (x *Query_Order_Direction) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Query_Order_Direction_value, data, "Query_Order_Direction") - if err != nil { - return err - } - *x = Query_Order_Direction(value) - return nil -} - -type Error_ErrorCode int32 - -const ( - Error_BAD_REQUEST Error_ErrorCode = 1 - Error_CONCURRENT_TRANSACTION Error_ErrorCode = 2 - Error_INTERNAL_ERROR Error_ErrorCode = 3 - Error_NEED_INDEX Error_ErrorCode = 4 - Error_TIMEOUT Error_ErrorCode = 5 - Error_PERMISSION_DENIED Error_ErrorCode = 6 - Error_BIGTABLE_ERROR Error_ErrorCode = 7 - Error_COMMITTED_BUT_STILL_APPLYING Error_ErrorCode = 8 - Error_CAPABILITY_DISABLED Error_ErrorCode = 9 - Error_TRY_ALTERNATE_BACKEND Error_ErrorCode = 10 - Error_SAFE_TIME_TOO_OLD Error_ErrorCode = 11 -) - -var Error_ErrorCode_name = map[int32]string{ - 1: "BAD_REQUEST", - 2: "CONCURRENT_TRANSACTION", - 3: "INTERNAL_ERROR", - 4: "NEED_INDEX", - 5: "TIMEOUT", - 6: "PERMISSION_DENIED", - 7: "BIGTABLE_ERROR", - 8: "COMMITTED_BUT_STILL_APPLYING", - 9: "CAPABILITY_DISABLED", - 10: "TRY_ALTERNATE_BACKEND", - 11: "SAFE_TIME_TOO_OLD", -} -var Error_ErrorCode_value = map[string]int32{ - "BAD_REQUEST": 1, - "CONCURRENT_TRANSACTION": 2, - "INTERNAL_ERROR": 3, - "NEED_INDEX": 4, - "TIMEOUT": 5, - "PERMISSION_DENIED": 6, - "BIGTABLE_ERROR": 7, - "COMMITTED_BUT_STILL_APPLYING": 8, - "CAPABILITY_DISABLED": 9, - "TRY_ALTERNATE_BACKEND": 10, - "SAFE_TIME_TOO_OLD": 11, -} - -func (x Error_ErrorCode) Enum() *Error_ErrorCode { - p := new(Error_ErrorCode) - *p = x - return p -} -func (x Error_ErrorCode) String() string { - return proto.EnumName(Error_ErrorCode_name, int32(x)) -} -func (x *Error_ErrorCode) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(Error_ErrorCode_value, data, "Error_ErrorCode") - if err != nil { - return err - } - *x = Error_ErrorCode(value) - return nil -} - -type PutRequest_AutoIdPolicy int32 - -const ( - PutRequest_CURRENT PutRequest_AutoIdPolicy = 0 - PutRequest_SEQUENTIAL PutRequest_AutoIdPolicy = 1 -) - -var PutRequest_AutoIdPolicy_name = map[int32]string{ - 0: "CURRENT", - 1: "SEQUENTIAL", -} -var PutRequest_AutoIdPolicy_value = map[string]int32{ - "CURRENT": 0, - "SEQUENTIAL": 1, -} - -func (x PutRequest_AutoIdPolicy) Enum() *PutRequest_AutoIdPolicy { - p := new(PutRequest_AutoIdPolicy) - *p = x - return p -} -func (x PutRequest_AutoIdPolicy) String() string { - return proto.EnumName(PutRequest_AutoIdPolicy_name, int32(x)) -} -func (x *PutRequest_AutoIdPolicy) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(PutRequest_AutoIdPolicy_value, data, "PutRequest_AutoIdPolicy") - if err != nil { - return err - } - *x = PutRequest_AutoIdPolicy(value) - return nil -} - -type Action struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *Action) Reset() { *m = Action{} } -func (m *Action) String() string { return proto.CompactTextString(m) } -func (*Action) ProtoMessage() {} - -type PropertyValue struct { - Int64Value *int64 `protobuf:"varint,1,opt,name=int64Value" json:"int64Value,omitempty"` - BooleanValue *bool `protobuf:"varint,2,opt,name=booleanValue" json:"booleanValue,omitempty"` - StringValue *string `protobuf:"bytes,3,opt,name=stringValue" json:"stringValue,omitempty"` - DoubleValue *float64 `protobuf:"fixed64,4,opt,name=doubleValue" json:"doubleValue,omitempty"` - Pointvalue *PropertyValue_PointValue `protobuf:"group,5,opt,name=PointValue" json:"pointvalue,omitempty"` - Uservalue *PropertyValue_UserValue `protobuf:"group,8,opt,name=UserValue" json:"uservalue,omitempty"` - Referencevalue *PropertyValue_ReferenceValue `protobuf:"group,12,opt,name=ReferenceValue" json:"referencevalue,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PropertyValue) Reset() { *m = PropertyValue{} } -func (m *PropertyValue) String() string { return proto.CompactTextString(m) } -func (*PropertyValue) ProtoMessage() {} - -func (m *PropertyValue) GetInt64Value() int64 { - if m != nil && m.Int64Value != nil { - return *m.Int64Value - } - return 0 -} - -func (m *PropertyValue) GetBooleanValue() bool { - if m != nil && m.BooleanValue != nil { - return *m.BooleanValue - } - return false -} - -func (m *PropertyValue) GetStringValue() string { - if m != nil && m.StringValue != nil { - return *m.StringValue - } - return "" -} - -func (m *PropertyValue) GetDoubleValue() float64 { - if m != nil && m.DoubleValue != nil { - return *m.DoubleValue - } - return 0 -} - -func (m *PropertyValue) GetPointvalue() *PropertyValue_PointValue { - if m != nil { - return m.Pointvalue - } - return nil -} - -func (m *PropertyValue) GetUservalue() *PropertyValue_UserValue { - if m != nil { - return m.Uservalue - } - return nil -} - -func (m *PropertyValue) GetReferencevalue() *PropertyValue_ReferenceValue { - if m != nil { - return m.Referencevalue - } - return nil -} - -type PropertyValue_PointValue struct { - X *float64 `protobuf:"fixed64,6,req,name=x" json:"x,omitempty"` - Y *float64 `protobuf:"fixed64,7,req,name=y" json:"y,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PropertyValue_PointValue) Reset() { *m = PropertyValue_PointValue{} } -func (m *PropertyValue_PointValue) String() string { return proto.CompactTextString(m) } -func (*PropertyValue_PointValue) ProtoMessage() {} - -func (m *PropertyValue_PointValue) GetX() float64 { - if m != nil && m.X != nil { - return *m.X - } - return 0 -} - -func (m *PropertyValue_PointValue) GetY() float64 { - if m != nil && m.Y != nil { - return *m.Y - } - return 0 -} - -type PropertyValue_UserValue struct { - Email *string `protobuf:"bytes,9,req,name=email" json:"email,omitempty"` - AuthDomain *string `protobuf:"bytes,10,req,name=auth_domain" json:"auth_domain,omitempty"` - Nickname *string `protobuf:"bytes,11,opt,name=nickname" json:"nickname,omitempty"` - FederatedIdentity *string `protobuf:"bytes,21,opt,name=federated_identity" json:"federated_identity,omitempty"` - FederatedProvider *string `protobuf:"bytes,22,opt,name=federated_provider" json:"federated_provider,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PropertyValue_UserValue) Reset() { *m = PropertyValue_UserValue{} } -func (m *PropertyValue_UserValue) String() string { return proto.CompactTextString(m) } -func (*PropertyValue_UserValue) ProtoMessage() {} - -func (m *PropertyValue_UserValue) GetEmail() string { - if m != nil && m.Email != nil { - return *m.Email - } - return "" -} - -func (m *PropertyValue_UserValue) GetAuthDomain() string { - if m != nil && m.AuthDomain != nil { - return *m.AuthDomain - } - return "" -} - -func (m *PropertyValue_UserValue) GetNickname() string { - if m != nil && m.Nickname != nil { - return *m.Nickname - } - return "" -} - -func (m *PropertyValue_UserValue) GetFederatedIdentity() string { - if m != nil && m.FederatedIdentity != nil { - return *m.FederatedIdentity - } - return "" -} - -func (m *PropertyValue_UserValue) GetFederatedProvider() string { - if m != nil && m.FederatedProvider != nil { - return *m.FederatedProvider - } - return "" -} - -type PropertyValue_ReferenceValue struct { - App *string `protobuf:"bytes,13,req,name=app" json:"app,omitempty"` - NameSpace *string `protobuf:"bytes,20,opt,name=name_space" json:"name_space,omitempty"` - Pathelement []*PropertyValue_ReferenceValue_PathElement `protobuf:"group,14,rep,name=PathElement" json:"pathelement,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PropertyValue_ReferenceValue) Reset() { *m = PropertyValue_ReferenceValue{} } -func (m *PropertyValue_ReferenceValue) String() string { return proto.CompactTextString(m) } -func (*PropertyValue_ReferenceValue) ProtoMessage() {} - -func (m *PropertyValue_ReferenceValue) GetApp() string { - if m != nil && m.App != nil { - return *m.App - } - return "" -} - -func (m *PropertyValue_ReferenceValue) GetNameSpace() string { - if m != nil && m.NameSpace != nil { - return *m.NameSpace - } - return "" -} - -func (m *PropertyValue_ReferenceValue) GetPathelement() []*PropertyValue_ReferenceValue_PathElement { - if m != nil { - return m.Pathelement - } - return nil -} - -type PropertyValue_ReferenceValue_PathElement struct { - Type *string `protobuf:"bytes,15,req,name=type" json:"type,omitempty"` - Id *int64 `protobuf:"varint,16,opt,name=id" json:"id,omitempty"` - Name *string `protobuf:"bytes,17,opt,name=name" json:"name,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PropertyValue_ReferenceValue_PathElement) Reset() { - *m = PropertyValue_ReferenceValue_PathElement{} -} -func (m *PropertyValue_ReferenceValue_PathElement) String() string { return proto.CompactTextString(m) } -func (*PropertyValue_ReferenceValue_PathElement) ProtoMessage() {} - -func (m *PropertyValue_ReferenceValue_PathElement) GetType() string { - if m != nil && m.Type != nil { - return *m.Type - } - return "" -} - -func (m *PropertyValue_ReferenceValue_PathElement) GetId() int64 { - if m != nil && m.Id != nil { - return *m.Id - } - return 0 -} - -func (m *PropertyValue_ReferenceValue_PathElement) GetName() string { - if m != nil && m.Name != nil { - return *m.Name - } - return "" -} - -type Property struct { - Meaning *Property_Meaning `protobuf:"varint,1,opt,name=meaning,enum=appengine.Property_Meaning,def=0" json:"meaning,omitempty"` - MeaningUri *string `protobuf:"bytes,2,opt,name=meaning_uri" json:"meaning_uri,omitempty"` - Name *string `protobuf:"bytes,3,req,name=name" json:"name,omitempty"` - Value *PropertyValue `protobuf:"bytes,5,req,name=value" json:"value,omitempty"` - Multiple *bool `protobuf:"varint,4,req,name=multiple" json:"multiple,omitempty"` - Searchable *bool `protobuf:"varint,6,opt,name=searchable,def=0" json:"searchable,omitempty"` - FtsTokenizationOption *Property_FtsTokenizationOption `protobuf:"varint,8,opt,name=fts_tokenization_option,enum=appengine.Property_FtsTokenizationOption" json:"fts_tokenization_option,omitempty"` - Locale *string `protobuf:"bytes,9,opt,name=locale,def=en" json:"locale,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Property) Reset() { *m = Property{} } -func (m *Property) String() string { return proto.CompactTextString(m) } -func (*Property) ProtoMessage() {} - -const Default_Property_Meaning Property_Meaning = Property_NO_MEANING -const Default_Property_Searchable bool = false -const Default_Property_Locale string = "en" - -func (m *Property) GetMeaning() Property_Meaning { - if m != nil && m.Meaning != nil { - return *m.Meaning - } - return Default_Property_Meaning -} - -func (m *Property) GetMeaningUri() string { - if m != nil && m.MeaningUri != nil { - return *m.MeaningUri - } - return "" -} - -func (m *Property) GetName() string { - if m != nil && m.Name != nil { - return *m.Name - } - return "" -} - -func (m *Property) GetValue() *PropertyValue { - if m != nil { - return m.Value - } - return nil -} - -func (m *Property) GetMultiple() bool { - if m != nil && m.Multiple != nil { - return *m.Multiple - } - return false -} - -func (m *Property) GetSearchable() bool { - if m != nil && m.Searchable != nil { - return *m.Searchable - } - return Default_Property_Searchable -} - -func (m *Property) GetFtsTokenizationOption() Property_FtsTokenizationOption { - if m != nil && m.FtsTokenizationOption != nil { - return *m.FtsTokenizationOption - } - return Property_HTML -} - -func (m *Property) GetLocale() string { - if m != nil && m.Locale != nil { - return *m.Locale - } - return Default_Property_Locale -} - -type Path struct { - Element []*Path_Element `protobuf:"group,1,rep,name=Element" json:"element,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Path) Reset() { *m = Path{} } -func (m *Path) String() string { return proto.CompactTextString(m) } -func (*Path) ProtoMessage() {} - -func (m *Path) GetElement() []*Path_Element { - if m != nil { - return m.Element - } - return nil -} - -type Path_Element struct { - Type *string `protobuf:"bytes,2,req,name=type" json:"type,omitempty"` - Id *int64 `protobuf:"varint,3,opt,name=id" json:"id,omitempty"` - Name *string `protobuf:"bytes,4,opt,name=name" json:"name,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Path_Element) Reset() { *m = Path_Element{} } -func (m *Path_Element) String() string { return proto.CompactTextString(m) } -func (*Path_Element) ProtoMessage() {} - -func (m *Path_Element) GetType() string { - if m != nil && m.Type != nil { - return *m.Type - } - return "" -} - -func (m *Path_Element) GetId() int64 { - if m != nil && m.Id != nil { - return *m.Id - } - return 0 -} - -func (m *Path_Element) GetName() string { - if m != nil && m.Name != nil { - return *m.Name - } - return "" -} - -type Reference struct { - App *string `protobuf:"bytes,13,req,name=app" json:"app,omitempty"` - NameSpace *string `protobuf:"bytes,20,opt,name=name_space" json:"name_space,omitempty"` - Path *Path `protobuf:"bytes,14,req,name=path" json:"path,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Reference) Reset() { *m = Reference{} } -func (m *Reference) String() string { return proto.CompactTextString(m) } -func (*Reference) ProtoMessage() {} - -func (m *Reference) GetApp() string { - if m != nil && m.App != nil { - return *m.App - } - return "" -} - -func (m *Reference) GetNameSpace() string { - if m != nil && m.NameSpace != nil { - return *m.NameSpace - } - return "" -} - -func (m *Reference) GetPath() *Path { - if m != nil { - return m.Path - } - return nil -} - -type User struct { - Email *string `protobuf:"bytes,1,req,name=email" json:"email,omitempty"` - AuthDomain *string `protobuf:"bytes,2,req,name=auth_domain" json:"auth_domain,omitempty"` - Nickname *string `protobuf:"bytes,3,opt,name=nickname" json:"nickname,omitempty"` - FederatedIdentity *string `protobuf:"bytes,6,opt,name=federated_identity" json:"federated_identity,omitempty"` - FederatedProvider *string `protobuf:"bytes,7,opt,name=federated_provider" json:"federated_provider,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *User) Reset() { *m = User{} } -func (m *User) String() string { return proto.CompactTextString(m) } -func (*User) ProtoMessage() {} - -func (m *User) GetEmail() string { - if m != nil && m.Email != nil { - return *m.Email - } - return "" -} - -func (m *User) GetAuthDomain() string { - if m != nil && m.AuthDomain != nil { - return *m.AuthDomain - } - return "" -} - -func (m *User) GetNickname() string { - if m != nil && m.Nickname != nil { - return *m.Nickname - } - return "" -} - -func (m *User) GetFederatedIdentity() string { - if m != nil && m.FederatedIdentity != nil { - return *m.FederatedIdentity - } - return "" -} - -func (m *User) GetFederatedProvider() string { - if m != nil && m.FederatedProvider != nil { - return *m.FederatedProvider - } - return "" -} - -type EntityProto struct { - Key *Reference `protobuf:"bytes,13,req,name=key" json:"key,omitempty"` - EntityGroup *Path `protobuf:"bytes,16,req,name=entity_group" json:"entity_group,omitempty"` - Owner *User `protobuf:"bytes,17,opt,name=owner" json:"owner,omitempty"` - Kind *EntityProto_Kind `protobuf:"varint,4,opt,name=kind,enum=appengine.EntityProto_Kind" json:"kind,omitempty"` - KindUri *string `protobuf:"bytes,5,opt,name=kind_uri" json:"kind_uri,omitempty"` - Property []*Property `protobuf:"bytes,14,rep,name=property" json:"property,omitempty"` - RawProperty []*Property `protobuf:"bytes,15,rep,name=raw_property" json:"raw_property,omitempty"` - Rank *int32 `protobuf:"varint,18,opt,name=rank" json:"rank,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *EntityProto) Reset() { *m = EntityProto{} } -func (m *EntityProto) String() string { return proto.CompactTextString(m) } -func (*EntityProto) ProtoMessage() {} - -func (m *EntityProto) GetKey() *Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *EntityProto) GetEntityGroup() *Path { - if m != nil { - return m.EntityGroup - } - return nil -} - -func (m *EntityProto) GetOwner() *User { - if m != nil { - return m.Owner - } - return nil -} - -func (m *EntityProto) GetKind() EntityProto_Kind { - if m != nil && m.Kind != nil { - return *m.Kind - } - return EntityProto_GD_CONTACT -} - -func (m *EntityProto) GetKindUri() string { - if m != nil && m.KindUri != nil { - return *m.KindUri - } - return "" -} - -func (m *EntityProto) GetProperty() []*Property { - if m != nil { - return m.Property - } - return nil -} - -func (m *EntityProto) GetRawProperty() []*Property { - if m != nil { - return m.RawProperty - } - return nil -} - -func (m *EntityProto) GetRank() int32 { - if m != nil && m.Rank != nil { - return *m.Rank - } - return 0 -} - -type CompositeProperty struct { - IndexId *int64 `protobuf:"varint,1,req,name=index_id" json:"index_id,omitempty"` - Value []string `protobuf:"bytes,2,rep,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompositeProperty) Reset() { *m = CompositeProperty{} } -func (m *CompositeProperty) String() string { return proto.CompactTextString(m) } -func (*CompositeProperty) ProtoMessage() {} - -func (m *CompositeProperty) GetIndexId() int64 { - if m != nil && m.IndexId != nil { - return *m.IndexId - } - return 0 -} - -func (m *CompositeProperty) GetValue() []string { - if m != nil { - return m.Value - } - return nil -} - -type Index struct { - EntityType *string `protobuf:"bytes,1,req,name=entity_type" json:"entity_type,omitempty"` - Ancestor *bool `protobuf:"varint,5,req,name=ancestor" json:"ancestor,omitempty"` - Property []*Index_Property `protobuf:"group,2,rep,name=Property" json:"property,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Index) Reset() { *m = Index{} } -func (m *Index) String() string { return proto.CompactTextString(m) } -func (*Index) ProtoMessage() {} - -func (m *Index) GetEntityType() string { - if m != nil && m.EntityType != nil { - return *m.EntityType - } - return "" -} - -func (m *Index) GetAncestor() bool { - if m != nil && m.Ancestor != nil { - return *m.Ancestor - } - return false -} - -func (m *Index) GetProperty() []*Index_Property { - if m != nil { - return m.Property - } - return nil -} - -type Index_Property struct { - Name *string `protobuf:"bytes,3,req,name=name" json:"name,omitempty"` - Direction *Index_Property_Direction `protobuf:"varint,4,opt,name=direction,enum=appengine.Index_Property_Direction,def=1" json:"direction,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Index_Property) Reset() { *m = Index_Property{} } -func (m *Index_Property) String() string { return proto.CompactTextString(m) } -func (*Index_Property) ProtoMessage() {} - -const Default_Index_Property_Direction Index_Property_Direction = Index_Property_ASCENDING - -func (m *Index_Property) GetName() string { - if m != nil && m.Name != nil { - return *m.Name - } - return "" -} - -func (m *Index_Property) GetDirection() Index_Property_Direction { - if m != nil && m.Direction != nil { - return *m.Direction - } - return Default_Index_Property_Direction -} - -type CompositeIndex struct { - AppId *string `protobuf:"bytes,1,req,name=app_id" json:"app_id,omitempty"` - Id *int64 `protobuf:"varint,2,req,name=id" json:"id,omitempty"` - Definition *Index `protobuf:"bytes,3,req,name=definition" json:"definition,omitempty"` - State *CompositeIndex_State `protobuf:"varint,4,req,name=state,enum=appengine.CompositeIndex_State" json:"state,omitempty"` - OnlyUseIfRequired *bool `protobuf:"varint,6,opt,name=only_use_if_required,def=0" json:"only_use_if_required,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompositeIndex) Reset() { *m = CompositeIndex{} } -func (m *CompositeIndex) String() string { return proto.CompactTextString(m) } -func (*CompositeIndex) ProtoMessage() {} - -const Default_CompositeIndex_OnlyUseIfRequired bool = false - -func (m *CompositeIndex) GetAppId() string { - if m != nil && m.AppId != nil { - return *m.AppId - } - return "" -} - -func (m *CompositeIndex) GetId() int64 { - if m != nil && m.Id != nil { - return *m.Id - } - return 0 -} - -func (m *CompositeIndex) GetDefinition() *Index { - if m != nil { - return m.Definition - } - return nil -} - -func (m *CompositeIndex) GetState() CompositeIndex_State { - if m != nil && m.State != nil { - return *m.State - } - return CompositeIndex_WRITE_ONLY -} - -func (m *CompositeIndex) GetOnlyUseIfRequired() bool { - if m != nil && m.OnlyUseIfRequired != nil { - return *m.OnlyUseIfRequired - } - return Default_CompositeIndex_OnlyUseIfRequired -} - -type IndexPostfix struct { - IndexValue []*IndexPostfix_IndexValue `protobuf:"bytes,1,rep,name=index_value" json:"index_value,omitempty"` - Key *Reference `protobuf:"bytes,2,opt,name=key" json:"key,omitempty"` - Before *bool `protobuf:"varint,3,opt,name=before,def=1" json:"before,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *IndexPostfix) Reset() { *m = IndexPostfix{} } -func (m *IndexPostfix) String() string { return proto.CompactTextString(m) } -func (*IndexPostfix) ProtoMessage() {} - -const Default_IndexPostfix_Before bool = true - -func (m *IndexPostfix) GetIndexValue() []*IndexPostfix_IndexValue { - if m != nil { - return m.IndexValue - } - return nil -} - -func (m *IndexPostfix) GetKey() *Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *IndexPostfix) GetBefore() bool { - if m != nil && m.Before != nil { - return *m.Before - } - return Default_IndexPostfix_Before -} - -type IndexPostfix_IndexValue struct { - PropertyName *string `protobuf:"bytes,1,req,name=property_name" json:"property_name,omitempty"` - Value *PropertyValue `protobuf:"bytes,2,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *IndexPostfix_IndexValue) Reset() { *m = IndexPostfix_IndexValue{} } -func (m *IndexPostfix_IndexValue) String() string { return proto.CompactTextString(m) } -func (*IndexPostfix_IndexValue) ProtoMessage() {} - -func (m *IndexPostfix_IndexValue) GetPropertyName() string { - if m != nil && m.PropertyName != nil { - return *m.PropertyName - } - return "" -} - -func (m *IndexPostfix_IndexValue) GetValue() *PropertyValue { - if m != nil { - return m.Value - } - return nil -} - -type IndexPosition struct { - Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"` - Before *bool `protobuf:"varint,2,opt,name=before,def=1" json:"before,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *IndexPosition) Reset() { *m = IndexPosition{} } -func (m *IndexPosition) String() string { return proto.CompactTextString(m) } -func (*IndexPosition) ProtoMessage() {} - -const Default_IndexPosition_Before bool = true - -func (m *IndexPosition) GetKey() string { - if m != nil && m.Key != nil { - return *m.Key - } - return "" -} - -func (m *IndexPosition) GetBefore() bool { - if m != nil && m.Before != nil { - return *m.Before - } - return Default_IndexPosition_Before -} - -type Snapshot struct { - Ts *int64 `protobuf:"varint,1,req,name=ts" json:"ts,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} - -func (m *Snapshot) GetTs() int64 { - if m != nil && m.Ts != nil { - return *m.Ts - } - return 0 -} - -type InternalHeader struct { - Qos *string `protobuf:"bytes,1,opt,name=qos" json:"qos,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *InternalHeader) Reset() { *m = InternalHeader{} } -func (m *InternalHeader) String() string { return proto.CompactTextString(m) } -func (*InternalHeader) ProtoMessage() {} - -func (m *InternalHeader) GetQos() string { - if m != nil && m.Qos != nil { - return *m.Qos - } - return "" -} - -type Transaction struct { - Header *InternalHeader `protobuf:"bytes,4,opt,name=header" json:"header,omitempty"` - Handle *uint64 `protobuf:"fixed64,1,req,name=handle" json:"handle,omitempty"` - App *string `protobuf:"bytes,2,req,name=app" json:"app,omitempty"` - MarkChanges *bool `protobuf:"varint,3,opt,name=mark_changes,def=0" json:"mark_changes,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Transaction) Reset() { *m = Transaction{} } -func (m *Transaction) String() string { return proto.CompactTextString(m) } -func (*Transaction) ProtoMessage() {} - -const Default_Transaction_MarkChanges bool = false - -func (m *Transaction) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *Transaction) GetHandle() uint64 { - if m != nil && m.Handle != nil { - return *m.Handle - } - return 0 -} - -func (m *Transaction) GetApp() string { - if m != nil && m.App != nil { - return *m.App - } - return "" -} - -func (m *Transaction) GetMarkChanges() bool { - if m != nil && m.MarkChanges != nil { - return *m.MarkChanges - } - return Default_Transaction_MarkChanges -} - -type Query struct { - Header *InternalHeader `protobuf:"bytes,39,opt,name=header" json:"header,omitempty"` - App *string `protobuf:"bytes,1,req,name=app" json:"app,omitempty"` - NameSpace *string `protobuf:"bytes,29,opt,name=name_space" json:"name_space,omitempty"` - Kind *string `protobuf:"bytes,3,opt,name=kind" json:"kind,omitempty"` - Ancestor *Reference `protobuf:"bytes,17,opt,name=ancestor" json:"ancestor,omitempty"` - Filter []*Query_Filter `protobuf:"group,4,rep,name=Filter" json:"filter,omitempty"` - SearchQuery *string `protobuf:"bytes,8,opt,name=search_query" json:"search_query,omitempty"` - Order []*Query_Order `protobuf:"group,9,rep,name=Order" json:"order,omitempty"` - Hint *Query_Hint `protobuf:"varint,18,opt,name=hint,enum=appengine.Query_Hint" json:"hint,omitempty"` - Count *int32 `protobuf:"varint,23,opt,name=count" json:"count,omitempty"` - Offset *int32 `protobuf:"varint,12,opt,name=offset,def=0" json:"offset,omitempty"` - Limit *int32 `protobuf:"varint,16,opt,name=limit" json:"limit,omitempty"` - CompiledCursor *CompiledCursor `protobuf:"bytes,30,opt,name=compiled_cursor" json:"compiled_cursor,omitempty"` - EndCompiledCursor *CompiledCursor `protobuf:"bytes,31,opt,name=end_compiled_cursor" json:"end_compiled_cursor,omitempty"` - CompositeIndex []*CompositeIndex `protobuf:"bytes,19,rep,name=composite_index" json:"composite_index,omitempty"` - RequirePerfectPlan *bool `protobuf:"varint,20,opt,name=require_perfect_plan,def=0" json:"require_perfect_plan,omitempty"` - KeysOnly *bool `protobuf:"varint,21,opt,name=keys_only,def=0" json:"keys_only,omitempty"` - Transaction *Transaction `protobuf:"bytes,22,opt,name=transaction" json:"transaction,omitempty"` - Compile *bool `protobuf:"varint,25,opt,name=compile,def=0" json:"compile,omitempty"` - FailoverMs *int64 `protobuf:"varint,26,opt,name=failover_ms" json:"failover_ms,omitempty"` - Strong *bool `protobuf:"varint,32,opt,name=strong" json:"strong,omitempty"` - PropertyName []string `protobuf:"bytes,33,rep,name=property_name" json:"property_name,omitempty"` - GroupByPropertyName []string `protobuf:"bytes,34,rep,name=group_by_property_name" json:"group_by_property_name,omitempty"` - Distinct *bool `protobuf:"varint,24,opt,name=distinct" json:"distinct,omitempty"` - MinSafeTimeSeconds *int64 `protobuf:"varint,35,opt,name=min_safe_time_seconds" json:"min_safe_time_seconds,omitempty"` - SafeReplicaName []string `protobuf:"bytes,36,rep,name=safe_replica_name" json:"safe_replica_name,omitempty"` - PersistOffset *bool `protobuf:"varint,37,opt,name=persist_offset,def=0" json:"persist_offset,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Query) Reset() { *m = Query{} } -func (m *Query) String() string { return proto.CompactTextString(m) } -func (*Query) ProtoMessage() {} - -const Default_Query_Offset int32 = 0 -const Default_Query_RequirePerfectPlan bool = false -const Default_Query_KeysOnly bool = false -const Default_Query_Compile bool = false -const Default_Query_PersistOffset bool = false - -func (m *Query) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *Query) GetApp() string { - if m != nil && m.App != nil { - return *m.App - } - return "" -} - -func (m *Query) GetNameSpace() string { - if m != nil && m.NameSpace != nil { - return *m.NameSpace - } - return "" -} - -func (m *Query) GetKind() string { - if m != nil && m.Kind != nil { - return *m.Kind - } - return "" -} - -func (m *Query) GetAncestor() *Reference { - if m != nil { - return m.Ancestor - } - return nil -} - -func (m *Query) GetFilter() []*Query_Filter { - if m != nil { - return m.Filter - } - return nil -} - -func (m *Query) GetSearchQuery() string { - if m != nil && m.SearchQuery != nil { - return *m.SearchQuery - } - return "" -} - -func (m *Query) GetOrder() []*Query_Order { - if m != nil { - return m.Order - } - return nil -} - -func (m *Query) GetHint() Query_Hint { - if m != nil && m.Hint != nil { - return *m.Hint - } - return Query_ORDER_FIRST -} - -func (m *Query) GetCount() int32 { - if m != nil && m.Count != nil { - return *m.Count - } - return 0 -} - -func (m *Query) GetOffset() int32 { - if m != nil && m.Offset != nil { - return *m.Offset - } - return Default_Query_Offset -} - -func (m *Query) GetLimit() int32 { - if m != nil && m.Limit != nil { - return *m.Limit - } - return 0 -} - -func (m *Query) GetCompiledCursor() *CompiledCursor { - if m != nil { - return m.CompiledCursor - } - return nil -} - -func (m *Query) GetEndCompiledCursor() *CompiledCursor { - if m != nil { - return m.EndCompiledCursor - } - return nil -} - -func (m *Query) GetCompositeIndex() []*CompositeIndex { - if m != nil { - return m.CompositeIndex - } - return nil -} - -func (m *Query) GetRequirePerfectPlan() bool { - if m != nil && m.RequirePerfectPlan != nil { - return *m.RequirePerfectPlan - } - return Default_Query_RequirePerfectPlan -} - -func (m *Query) GetKeysOnly() bool { - if m != nil && m.KeysOnly != nil { - return *m.KeysOnly - } - return Default_Query_KeysOnly -} - -func (m *Query) GetTransaction() *Transaction { - if m != nil { - return m.Transaction - } - return nil -} - -func (m *Query) GetCompile() bool { - if m != nil && m.Compile != nil { - return *m.Compile - } - return Default_Query_Compile -} - -func (m *Query) GetFailoverMs() int64 { - if m != nil && m.FailoverMs != nil { - return *m.FailoverMs - } - return 0 -} - -func (m *Query) GetStrong() bool { - if m != nil && m.Strong != nil { - return *m.Strong - } - return false -} - -func (m *Query) GetPropertyName() []string { - if m != nil { - return m.PropertyName - } - return nil -} - -func (m *Query) GetGroupByPropertyName() []string { - if m != nil { - return m.GroupByPropertyName - } - return nil -} - -func (m *Query) GetDistinct() bool { - if m != nil && m.Distinct != nil { - return *m.Distinct - } - return false -} - -func (m *Query) GetMinSafeTimeSeconds() int64 { - if m != nil && m.MinSafeTimeSeconds != nil { - return *m.MinSafeTimeSeconds - } - return 0 -} - -func (m *Query) GetSafeReplicaName() []string { - if m != nil { - return m.SafeReplicaName - } - return nil -} - -func (m *Query) GetPersistOffset() bool { - if m != nil && m.PersistOffset != nil { - return *m.PersistOffset - } - return Default_Query_PersistOffset -} - -type Query_Filter struct { - Op *Query_Filter_Operator `protobuf:"varint,6,req,name=op,enum=appengine.Query_Filter_Operator" json:"op,omitempty"` - Property []*Property `protobuf:"bytes,14,rep,name=property" json:"property,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Query_Filter) Reset() { *m = Query_Filter{} } -func (m *Query_Filter) String() string { return proto.CompactTextString(m) } -func (*Query_Filter) ProtoMessage() {} - -func (m *Query_Filter) GetOp() Query_Filter_Operator { - if m != nil && m.Op != nil { - return *m.Op - } - return Query_Filter_LESS_THAN -} - -func (m *Query_Filter) GetProperty() []*Property { - if m != nil { - return m.Property - } - return nil -} - -type Query_Order struct { - Property *string `protobuf:"bytes,10,req,name=property" json:"property,omitempty"` - Direction *Query_Order_Direction `protobuf:"varint,11,opt,name=direction,enum=appengine.Query_Order_Direction,def=1" json:"direction,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Query_Order) Reset() { *m = Query_Order{} } -func (m *Query_Order) String() string { return proto.CompactTextString(m) } -func (*Query_Order) ProtoMessage() {} - -const Default_Query_Order_Direction Query_Order_Direction = Query_Order_ASCENDING - -func (m *Query_Order) GetProperty() string { - if m != nil && m.Property != nil { - return *m.Property - } - return "" -} - -func (m *Query_Order) GetDirection() Query_Order_Direction { - if m != nil && m.Direction != nil { - return *m.Direction - } - return Default_Query_Order_Direction -} - -type CompiledQuery struct { - Primaryscan *CompiledQuery_PrimaryScan `protobuf:"group,1,req,name=PrimaryScan" json:"primaryscan,omitempty"` - Mergejoinscan []*CompiledQuery_MergeJoinScan `protobuf:"group,7,rep,name=MergeJoinScan" json:"mergejoinscan,omitempty"` - IndexDef *Index `protobuf:"bytes,21,opt,name=index_def" json:"index_def,omitempty"` - Offset *int32 `protobuf:"varint,10,opt,name=offset,def=0" json:"offset,omitempty"` - Limit *int32 `protobuf:"varint,11,opt,name=limit" json:"limit,omitempty"` - KeysOnly *bool `protobuf:"varint,12,req,name=keys_only" json:"keys_only,omitempty"` - PropertyName []string `protobuf:"bytes,24,rep,name=property_name" json:"property_name,omitempty"` - DistinctInfixSize *int32 `protobuf:"varint,25,opt,name=distinct_infix_size" json:"distinct_infix_size,omitempty"` - Entityfilter *CompiledQuery_EntityFilter `protobuf:"group,13,opt,name=EntityFilter" json:"entityfilter,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledQuery) Reset() { *m = CompiledQuery{} } -func (m *CompiledQuery) String() string { return proto.CompactTextString(m) } -func (*CompiledQuery) ProtoMessage() {} - -const Default_CompiledQuery_Offset int32 = 0 - -func (m *CompiledQuery) GetPrimaryscan() *CompiledQuery_PrimaryScan { - if m != nil { - return m.Primaryscan - } - return nil -} - -func (m *CompiledQuery) GetMergejoinscan() []*CompiledQuery_MergeJoinScan { - if m != nil { - return m.Mergejoinscan - } - return nil -} - -func (m *CompiledQuery) GetIndexDef() *Index { - if m != nil { - return m.IndexDef - } - return nil -} - -func (m *CompiledQuery) GetOffset() int32 { - if m != nil && m.Offset != nil { - return *m.Offset - } - return Default_CompiledQuery_Offset -} - -func (m *CompiledQuery) GetLimit() int32 { - if m != nil && m.Limit != nil { - return *m.Limit - } - return 0 -} - -func (m *CompiledQuery) GetKeysOnly() bool { - if m != nil && m.KeysOnly != nil { - return *m.KeysOnly - } - return false -} - -func (m *CompiledQuery) GetPropertyName() []string { - if m != nil { - return m.PropertyName - } - return nil -} - -func (m *CompiledQuery) GetDistinctInfixSize() int32 { - if m != nil && m.DistinctInfixSize != nil { - return *m.DistinctInfixSize - } - return 0 -} - -func (m *CompiledQuery) GetEntityfilter() *CompiledQuery_EntityFilter { - if m != nil { - return m.Entityfilter - } - return nil -} - -type CompiledQuery_PrimaryScan struct { - IndexName *string `protobuf:"bytes,2,opt,name=index_name" json:"index_name,omitempty"` - StartKey *string `protobuf:"bytes,3,opt,name=start_key" json:"start_key,omitempty"` - StartInclusive *bool `protobuf:"varint,4,opt,name=start_inclusive" json:"start_inclusive,omitempty"` - EndKey *string `protobuf:"bytes,5,opt,name=end_key" json:"end_key,omitempty"` - EndInclusive *bool `protobuf:"varint,6,opt,name=end_inclusive" json:"end_inclusive,omitempty"` - StartPostfixValue []string `protobuf:"bytes,22,rep,name=start_postfix_value" json:"start_postfix_value,omitempty"` - EndPostfixValue []string `protobuf:"bytes,23,rep,name=end_postfix_value" json:"end_postfix_value,omitempty"` - EndUnappliedLogTimestampUs *int64 `protobuf:"varint,19,opt,name=end_unapplied_log_timestamp_us" json:"end_unapplied_log_timestamp_us,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledQuery_PrimaryScan) Reset() { *m = CompiledQuery_PrimaryScan{} } -func (m *CompiledQuery_PrimaryScan) String() string { return proto.CompactTextString(m) } -func (*CompiledQuery_PrimaryScan) ProtoMessage() {} - -func (m *CompiledQuery_PrimaryScan) GetIndexName() string { - if m != nil && m.IndexName != nil { - return *m.IndexName - } - return "" -} - -func (m *CompiledQuery_PrimaryScan) GetStartKey() string { - if m != nil && m.StartKey != nil { - return *m.StartKey - } - return "" -} - -func (m *CompiledQuery_PrimaryScan) GetStartInclusive() bool { - if m != nil && m.StartInclusive != nil { - return *m.StartInclusive - } - return false -} - -func (m *CompiledQuery_PrimaryScan) GetEndKey() string { - if m != nil && m.EndKey != nil { - return *m.EndKey - } - return "" -} - -func (m *CompiledQuery_PrimaryScan) GetEndInclusive() bool { - if m != nil && m.EndInclusive != nil { - return *m.EndInclusive - } - return false -} - -func (m *CompiledQuery_PrimaryScan) GetStartPostfixValue() []string { - if m != nil { - return m.StartPostfixValue - } - return nil -} - -func (m *CompiledQuery_PrimaryScan) GetEndPostfixValue() []string { - if m != nil { - return m.EndPostfixValue - } - return nil -} - -func (m *CompiledQuery_PrimaryScan) GetEndUnappliedLogTimestampUs() int64 { - if m != nil && m.EndUnappliedLogTimestampUs != nil { - return *m.EndUnappliedLogTimestampUs - } - return 0 -} - -type CompiledQuery_MergeJoinScan struct { - IndexName *string `protobuf:"bytes,8,req,name=index_name" json:"index_name,omitempty"` - PrefixValue []string `protobuf:"bytes,9,rep,name=prefix_value" json:"prefix_value,omitempty"` - ValuePrefix *bool `protobuf:"varint,20,opt,name=value_prefix,def=0" json:"value_prefix,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledQuery_MergeJoinScan) Reset() { *m = CompiledQuery_MergeJoinScan{} } -func (m *CompiledQuery_MergeJoinScan) String() string { return proto.CompactTextString(m) } -func (*CompiledQuery_MergeJoinScan) ProtoMessage() {} - -const Default_CompiledQuery_MergeJoinScan_ValuePrefix bool = false - -func (m *CompiledQuery_MergeJoinScan) GetIndexName() string { - if m != nil && m.IndexName != nil { - return *m.IndexName - } - return "" -} - -func (m *CompiledQuery_MergeJoinScan) GetPrefixValue() []string { - if m != nil { - return m.PrefixValue - } - return nil -} - -func (m *CompiledQuery_MergeJoinScan) GetValuePrefix() bool { - if m != nil && m.ValuePrefix != nil { - return *m.ValuePrefix - } - return Default_CompiledQuery_MergeJoinScan_ValuePrefix -} - -type CompiledQuery_EntityFilter struct { - Distinct *bool `protobuf:"varint,14,opt,name=distinct,def=0" json:"distinct,omitempty"` - Kind *string `protobuf:"bytes,17,opt,name=kind" json:"kind,omitempty"` - Ancestor *Reference `protobuf:"bytes,18,opt,name=ancestor" json:"ancestor,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledQuery_EntityFilter) Reset() { *m = CompiledQuery_EntityFilter{} } -func (m *CompiledQuery_EntityFilter) String() string { return proto.CompactTextString(m) } -func (*CompiledQuery_EntityFilter) ProtoMessage() {} - -const Default_CompiledQuery_EntityFilter_Distinct bool = false - -func (m *CompiledQuery_EntityFilter) GetDistinct() bool { - if m != nil && m.Distinct != nil { - return *m.Distinct - } - return Default_CompiledQuery_EntityFilter_Distinct -} - -func (m *CompiledQuery_EntityFilter) GetKind() string { - if m != nil && m.Kind != nil { - return *m.Kind - } - return "" -} - -func (m *CompiledQuery_EntityFilter) GetAncestor() *Reference { - if m != nil { - return m.Ancestor - } - return nil -} - -type CompiledCursor struct { - Position *CompiledCursor_Position `protobuf:"group,2,opt,name=Position" json:"position,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledCursor) Reset() { *m = CompiledCursor{} } -func (m *CompiledCursor) String() string { return proto.CompactTextString(m) } -func (*CompiledCursor) ProtoMessage() {} - -func (m *CompiledCursor) GetPosition() *CompiledCursor_Position { - if m != nil { - return m.Position - } - return nil -} - -type CompiledCursor_Position struct { - StartKey *string `protobuf:"bytes,27,opt,name=start_key" json:"start_key,omitempty"` - Indexvalue []*CompiledCursor_Position_IndexValue `protobuf:"group,29,rep,name=IndexValue" json:"indexvalue,omitempty"` - Key *Reference `protobuf:"bytes,32,opt,name=key" json:"key,omitempty"` - StartInclusive *bool `protobuf:"varint,28,opt,name=start_inclusive,def=1" json:"start_inclusive,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledCursor_Position) Reset() { *m = CompiledCursor_Position{} } -func (m *CompiledCursor_Position) String() string { return proto.CompactTextString(m) } -func (*CompiledCursor_Position) ProtoMessage() {} - -const Default_CompiledCursor_Position_StartInclusive bool = true - -func (m *CompiledCursor_Position) GetStartKey() string { - if m != nil && m.StartKey != nil { - return *m.StartKey - } - return "" -} - -func (m *CompiledCursor_Position) GetIndexvalue() []*CompiledCursor_Position_IndexValue { - if m != nil { - return m.Indexvalue - } - return nil -} - -func (m *CompiledCursor_Position) GetKey() *Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *CompiledCursor_Position) GetStartInclusive() bool { - if m != nil && m.StartInclusive != nil { - return *m.StartInclusive - } - return Default_CompiledCursor_Position_StartInclusive -} - -type CompiledCursor_Position_IndexValue struct { - Property *string `protobuf:"bytes,30,opt,name=property" json:"property,omitempty"` - Value *PropertyValue `protobuf:"bytes,31,req,name=value" json:"value,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompiledCursor_Position_IndexValue) Reset() { *m = CompiledCursor_Position_IndexValue{} } -func (m *CompiledCursor_Position_IndexValue) String() string { return proto.CompactTextString(m) } -func (*CompiledCursor_Position_IndexValue) ProtoMessage() {} - -func (m *CompiledCursor_Position_IndexValue) GetProperty() string { - if m != nil && m.Property != nil { - return *m.Property - } - return "" -} - -func (m *CompiledCursor_Position_IndexValue) GetValue() *PropertyValue { - if m != nil { - return m.Value - } - return nil -} - -type Cursor struct { - Cursor *uint64 `protobuf:"fixed64,1,req,name=cursor" json:"cursor,omitempty"` - App *string `protobuf:"bytes,2,opt,name=app" json:"app,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Cursor) Reset() { *m = Cursor{} } -func (m *Cursor) String() string { return proto.CompactTextString(m) } -func (*Cursor) ProtoMessage() {} - -func (m *Cursor) GetCursor() uint64 { - if m != nil && m.Cursor != nil { - return *m.Cursor - } - return 0 -} - -func (m *Cursor) GetApp() string { - if m != nil && m.App != nil { - return *m.App - } - return "" -} - -type Error struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *Error) Reset() { *m = Error{} } -func (m *Error) String() string { return proto.CompactTextString(m) } -func (*Error) ProtoMessage() {} - -type Cost struct { - IndexWrites *int32 `protobuf:"varint,1,opt,name=index_writes" json:"index_writes,omitempty"` - IndexWriteBytes *int32 `protobuf:"varint,2,opt,name=index_write_bytes" json:"index_write_bytes,omitempty"` - EntityWrites *int32 `protobuf:"varint,3,opt,name=entity_writes" json:"entity_writes,omitempty"` - EntityWriteBytes *int32 `protobuf:"varint,4,opt,name=entity_write_bytes" json:"entity_write_bytes,omitempty"` - Commitcost *Cost_CommitCost `protobuf:"group,5,opt,name=CommitCost" json:"commitcost,omitempty"` - ApproximateStorageDelta *int32 `protobuf:"varint,8,opt,name=approximate_storage_delta" json:"approximate_storage_delta,omitempty"` - IdSequenceUpdates *int32 `protobuf:"varint,9,opt,name=id_sequence_updates" json:"id_sequence_updates,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Cost) Reset() { *m = Cost{} } -func (m *Cost) String() string { return proto.CompactTextString(m) } -func (*Cost) ProtoMessage() {} - -func (m *Cost) GetIndexWrites() int32 { - if m != nil && m.IndexWrites != nil { - return *m.IndexWrites - } - return 0 -} - -func (m *Cost) GetIndexWriteBytes() int32 { - if m != nil && m.IndexWriteBytes != nil { - return *m.IndexWriteBytes - } - return 0 -} - -func (m *Cost) GetEntityWrites() int32 { - if m != nil && m.EntityWrites != nil { - return *m.EntityWrites - } - return 0 -} - -func (m *Cost) GetEntityWriteBytes() int32 { - if m != nil && m.EntityWriteBytes != nil { - return *m.EntityWriteBytes - } - return 0 -} - -func (m *Cost) GetCommitcost() *Cost_CommitCost { - if m != nil { - return m.Commitcost - } - return nil -} - -func (m *Cost) GetApproximateStorageDelta() int32 { - if m != nil && m.ApproximateStorageDelta != nil { - return *m.ApproximateStorageDelta - } - return 0 -} - -func (m *Cost) GetIdSequenceUpdates() int32 { - if m != nil && m.IdSequenceUpdates != nil { - return *m.IdSequenceUpdates - } - return 0 -} - -type Cost_CommitCost struct { - RequestedEntityPuts *int32 `protobuf:"varint,6,opt,name=requested_entity_puts" json:"requested_entity_puts,omitempty"` - RequestedEntityDeletes *int32 `protobuf:"varint,7,opt,name=requested_entity_deletes" json:"requested_entity_deletes,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Cost_CommitCost) Reset() { *m = Cost_CommitCost{} } -func (m *Cost_CommitCost) String() string { return proto.CompactTextString(m) } -func (*Cost_CommitCost) ProtoMessage() {} - -func (m *Cost_CommitCost) GetRequestedEntityPuts() int32 { - if m != nil && m.RequestedEntityPuts != nil { - return *m.RequestedEntityPuts - } - return 0 -} - -func (m *Cost_CommitCost) GetRequestedEntityDeletes() int32 { - if m != nil && m.RequestedEntityDeletes != nil { - return *m.RequestedEntityDeletes - } - return 0 -} - -type GetRequest struct { - Header *InternalHeader `protobuf:"bytes,6,opt,name=header" json:"header,omitempty"` - Key []*Reference `protobuf:"bytes,1,rep,name=key" json:"key,omitempty"` - Transaction *Transaction `protobuf:"bytes,2,opt,name=transaction" json:"transaction,omitempty"` - FailoverMs *int64 `protobuf:"varint,3,opt,name=failover_ms" json:"failover_ms,omitempty"` - Strong *bool `protobuf:"varint,4,opt,name=strong" json:"strong,omitempty"` - AllowDeferred *bool `protobuf:"varint,5,opt,name=allow_deferred,def=0" json:"allow_deferred,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetRequest) Reset() { *m = GetRequest{} } -func (m *GetRequest) String() string { return proto.CompactTextString(m) } -func (*GetRequest) ProtoMessage() {} - -const Default_GetRequest_AllowDeferred bool = false - -func (m *GetRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *GetRequest) GetKey() []*Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *GetRequest) GetTransaction() *Transaction { - if m != nil { - return m.Transaction - } - return nil -} - -func (m *GetRequest) GetFailoverMs() int64 { - if m != nil && m.FailoverMs != nil { - return *m.FailoverMs - } - return 0 -} - -func (m *GetRequest) GetStrong() bool { - if m != nil && m.Strong != nil { - return *m.Strong - } - return false -} - -func (m *GetRequest) GetAllowDeferred() bool { - if m != nil && m.AllowDeferred != nil { - return *m.AllowDeferred - } - return Default_GetRequest_AllowDeferred -} - -type GetResponse struct { - Entity []*GetResponse_Entity `protobuf:"group,1,rep,name=Entity" json:"entity,omitempty"` - Deferred []*Reference `protobuf:"bytes,5,rep,name=deferred" json:"deferred,omitempty"` - InOrder *bool `protobuf:"varint,6,opt,name=in_order,def=1" json:"in_order,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetResponse) Reset() { *m = GetResponse{} } -func (m *GetResponse) String() string { return proto.CompactTextString(m) } -func (*GetResponse) ProtoMessage() {} - -const Default_GetResponse_InOrder bool = true - -func (m *GetResponse) GetEntity() []*GetResponse_Entity { - if m != nil { - return m.Entity - } - return nil -} - -func (m *GetResponse) GetDeferred() []*Reference { - if m != nil { - return m.Deferred - } - return nil -} - -func (m *GetResponse) GetInOrder() bool { - if m != nil && m.InOrder != nil { - return *m.InOrder - } - return Default_GetResponse_InOrder -} - -type GetResponse_Entity struct { - Entity *EntityProto `protobuf:"bytes,2,opt,name=entity" json:"entity,omitempty"` - Key *Reference `protobuf:"bytes,4,opt,name=key" json:"key,omitempty"` - Version *int64 `protobuf:"varint,3,opt,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetResponse_Entity) Reset() { *m = GetResponse_Entity{} } -func (m *GetResponse_Entity) String() string { return proto.CompactTextString(m) } -func (*GetResponse_Entity) ProtoMessage() {} - -func (m *GetResponse_Entity) GetEntity() *EntityProto { - if m != nil { - return m.Entity - } - return nil -} - -func (m *GetResponse_Entity) GetKey() *Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *GetResponse_Entity) GetVersion() int64 { - if m != nil && m.Version != nil { - return *m.Version - } - return 0 -} - -type PutRequest struct { - Header *InternalHeader `protobuf:"bytes,11,opt,name=header" json:"header,omitempty"` - Entity []*EntityProto `protobuf:"bytes,1,rep,name=entity" json:"entity,omitempty"` - Transaction *Transaction `protobuf:"bytes,2,opt,name=transaction" json:"transaction,omitempty"` - CompositeIndex []*CompositeIndex `protobuf:"bytes,3,rep,name=composite_index" json:"composite_index,omitempty"` - Trusted *bool `protobuf:"varint,4,opt,name=trusted,def=0" json:"trusted,omitempty"` - Force *bool `protobuf:"varint,7,opt,name=force,def=0" json:"force,omitempty"` - MarkChanges *bool `protobuf:"varint,8,opt,name=mark_changes,def=0" json:"mark_changes,omitempty"` - Snapshot []*Snapshot `protobuf:"bytes,9,rep,name=snapshot" json:"snapshot,omitempty"` - AutoIdPolicy *PutRequest_AutoIdPolicy `protobuf:"varint,10,opt,name=auto_id_policy,enum=appengine.PutRequest_AutoIdPolicy,def=0" json:"auto_id_policy,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PutRequest) Reset() { *m = PutRequest{} } -func (m *PutRequest) String() string { return proto.CompactTextString(m) } -func (*PutRequest) ProtoMessage() {} - -const Default_PutRequest_Trusted bool = false -const Default_PutRequest_Force bool = false -const Default_PutRequest_MarkChanges bool = false -const Default_PutRequest_AutoIdPolicy PutRequest_AutoIdPolicy = PutRequest_CURRENT - -func (m *PutRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *PutRequest) GetEntity() []*EntityProto { - if m != nil { - return m.Entity - } - return nil -} - -func (m *PutRequest) GetTransaction() *Transaction { - if m != nil { - return m.Transaction - } - return nil -} - -func (m *PutRequest) GetCompositeIndex() []*CompositeIndex { - if m != nil { - return m.CompositeIndex - } - return nil -} - -func (m *PutRequest) GetTrusted() bool { - if m != nil && m.Trusted != nil { - return *m.Trusted - } - return Default_PutRequest_Trusted -} - -func (m *PutRequest) GetForce() bool { - if m != nil && m.Force != nil { - return *m.Force - } - return Default_PutRequest_Force -} - -func (m *PutRequest) GetMarkChanges() bool { - if m != nil && m.MarkChanges != nil { - return *m.MarkChanges - } - return Default_PutRequest_MarkChanges -} - -func (m *PutRequest) GetSnapshot() []*Snapshot { - if m != nil { - return m.Snapshot - } - return nil -} - -func (m *PutRequest) GetAutoIdPolicy() PutRequest_AutoIdPolicy { - if m != nil && m.AutoIdPolicy != nil { - return *m.AutoIdPolicy - } - return Default_PutRequest_AutoIdPolicy -} - -type PutResponse struct { - Key []*Reference `protobuf:"bytes,1,rep,name=key" json:"key,omitempty"` - Cost *Cost `protobuf:"bytes,2,opt,name=cost" json:"cost,omitempty"` - Version []int64 `protobuf:"varint,3,rep,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *PutResponse) Reset() { *m = PutResponse{} } -func (m *PutResponse) String() string { return proto.CompactTextString(m) } -func (*PutResponse) ProtoMessage() {} - -func (m *PutResponse) GetKey() []*Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *PutResponse) GetCost() *Cost { - if m != nil { - return m.Cost - } - return nil -} - -func (m *PutResponse) GetVersion() []int64 { - if m != nil { - return m.Version - } - return nil -} - -type TouchRequest struct { - Header *InternalHeader `protobuf:"bytes,10,opt,name=header" json:"header,omitempty"` - Key []*Reference `protobuf:"bytes,1,rep,name=key" json:"key,omitempty"` - CompositeIndex []*CompositeIndex `protobuf:"bytes,2,rep,name=composite_index" json:"composite_index,omitempty"` - Force *bool `protobuf:"varint,3,opt,name=force,def=0" json:"force,omitempty"` - Snapshot []*Snapshot `protobuf:"bytes,9,rep,name=snapshot" json:"snapshot,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *TouchRequest) Reset() { *m = TouchRequest{} } -func (m *TouchRequest) String() string { return proto.CompactTextString(m) } -func (*TouchRequest) ProtoMessage() {} - -const Default_TouchRequest_Force bool = false - -func (m *TouchRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *TouchRequest) GetKey() []*Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *TouchRequest) GetCompositeIndex() []*CompositeIndex { - if m != nil { - return m.CompositeIndex - } - return nil -} - -func (m *TouchRequest) GetForce() bool { - if m != nil && m.Force != nil { - return *m.Force - } - return Default_TouchRequest_Force -} - -func (m *TouchRequest) GetSnapshot() []*Snapshot { - if m != nil { - return m.Snapshot - } - return nil -} - -type TouchResponse struct { - Cost *Cost `protobuf:"bytes,1,opt,name=cost" json:"cost,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *TouchResponse) Reset() { *m = TouchResponse{} } -func (m *TouchResponse) String() string { return proto.CompactTextString(m) } -func (*TouchResponse) ProtoMessage() {} - -func (m *TouchResponse) GetCost() *Cost { - if m != nil { - return m.Cost - } - return nil -} - -type DeleteRequest struct { - Header *InternalHeader `protobuf:"bytes,10,opt,name=header" json:"header,omitempty"` - Key []*Reference `protobuf:"bytes,6,rep,name=key" json:"key,omitempty"` - Transaction *Transaction `protobuf:"bytes,5,opt,name=transaction" json:"transaction,omitempty"` - Trusted *bool `protobuf:"varint,4,opt,name=trusted,def=0" json:"trusted,omitempty"` - Force *bool `protobuf:"varint,7,opt,name=force,def=0" json:"force,omitempty"` - MarkChanges *bool `protobuf:"varint,8,opt,name=mark_changes,def=0" json:"mark_changes,omitempty"` - Snapshot []*Snapshot `protobuf:"bytes,9,rep,name=snapshot" json:"snapshot,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } -func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } -func (*DeleteRequest) ProtoMessage() {} - -const Default_DeleteRequest_Trusted bool = false -const Default_DeleteRequest_Force bool = false -const Default_DeleteRequest_MarkChanges bool = false - -func (m *DeleteRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *DeleteRequest) GetKey() []*Reference { - if m != nil { - return m.Key - } - return nil -} - -func (m *DeleteRequest) GetTransaction() *Transaction { - if m != nil { - return m.Transaction - } - return nil -} - -func (m *DeleteRequest) GetTrusted() bool { - if m != nil && m.Trusted != nil { - return *m.Trusted - } - return Default_DeleteRequest_Trusted -} - -func (m *DeleteRequest) GetForce() bool { - if m != nil && m.Force != nil { - return *m.Force - } - return Default_DeleteRequest_Force -} - -func (m *DeleteRequest) GetMarkChanges() bool { - if m != nil && m.MarkChanges != nil { - return *m.MarkChanges - } - return Default_DeleteRequest_MarkChanges -} - -func (m *DeleteRequest) GetSnapshot() []*Snapshot { - if m != nil { - return m.Snapshot - } - return nil -} - -type DeleteResponse struct { - Cost *Cost `protobuf:"bytes,1,opt,name=cost" json:"cost,omitempty"` - Version []int64 `protobuf:"varint,3,rep,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } -func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } -func (*DeleteResponse) ProtoMessage() {} - -func (m *DeleteResponse) GetCost() *Cost { - if m != nil { - return m.Cost - } - return nil -} - -func (m *DeleteResponse) GetVersion() []int64 { - if m != nil { - return m.Version - } - return nil -} - -type NextRequest struct { - Header *InternalHeader `protobuf:"bytes,5,opt,name=header" json:"header,omitempty"` - Cursor *Cursor `protobuf:"bytes,1,req,name=cursor" json:"cursor,omitempty"` - Count *int32 `protobuf:"varint,2,opt,name=count" json:"count,omitempty"` - Offset *int32 `protobuf:"varint,4,opt,name=offset,def=0" json:"offset,omitempty"` - Compile *bool `protobuf:"varint,3,opt,name=compile,def=0" json:"compile,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *NextRequest) Reset() { *m = NextRequest{} } -func (m *NextRequest) String() string { return proto.CompactTextString(m) } -func (*NextRequest) ProtoMessage() {} - -const Default_NextRequest_Offset int32 = 0 -const Default_NextRequest_Compile bool = false - -func (m *NextRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *NextRequest) GetCursor() *Cursor { - if m != nil { - return m.Cursor - } - return nil -} - -func (m *NextRequest) GetCount() int32 { - if m != nil && m.Count != nil { - return *m.Count - } - return 0 -} - -func (m *NextRequest) GetOffset() int32 { - if m != nil && m.Offset != nil { - return *m.Offset - } - return Default_NextRequest_Offset -} - -func (m *NextRequest) GetCompile() bool { - if m != nil && m.Compile != nil { - return *m.Compile - } - return Default_NextRequest_Compile -} - -type QueryResult struct { - Cursor *Cursor `protobuf:"bytes,1,opt,name=cursor" json:"cursor,omitempty"` - Result []*EntityProto `protobuf:"bytes,2,rep,name=result" json:"result,omitempty"` - SkippedResults *int32 `protobuf:"varint,7,opt,name=skipped_results" json:"skipped_results,omitempty"` - MoreResults *bool `protobuf:"varint,3,req,name=more_results" json:"more_results,omitempty"` - KeysOnly *bool `protobuf:"varint,4,opt,name=keys_only" json:"keys_only,omitempty"` - IndexOnly *bool `protobuf:"varint,9,opt,name=index_only" json:"index_only,omitempty"` - SmallOps *bool `protobuf:"varint,10,opt,name=small_ops" json:"small_ops,omitempty"` - CompiledQuery *CompiledQuery `protobuf:"bytes,5,opt,name=compiled_query" json:"compiled_query,omitempty"` - CompiledCursor *CompiledCursor `protobuf:"bytes,6,opt,name=compiled_cursor" json:"compiled_cursor,omitempty"` - Index []*CompositeIndex `protobuf:"bytes,8,rep,name=index" json:"index,omitempty"` - Version []int64 `protobuf:"varint,11,rep,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *QueryResult) Reset() { *m = QueryResult{} } -func (m *QueryResult) String() string { return proto.CompactTextString(m) } -func (*QueryResult) ProtoMessage() {} - -func (m *QueryResult) GetCursor() *Cursor { - if m != nil { - return m.Cursor - } - return nil -} - -func (m *QueryResult) GetResult() []*EntityProto { - if m != nil { - return m.Result - } - return nil -} - -func (m *QueryResult) GetSkippedResults() int32 { - if m != nil && m.SkippedResults != nil { - return *m.SkippedResults - } - return 0 -} - -func (m *QueryResult) GetMoreResults() bool { - if m != nil && m.MoreResults != nil { - return *m.MoreResults - } - return false -} - -func (m *QueryResult) GetKeysOnly() bool { - if m != nil && m.KeysOnly != nil { - return *m.KeysOnly - } - return false -} - -func (m *QueryResult) GetIndexOnly() bool { - if m != nil && m.IndexOnly != nil { - return *m.IndexOnly - } - return false -} - -func (m *QueryResult) GetSmallOps() bool { - if m != nil && m.SmallOps != nil { - return *m.SmallOps - } - return false -} - -func (m *QueryResult) GetCompiledQuery() *CompiledQuery { - if m != nil { - return m.CompiledQuery - } - return nil -} - -func (m *QueryResult) GetCompiledCursor() *CompiledCursor { - if m != nil { - return m.CompiledCursor - } - return nil -} - -func (m *QueryResult) GetIndex() []*CompositeIndex { - if m != nil { - return m.Index - } - return nil -} - -func (m *QueryResult) GetVersion() []int64 { - if m != nil { - return m.Version - } - return nil -} - -type AllocateIdsRequest struct { - Header *InternalHeader `protobuf:"bytes,4,opt,name=header" json:"header,omitempty"` - ModelKey *Reference `protobuf:"bytes,1,opt,name=model_key" json:"model_key,omitempty"` - Size *int64 `protobuf:"varint,2,opt,name=size" json:"size,omitempty"` - Max *int64 `protobuf:"varint,3,opt,name=max" json:"max,omitempty"` - Reserve []*Reference `protobuf:"bytes,5,rep,name=reserve" json:"reserve,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *AllocateIdsRequest) Reset() { *m = AllocateIdsRequest{} } -func (m *AllocateIdsRequest) String() string { return proto.CompactTextString(m) } -func (*AllocateIdsRequest) ProtoMessage() {} - -func (m *AllocateIdsRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AllocateIdsRequest) GetModelKey() *Reference { - if m != nil { - return m.ModelKey - } - return nil -} - -func (m *AllocateIdsRequest) GetSize() int64 { - if m != nil && m.Size != nil { - return *m.Size - } - return 0 -} - -func (m *AllocateIdsRequest) GetMax() int64 { - if m != nil && m.Max != nil { - return *m.Max - } - return 0 -} - -func (m *AllocateIdsRequest) GetReserve() []*Reference { - if m != nil { - return m.Reserve - } - return nil -} - -type AllocateIdsResponse struct { - Start *int64 `protobuf:"varint,1,req,name=start" json:"start,omitempty"` - End *int64 `protobuf:"varint,2,req,name=end" json:"end,omitempty"` - Cost *Cost `protobuf:"bytes,3,opt,name=cost" json:"cost,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *AllocateIdsResponse) Reset() { *m = AllocateIdsResponse{} } -func (m *AllocateIdsResponse) String() string { return proto.CompactTextString(m) } -func (*AllocateIdsResponse) ProtoMessage() {} - -func (m *AllocateIdsResponse) GetStart() int64 { - if m != nil && m.Start != nil { - return *m.Start - } - return 0 -} - -func (m *AllocateIdsResponse) GetEnd() int64 { - if m != nil && m.End != nil { - return *m.End - } - return 0 -} - -func (m *AllocateIdsResponse) GetCost() *Cost { - if m != nil { - return m.Cost - } - return nil -} - -type CompositeIndices struct { - Index []*CompositeIndex `protobuf:"bytes,1,rep,name=index" json:"index,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CompositeIndices) Reset() { *m = CompositeIndices{} } -func (m *CompositeIndices) String() string { return proto.CompactTextString(m) } -func (*CompositeIndices) ProtoMessage() {} - -func (m *CompositeIndices) GetIndex() []*CompositeIndex { - if m != nil { - return m.Index - } - return nil -} - -type AddActionsRequest struct { - Header *InternalHeader `protobuf:"bytes,3,opt,name=header" json:"header,omitempty"` - Transaction *Transaction `protobuf:"bytes,1,req,name=transaction" json:"transaction,omitempty"` - Action []*Action `protobuf:"bytes,2,rep,name=action" json:"action,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *AddActionsRequest) Reset() { *m = AddActionsRequest{} } -func (m *AddActionsRequest) String() string { return proto.CompactTextString(m) } -func (*AddActionsRequest) ProtoMessage() {} - -func (m *AddActionsRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *AddActionsRequest) GetTransaction() *Transaction { - if m != nil { - return m.Transaction - } - return nil -} - -func (m *AddActionsRequest) GetAction() []*Action { - if m != nil { - return m.Action - } - return nil -} - -type AddActionsResponse struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *AddActionsResponse) Reset() { *m = AddActionsResponse{} } -func (m *AddActionsResponse) String() string { return proto.CompactTextString(m) } -func (*AddActionsResponse) ProtoMessage() {} - -type BeginTransactionRequest struct { - Header *InternalHeader `protobuf:"bytes,3,opt,name=header" json:"header,omitempty"` - App *string `protobuf:"bytes,1,req,name=app" json:"app,omitempty"` - AllowMultipleEg *bool `protobuf:"varint,2,opt,name=allow_multiple_eg,def=0" json:"allow_multiple_eg,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *BeginTransactionRequest) Reset() { *m = BeginTransactionRequest{} } -func (m *BeginTransactionRequest) String() string { return proto.CompactTextString(m) } -func (*BeginTransactionRequest) ProtoMessage() {} - -const Default_BeginTransactionRequest_AllowMultipleEg bool = false - -func (m *BeginTransactionRequest) GetHeader() *InternalHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *BeginTransactionRequest) GetApp() string { - if m != nil && m.App != nil { - return *m.App - } - return "" -} - -func (m *BeginTransactionRequest) GetAllowMultipleEg() bool { - if m != nil && m.AllowMultipleEg != nil { - return *m.AllowMultipleEg - } - return Default_BeginTransactionRequest_AllowMultipleEg -} - -type CommitResponse struct { - Cost *Cost `protobuf:"bytes,1,opt,name=cost" json:"cost,omitempty"` - Version []*CommitResponse_Version `protobuf:"group,3,rep,name=Version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CommitResponse) Reset() { *m = CommitResponse{} } -func (m *CommitResponse) String() string { return proto.CompactTextString(m) } -func (*CommitResponse) ProtoMessage() {} - -func (m *CommitResponse) GetCost() *Cost { - if m != nil { - return m.Cost - } - return nil -} - -func (m *CommitResponse) GetVersion() []*CommitResponse_Version { - if m != nil { - return m.Version - } - return nil -} - -type CommitResponse_Version struct { - RootEntityKey *Reference `protobuf:"bytes,4,req,name=root_entity_key" json:"root_entity_key,omitempty"` - Version *int64 `protobuf:"varint,5,req,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *CommitResponse_Version) Reset() { *m = CommitResponse_Version{} } -func (m *CommitResponse_Version) String() string { return proto.CompactTextString(m) } -func (*CommitResponse_Version) ProtoMessage() {} - -func (m *CommitResponse_Version) GetRootEntityKey() *Reference { - if m != nil { - return m.RootEntityKey - } - return nil -} - -func (m *CommitResponse_Version) GetVersion() int64 { - if m != nil && m.Version != nil { - return *m.Version - } - return 0 -} - -func init() { -} diff --git a/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto b/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto deleted file mode 100755 index e76f126ff7c6a3dc58ff2e4e2d0323d93529cb10..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto +++ /dev/null @@ -1,541 +0,0 @@ -syntax = "proto2"; -option go_package = "datastore"; - -package appengine; - -message Action{} - -message PropertyValue { - optional int64 int64Value = 1; - optional bool booleanValue = 2; - optional string stringValue = 3; - optional double doubleValue = 4; - - optional group PointValue = 5 { - required double x = 6; - required double y = 7; - } - - optional group UserValue = 8 { - required string email = 9; - required string auth_domain = 10; - optional string nickname = 11; - optional string federated_identity = 21; - optional string federated_provider = 22; - } - - optional group ReferenceValue = 12 { - required string app = 13; - optional string name_space = 20; - repeated group PathElement = 14 { - required string type = 15; - optional int64 id = 16; - optional string name = 17; - } - } -} - -message Property { - enum Meaning { - NO_MEANING = 0; - BLOB = 14; - TEXT = 15; - BYTESTRING = 16; - - ATOM_CATEGORY = 1; - ATOM_LINK = 2; - ATOM_TITLE = 3; - ATOM_CONTENT = 4; - ATOM_SUMMARY = 5; - ATOM_AUTHOR = 6; - - GD_WHEN = 7; - GD_EMAIL = 8; - GEORSS_POINT = 9; - GD_IM = 10; - - GD_PHONENUMBER = 11; - GD_POSTALADDRESS = 12; - - GD_RATING = 13; - - BLOBKEY = 17; - ENTITY_PROTO = 19; - - INDEX_VALUE = 18; - }; - - optional Meaning meaning = 1 [default = NO_MEANING]; - optional string meaning_uri = 2; - - required string name = 3; - - required PropertyValue value = 5; - - required bool multiple = 4; - - optional bool searchable = 6 [default=false]; - - enum FtsTokenizationOption { - HTML = 1; - ATOM = 2; - } - - optional FtsTokenizationOption fts_tokenization_option = 8; - - optional string locale = 9 [default = "en"]; -} - -message Path { - repeated group Element = 1 { - required string type = 2; - optional int64 id = 3; - optional string name = 4; - } -} - -message Reference { - required string app = 13; - optional string name_space = 20; - required Path path = 14; -} - -message User { - required string email = 1; - required string auth_domain = 2; - optional string nickname = 3; - optional string federated_identity = 6; - optional string federated_provider = 7; -} - -message EntityProto { - required Reference key = 13; - required Path entity_group = 16; - optional User owner = 17; - - enum Kind { - GD_CONTACT = 1; - GD_EVENT = 2; - GD_MESSAGE = 3; - } - optional Kind kind = 4; - optional string kind_uri = 5; - - repeated Property property = 14; - repeated Property raw_property = 15; - - optional int32 rank = 18; -} - -message CompositeProperty { - required int64 index_id = 1; - repeated string value = 2; -} - -message Index { - required string entity_type = 1; - required bool ancestor = 5; - repeated group Property = 2 { - required string name = 3; - enum Direction { - ASCENDING = 1; - DESCENDING = 2; - } - optional Direction direction = 4 [default = ASCENDING]; - } -} - -message CompositeIndex { - required string app_id = 1; - required int64 id = 2; - required Index definition = 3; - - enum State { - WRITE_ONLY = 1; - READ_WRITE = 2; - DELETED = 3; - ERROR = 4; - } - required State state = 4; - - optional bool only_use_if_required = 6 [default = false]; -} - -message IndexPostfix { - message IndexValue { - required string property_name = 1; - required PropertyValue value = 2; - } - - repeated IndexValue index_value = 1; - - optional Reference key = 2; - - optional bool before = 3 [default=true]; -} - -message IndexPosition { - optional string key = 1; - - optional bool before = 2 [default=true]; -} - -message Snapshot { - enum Status { - INACTIVE = 0; - ACTIVE = 1; - } - - required int64 ts = 1; -} - -message InternalHeader { - optional string qos = 1; -} - -message Transaction { - optional InternalHeader header = 4; - required fixed64 handle = 1; - required string app = 2; - optional bool mark_changes = 3 [default = false]; -} - -message Query { - optional InternalHeader header = 39; - - required string app = 1; - optional string name_space = 29; - - optional string kind = 3; - optional Reference ancestor = 17; - - repeated group Filter = 4 { - enum Operator { - LESS_THAN = 1; - LESS_THAN_OR_EQUAL = 2; - GREATER_THAN = 3; - GREATER_THAN_OR_EQUAL = 4; - EQUAL = 5; - IN = 6; - EXISTS = 7; - } - - required Operator op = 6; - repeated Property property = 14; - } - - optional string search_query = 8; - - repeated group Order = 9 { - enum Direction { - ASCENDING = 1; - DESCENDING = 2; - } - - required string property = 10; - optional Direction direction = 11 [default = ASCENDING]; - } - - enum Hint { - ORDER_FIRST = 1; - ANCESTOR_FIRST = 2; - FILTER_FIRST = 3; - } - optional Hint hint = 18; - - optional int32 count = 23; - - optional int32 offset = 12 [default = 0]; - - optional int32 limit = 16; - - optional CompiledCursor compiled_cursor = 30; - optional CompiledCursor end_compiled_cursor = 31; - - repeated CompositeIndex composite_index = 19; - - optional bool require_perfect_plan = 20 [default = false]; - - optional bool keys_only = 21 [default = false]; - - optional Transaction transaction = 22; - - optional bool compile = 25 [default = false]; - - optional int64 failover_ms = 26; - - optional bool strong = 32; - - repeated string property_name = 33; - - repeated string group_by_property_name = 34; - - optional bool distinct = 24; - - optional int64 min_safe_time_seconds = 35; - - repeated string safe_replica_name = 36; - - optional bool persist_offset = 37 [default=false]; -} - -message CompiledQuery { - required group PrimaryScan = 1 { - optional string index_name = 2; - - optional string start_key = 3; - optional bool start_inclusive = 4; - optional string end_key = 5; - optional bool end_inclusive = 6; - - repeated string start_postfix_value = 22; - repeated string end_postfix_value = 23; - - optional int64 end_unapplied_log_timestamp_us = 19; - } - - repeated group MergeJoinScan = 7 { - required string index_name = 8; - - repeated string prefix_value = 9; - - optional bool value_prefix = 20 [default=false]; - } - - optional Index index_def = 21; - - optional int32 offset = 10 [default = 0]; - - optional int32 limit = 11; - - required bool keys_only = 12; - - repeated string property_name = 24; - - optional int32 distinct_infix_size = 25; - - optional group EntityFilter = 13 { - optional bool distinct = 14 [default=false]; - - optional string kind = 17; - optional Reference ancestor = 18; - } -} - -message CompiledCursor { - optional group Position = 2 { - optional string start_key = 27; - - repeated group IndexValue = 29 { - optional string property = 30; - required PropertyValue value = 31; - } - - optional Reference key = 32; - - optional bool start_inclusive = 28 [default=true]; - } -} - -message Cursor { - required fixed64 cursor = 1; - - optional string app = 2; -} - -message Error { - enum ErrorCode { - BAD_REQUEST = 1; - CONCURRENT_TRANSACTION = 2; - INTERNAL_ERROR = 3; - NEED_INDEX = 4; - TIMEOUT = 5; - PERMISSION_DENIED = 6; - BIGTABLE_ERROR = 7; - COMMITTED_BUT_STILL_APPLYING = 8; - CAPABILITY_DISABLED = 9; - TRY_ALTERNATE_BACKEND = 10; - SAFE_TIME_TOO_OLD = 11; - } -} - -message Cost { - optional int32 index_writes = 1; - optional int32 index_write_bytes = 2; - optional int32 entity_writes = 3; - optional int32 entity_write_bytes = 4; - optional group CommitCost = 5 { - optional int32 requested_entity_puts = 6; - optional int32 requested_entity_deletes = 7; - }; - optional int32 approximate_storage_delta = 8; - optional int32 id_sequence_updates = 9; -} - -message GetRequest { - optional InternalHeader header = 6; - - repeated Reference key = 1; - optional Transaction transaction = 2; - - optional int64 failover_ms = 3; - - optional bool strong = 4; - - optional bool allow_deferred = 5 [default=false]; -} - -message GetResponse { - repeated group Entity = 1 { - optional EntityProto entity = 2; - optional Reference key = 4; - - optional int64 version = 3; - } - - repeated Reference deferred = 5; - - optional bool in_order = 6 [default=true]; -} - -message PutRequest { - optional InternalHeader header = 11; - - repeated EntityProto entity = 1; - optional Transaction transaction = 2; - repeated CompositeIndex composite_index = 3; - - optional bool trusted = 4 [default = false]; - - optional bool force = 7 [default = false]; - - optional bool mark_changes = 8 [default = false]; - repeated Snapshot snapshot = 9; - - enum AutoIdPolicy { - CURRENT = 0; - SEQUENTIAL = 1; - } - optional AutoIdPolicy auto_id_policy = 10 [default = CURRENT]; -} - -message PutResponse { - repeated Reference key = 1; - optional Cost cost = 2; - repeated int64 version = 3; -} - -message TouchRequest { - optional InternalHeader header = 10; - - repeated Reference key = 1; - repeated CompositeIndex composite_index = 2; - optional bool force = 3 [default = false]; - repeated Snapshot snapshot = 9; -} - -message TouchResponse { - optional Cost cost = 1; -} - -message DeleteRequest { - optional InternalHeader header = 10; - - repeated Reference key = 6; - optional Transaction transaction = 5; - - optional bool trusted = 4 [default = false]; - - optional bool force = 7 [default = false]; - - optional bool mark_changes = 8 [default = false]; - repeated Snapshot snapshot = 9; -} - -message DeleteResponse { - optional Cost cost = 1; - repeated int64 version = 3; -} - -message NextRequest { - optional InternalHeader header = 5; - - required Cursor cursor = 1; - optional int32 count = 2; - - optional int32 offset = 4 [default = 0]; - - optional bool compile = 3 [default = false]; -} - -message QueryResult { - optional Cursor cursor = 1; - - repeated EntityProto result = 2; - - optional int32 skipped_results = 7; - - required bool more_results = 3; - - optional bool keys_only = 4; - - optional bool index_only = 9; - - optional bool small_ops = 10; - - optional CompiledQuery compiled_query = 5; - - optional CompiledCursor compiled_cursor = 6; - - repeated CompositeIndex index = 8; - - repeated int64 version = 11; -} - -message AllocateIdsRequest { - optional InternalHeader header = 4; - - optional Reference model_key = 1; - - optional int64 size = 2; - - optional int64 max = 3; - - repeated Reference reserve = 5; -} - -message AllocateIdsResponse { - required int64 start = 1; - required int64 end = 2; - optional Cost cost = 3; -} - -message CompositeIndices { - repeated CompositeIndex index = 1; -} - -message AddActionsRequest { - optional InternalHeader header = 3; - - required Transaction transaction = 1; - repeated Action action = 2; -} - -message AddActionsResponse { -} - -message BeginTransactionRequest { - optional InternalHeader header = 3; - - required string app = 1; - optional bool allow_multiple_eg = 2 [default = false]; -} - -message CommitResponse { - optional Cost cost = 1; - - repeated group Version = 3 { - required Reference root_entity_key = 4; - required int64 version = 5; - } -} diff --git a/vendor/google.golang.org/appengine/internal/identity.go b/vendor/google.golang.org/appengine/internal/identity.go deleted file mode 100644 index d538701ab3b2bd817981abe4a1d7a111fdd72e41..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/identity.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package internal - -import netcontext "golang.org/x/net/context" - -// These functions are implementations of the wrapper functions -// in ../appengine/identity.go. See that file for commentary. - -func AppID(c netcontext.Context) string { - return appID(FullyQualifiedAppID(c)) -} diff --git a/vendor/google.golang.org/appengine/internal/identity_vm.go b/vendor/google.golang.org/appengine/internal/identity_vm.go deleted file mode 100644 index d5fa75be78eb31a709f5bae34a49453bfad1100e..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/identity_vm.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// +build !appengine - -package internal - -import ( - "net/http" - "os" - - netcontext "golang.org/x/net/context" -) - -// These functions are implementations of the wrapper functions -// in ../appengine/identity.go. See that file for commentary. - -const ( - hDefaultVersionHostname = "X-AppEngine-Default-Version-Hostname" - hRequestLogId = "X-AppEngine-Request-Log-Id" - hDatacenter = "X-AppEngine-Datacenter" -) - -func ctxHeaders(ctx netcontext.Context) http.Header { - c := fromContext(ctx) - if c == nil { - return nil - } - return c.Request().Header -} - -func DefaultVersionHostname(ctx netcontext.Context) string { - return ctxHeaders(ctx).Get(hDefaultVersionHostname) -} - -func RequestID(ctx netcontext.Context) string { - return ctxHeaders(ctx).Get(hRequestLogId) -} - -func Datacenter(ctx netcontext.Context) string { - return ctxHeaders(ctx).Get(hDatacenter) -} - -func ServerSoftware() string { - // TODO(dsymonds): Remove fallback when we've verified this. - if s := os.Getenv("SERVER_SOFTWARE"); s != "" { - return s - } - return "Google App Engine/1.x.x" -} - -// TODO(dsymonds): Remove the metadata fetches. - -func ModuleName(_ netcontext.Context) string { - if s := os.Getenv("GAE_MODULE_NAME"); s != "" { - return s - } - return string(mustGetMetadata("instance/attributes/gae_backend_name")) -} - -func VersionID(_ netcontext.Context) string { - if s1, s2 := os.Getenv("GAE_MODULE_VERSION"), os.Getenv("GAE_MINOR_VERSION"); s1 != "" && s2 != "" { - return s1 + "." + s2 - } - return string(mustGetMetadata("instance/attributes/gae_backend_version")) + "." + string(mustGetMetadata("instance/attributes/gae_backend_minor_version")) -} - -func InstanceID() string { - if s := os.Getenv("GAE_MODULE_INSTANCE"); s != "" { - return s - } - return string(mustGetMetadata("instance/attributes/gae_backend_instance")) -} - -func partitionlessAppID() string { - // gae_project has everything except the partition prefix. - appID := os.Getenv("GAE_LONG_APP_ID") - if appID == "" { - appID = string(mustGetMetadata("instance/attributes/gae_project")) - } - return appID -} - -func fullyQualifiedAppID(_ netcontext.Context) string { - appID := partitionlessAppID() - - part := os.Getenv("GAE_PARTITION") - if part == "" { - part = string(mustGetMetadata("instance/attributes/gae_partition")) - } - - if part != "" { - appID = part + "~" + appID - } - return appID -} - -func IsDevAppServer() bool { - return os.Getenv("RUN_WITH_DEVAPPSERVER") != "" -} diff --git a/vendor/google.golang.org/appengine/internal/internal.go b/vendor/google.golang.org/appengine/internal/internal.go deleted file mode 100644 index 051ea3980abe4d4e189dbc1b64b1c9c80a3844f4..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/internal.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// Package internal provides support for package appengine. -// -// Programs should not use this package directly. Its API is not stable. -// Use packages appengine and appengine/* instead. -package internal - -import ( - "fmt" - - "github.com/golang/protobuf/proto" - - remotepb "google.golang.org/appengine/internal/remote_api" -) - -// errorCodeMaps is a map of service name to the error code map for the service. -var errorCodeMaps = make(map[string]map[int32]string) - -// RegisterErrorCodeMap is called from API implementations to register their -// error code map. This should only be called from init functions. -func RegisterErrorCodeMap(service string, m map[int32]string) { - errorCodeMaps[service] = m -} - -type timeoutCodeKey struct { - service string - code int32 -} - -// timeoutCodes is the set of service+code pairs that represent timeouts. -var timeoutCodes = make(map[timeoutCodeKey]bool) - -func RegisterTimeoutErrorCode(service string, code int32) { - timeoutCodes[timeoutCodeKey{service, code}] = true -} - -// APIError is the type returned by appengine.Context's Call method -// when an API call fails in an API-specific way. This may be, for instance, -// a taskqueue API call failing with TaskQueueServiceError::UNKNOWN_QUEUE. -type APIError struct { - Service string - Detail string - Code int32 // API-specific error code -} - -func (e *APIError) Error() string { - if e.Code == 0 { - if e.Detail == "" { - return "APIError <empty>" - } - return e.Detail - } - s := fmt.Sprintf("API error %d", e.Code) - if m, ok := errorCodeMaps[e.Service]; ok { - s += " (" + e.Service + ": " + m[e.Code] + ")" - } else { - // Shouldn't happen, but provide a bit more detail if it does. - s = e.Service + " " + s - } - if e.Detail != "" { - s += ": " + e.Detail - } - return s -} - -func (e *APIError) IsTimeout() bool { - return timeoutCodes[timeoutCodeKey{e.Service, e.Code}] -} - -// CallError is the type returned by appengine.Context's Call method when an -// API call fails in a generic way, such as RpcError::CAPABILITY_DISABLED. -type CallError struct { - Detail string - Code int32 - // TODO: Remove this if we get a distinguishable error code. - Timeout bool -} - -func (e *CallError) Error() string { - var msg string - switch remotepb.RpcError_ErrorCode(e.Code) { - case remotepb.RpcError_UNKNOWN: - return e.Detail - case remotepb.RpcError_OVER_QUOTA: - msg = "Over quota" - case remotepb.RpcError_CAPABILITY_DISABLED: - msg = "Capability disabled" - case remotepb.RpcError_CANCELLED: - msg = "Canceled" - default: - msg = fmt.Sprintf("Call error %d", e.Code) - } - s := msg + ": " + e.Detail - if e.Timeout { - s += " (timeout)" - } - return s -} - -func (e *CallError) IsTimeout() bool { - return e.Timeout -} - -// NamespaceMods is a map from API service to a function that will mutate an RPC request to attach a namespace. -// The function should be prepared to be called on the same message more than once; it should only modify the -// RPC request the first time. -var NamespaceMods = make(map[string]func(m proto.Message, namespace string)) diff --git a/vendor/google.golang.org/appengine/internal/log/log_service.pb.go b/vendor/google.golang.org/appengine/internal/log/log_service.pb.go deleted file mode 100644 index 20c595be30a1a129b3936585f932dc5a06cfcfd0..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/log/log_service.pb.go +++ /dev/null @@ -1,899 +0,0 @@ -// Code generated by protoc-gen-go. -// source: google.golang.org/appengine/internal/log/log_service.proto -// DO NOT EDIT! - -/* -Package log is a generated protocol buffer package. - -It is generated from these files: - google.golang.org/appengine/internal/log/log_service.proto - -It has these top-level messages: - LogServiceError - UserAppLogLine - UserAppLogGroup - FlushRequest - SetStatusRequest - LogOffset - LogLine - RequestLog - LogModuleVersion - LogReadRequest - LogReadResponse - LogUsageRecord - LogUsageRequest - LogUsageResponse -*/ -package log - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type LogServiceError_ErrorCode int32 - -const ( - LogServiceError_OK LogServiceError_ErrorCode = 0 - LogServiceError_INVALID_REQUEST LogServiceError_ErrorCode = 1 - LogServiceError_STORAGE_ERROR LogServiceError_ErrorCode = 2 -) - -var LogServiceError_ErrorCode_name = map[int32]string{ - 0: "OK", - 1: "INVALID_REQUEST", - 2: "STORAGE_ERROR", -} -var LogServiceError_ErrorCode_value = map[string]int32{ - "OK": 0, - "INVALID_REQUEST": 1, - "STORAGE_ERROR": 2, -} - -func (x LogServiceError_ErrorCode) Enum() *LogServiceError_ErrorCode { - p := new(LogServiceError_ErrorCode) - *p = x - return p -} -func (x LogServiceError_ErrorCode) String() string { - return proto.EnumName(LogServiceError_ErrorCode_name, int32(x)) -} -func (x *LogServiceError_ErrorCode) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(LogServiceError_ErrorCode_value, data, "LogServiceError_ErrorCode") - if err != nil { - return err - } - *x = LogServiceError_ErrorCode(value) - return nil -} - -type LogServiceError struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogServiceError) Reset() { *m = LogServiceError{} } -func (m *LogServiceError) String() string { return proto.CompactTextString(m) } -func (*LogServiceError) ProtoMessage() {} - -type UserAppLogLine struct { - TimestampUsec *int64 `protobuf:"varint,1,req,name=timestamp_usec" json:"timestamp_usec,omitempty"` - Level *int64 `protobuf:"varint,2,req,name=level" json:"level,omitempty"` - Message *string `protobuf:"bytes,3,req,name=message" json:"message,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *UserAppLogLine) Reset() { *m = UserAppLogLine{} } -func (m *UserAppLogLine) String() string { return proto.CompactTextString(m) } -func (*UserAppLogLine) ProtoMessage() {} - -func (m *UserAppLogLine) GetTimestampUsec() int64 { - if m != nil && m.TimestampUsec != nil { - return *m.TimestampUsec - } - return 0 -} - -func (m *UserAppLogLine) GetLevel() int64 { - if m != nil && m.Level != nil { - return *m.Level - } - return 0 -} - -func (m *UserAppLogLine) GetMessage() string { - if m != nil && m.Message != nil { - return *m.Message - } - return "" -} - -type UserAppLogGroup struct { - LogLine []*UserAppLogLine `protobuf:"bytes,2,rep,name=log_line" json:"log_line,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *UserAppLogGroup) Reset() { *m = UserAppLogGroup{} } -func (m *UserAppLogGroup) String() string { return proto.CompactTextString(m) } -func (*UserAppLogGroup) ProtoMessage() {} - -func (m *UserAppLogGroup) GetLogLine() []*UserAppLogLine { - if m != nil { - return m.LogLine - } - return nil -} - -type FlushRequest struct { - Logs []byte `protobuf:"bytes,1,opt,name=logs" json:"logs,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *FlushRequest) Reset() { *m = FlushRequest{} } -func (m *FlushRequest) String() string { return proto.CompactTextString(m) } -func (*FlushRequest) ProtoMessage() {} - -func (m *FlushRequest) GetLogs() []byte { - if m != nil { - return m.Logs - } - return nil -} - -type SetStatusRequest struct { - Status *string `protobuf:"bytes,1,req,name=status" json:"status,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *SetStatusRequest) Reset() { *m = SetStatusRequest{} } -func (m *SetStatusRequest) String() string { return proto.CompactTextString(m) } -func (*SetStatusRequest) ProtoMessage() {} - -func (m *SetStatusRequest) GetStatus() string { - if m != nil && m.Status != nil { - return *m.Status - } - return "" -} - -type LogOffset struct { - RequestId []byte `protobuf:"bytes,1,opt,name=request_id" json:"request_id,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogOffset) Reset() { *m = LogOffset{} } -func (m *LogOffset) String() string { return proto.CompactTextString(m) } -func (*LogOffset) ProtoMessage() {} - -func (m *LogOffset) GetRequestId() []byte { - if m != nil { - return m.RequestId - } - return nil -} - -type LogLine struct { - Time *int64 `protobuf:"varint,1,req,name=time" json:"time,omitempty"` - Level *int32 `protobuf:"varint,2,req,name=level" json:"level,omitempty"` - LogMessage *string `protobuf:"bytes,3,req,name=log_message" json:"log_message,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogLine) Reset() { *m = LogLine{} } -func (m *LogLine) String() string { return proto.CompactTextString(m) } -func (*LogLine) ProtoMessage() {} - -func (m *LogLine) GetTime() int64 { - if m != nil && m.Time != nil { - return *m.Time - } - return 0 -} - -func (m *LogLine) GetLevel() int32 { - if m != nil && m.Level != nil { - return *m.Level - } - return 0 -} - -func (m *LogLine) GetLogMessage() string { - if m != nil && m.LogMessage != nil { - return *m.LogMessage - } - return "" -} - -type RequestLog struct { - AppId *string `protobuf:"bytes,1,req,name=app_id" json:"app_id,omitempty"` - ModuleId *string `protobuf:"bytes,37,opt,name=module_id,def=default" json:"module_id,omitempty"` - VersionId *string `protobuf:"bytes,2,req,name=version_id" json:"version_id,omitempty"` - RequestId []byte `protobuf:"bytes,3,req,name=request_id" json:"request_id,omitempty"` - Offset *LogOffset `protobuf:"bytes,35,opt,name=offset" json:"offset,omitempty"` - Ip *string `protobuf:"bytes,4,req,name=ip" json:"ip,omitempty"` - Nickname *string `protobuf:"bytes,5,opt,name=nickname" json:"nickname,omitempty"` - StartTime *int64 `protobuf:"varint,6,req,name=start_time" json:"start_time,omitempty"` - EndTime *int64 `protobuf:"varint,7,req,name=end_time" json:"end_time,omitempty"` - Latency *int64 `protobuf:"varint,8,req,name=latency" json:"latency,omitempty"` - Mcycles *int64 `protobuf:"varint,9,req,name=mcycles" json:"mcycles,omitempty"` - Method *string `protobuf:"bytes,10,req,name=method" json:"method,omitempty"` - Resource *string `protobuf:"bytes,11,req,name=resource" json:"resource,omitempty"` - HttpVersion *string `protobuf:"bytes,12,req,name=http_version" json:"http_version,omitempty"` - Status *int32 `protobuf:"varint,13,req,name=status" json:"status,omitempty"` - ResponseSize *int64 `protobuf:"varint,14,req,name=response_size" json:"response_size,omitempty"` - Referrer *string `protobuf:"bytes,15,opt,name=referrer" json:"referrer,omitempty"` - UserAgent *string `protobuf:"bytes,16,opt,name=user_agent" json:"user_agent,omitempty"` - UrlMapEntry *string `protobuf:"bytes,17,req,name=url_map_entry" json:"url_map_entry,omitempty"` - Combined *string `protobuf:"bytes,18,req,name=combined" json:"combined,omitempty"` - ApiMcycles *int64 `protobuf:"varint,19,opt,name=api_mcycles" json:"api_mcycles,omitempty"` - Host *string `protobuf:"bytes,20,opt,name=host" json:"host,omitempty"` - Cost *float64 `protobuf:"fixed64,21,opt,name=cost" json:"cost,omitempty"` - TaskQueueName *string `protobuf:"bytes,22,opt,name=task_queue_name" json:"task_queue_name,omitempty"` - TaskName *string `protobuf:"bytes,23,opt,name=task_name" json:"task_name,omitempty"` - WasLoadingRequest *bool `protobuf:"varint,24,opt,name=was_loading_request" json:"was_loading_request,omitempty"` - PendingTime *int64 `protobuf:"varint,25,opt,name=pending_time" json:"pending_time,omitempty"` - ReplicaIndex *int32 `protobuf:"varint,26,opt,name=replica_index,def=-1" json:"replica_index,omitempty"` - Finished *bool `protobuf:"varint,27,opt,name=finished,def=1" json:"finished,omitempty"` - CloneKey []byte `protobuf:"bytes,28,opt,name=clone_key" json:"clone_key,omitempty"` - Line []*LogLine `protobuf:"bytes,29,rep,name=line" json:"line,omitempty"` - LinesIncomplete *bool `protobuf:"varint,36,opt,name=lines_incomplete" json:"lines_incomplete,omitempty"` - AppEngineRelease []byte `protobuf:"bytes,38,opt,name=app_engine_release" json:"app_engine_release,omitempty"` - ExitReason *int32 `protobuf:"varint,30,opt,name=exit_reason" json:"exit_reason,omitempty"` - WasThrottledForTime *bool `protobuf:"varint,31,opt,name=was_throttled_for_time" json:"was_throttled_for_time,omitempty"` - WasThrottledForRequests *bool `protobuf:"varint,32,opt,name=was_throttled_for_requests" json:"was_throttled_for_requests,omitempty"` - ThrottledTime *int64 `protobuf:"varint,33,opt,name=throttled_time" json:"throttled_time,omitempty"` - ServerName []byte `protobuf:"bytes,34,opt,name=server_name" json:"server_name,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *RequestLog) Reset() { *m = RequestLog{} } -func (m *RequestLog) String() string { return proto.CompactTextString(m) } -func (*RequestLog) ProtoMessage() {} - -const Default_RequestLog_ModuleId string = "default" -const Default_RequestLog_ReplicaIndex int32 = -1 -const Default_RequestLog_Finished bool = true - -func (m *RequestLog) GetAppId() string { - if m != nil && m.AppId != nil { - return *m.AppId - } - return "" -} - -func (m *RequestLog) GetModuleId() string { - if m != nil && m.ModuleId != nil { - return *m.ModuleId - } - return Default_RequestLog_ModuleId -} - -func (m *RequestLog) GetVersionId() string { - if m != nil && m.VersionId != nil { - return *m.VersionId - } - return "" -} - -func (m *RequestLog) GetRequestId() []byte { - if m != nil { - return m.RequestId - } - return nil -} - -func (m *RequestLog) GetOffset() *LogOffset { - if m != nil { - return m.Offset - } - return nil -} - -func (m *RequestLog) GetIp() string { - if m != nil && m.Ip != nil { - return *m.Ip - } - return "" -} - -func (m *RequestLog) GetNickname() string { - if m != nil && m.Nickname != nil { - return *m.Nickname - } - return "" -} - -func (m *RequestLog) GetStartTime() int64 { - if m != nil && m.StartTime != nil { - return *m.StartTime - } - return 0 -} - -func (m *RequestLog) GetEndTime() int64 { - if m != nil && m.EndTime != nil { - return *m.EndTime - } - return 0 -} - -func (m *RequestLog) GetLatency() int64 { - if m != nil && m.Latency != nil { - return *m.Latency - } - return 0 -} - -func (m *RequestLog) GetMcycles() int64 { - if m != nil && m.Mcycles != nil { - return *m.Mcycles - } - return 0 -} - -func (m *RequestLog) GetMethod() string { - if m != nil && m.Method != nil { - return *m.Method - } - return "" -} - -func (m *RequestLog) GetResource() string { - if m != nil && m.Resource != nil { - return *m.Resource - } - return "" -} - -func (m *RequestLog) GetHttpVersion() string { - if m != nil && m.HttpVersion != nil { - return *m.HttpVersion - } - return "" -} - -func (m *RequestLog) GetStatus() int32 { - if m != nil && m.Status != nil { - return *m.Status - } - return 0 -} - -func (m *RequestLog) GetResponseSize() int64 { - if m != nil && m.ResponseSize != nil { - return *m.ResponseSize - } - return 0 -} - -func (m *RequestLog) GetReferrer() string { - if m != nil && m.Referrer != nil { - return *m.Referrer - } - return "" -} - -func (m *RequestLog) GetUserAgent() string { - if m != nil && m.UserAgent != nil { - return *m.UserAgent - } - return "" -} - -func (m *RequestLog) GetUrlMapEntry() string { - if m != nil && m.UrlMapEntry != nil { - return *m.UrlMapEntry - } - return "" -} - -func (m *RequestLog) GetCombined() string { - if m != nil && m.Combined != nil { - return *m.Combined - } - return "" -} - -func (m *RequestLog) GetApiMcycles() int64 { - if m != nil && m.ApiMcycles != nil { - return *m.ApiMcycles - } - return 0 -} - -func (m *RequestLog) GetHost() string { - if m != nil && m.Host != nil { - return *m.Host - } - return "" -} - -func (m *RequestLog) GetCost() float64 { - if m != nil && m.Cost != nil { - return *m.Cost - } - return 0 -} - -func (m *RequestLog) GetTaskQueueName() string { - if m != nil && m.TaskQueueName != nil { - return *m.TaskQueueName - } - return "" -} - -func (m *RequestLog) GetTaskName() string { - if m != nil && m.TaskName != nil { - return *m.TaskName - } - return "" -} - -func (m *RequestLog) GetWasLoadingRequest() bool { - if m != nil && m.WasLoadingRequest != nil { - return *m.WasLoadingRequest - } - return false -} - -func (m *RequestLog) GetPendingTime() int64 { - if m != nil && m.PendingTime != nil { - return *m.PendingTime - } - return 0 -} - -func (m *RequestLog) GetReplicaIndex() int32 { - if m != nil && m.ReplicaIndex != nil { - return *m.ReplicaIndex - } - return Default_RequestLog_ReplicaIndex -} - -func (m *RequestLog) GetFinished() bool { - if m != nil && m.Finished != nil { - return *m.Finished - } - return Default_RequestLog_Finished -} - -func (m *RequestLog) GetCloneKey() []byte { - if m != nil { - return m.CloneKey - } - return nil -} - -func (m *RequestLog) GetLine() []*LogLine { - if m != nil { - return m.Line - } - return nil -} - -func (m *RequestLog) GetLinesIncomplete() bool { - if m != nil && m.LinesIncomplete != nil { - return *m.LinesIncomplete - } - return false -} - -func (m *RequestLog) GetAppEngineRelease() []byte { - if m != nil { - return m.AppEngineRelease - } - return nil -} - -func (m *RequestLog) GetExitReason() int32 { - if m != nil && m.ExitReason != nil { - return *m.ExitReason - } - return 0 -} - -func (m *RequestLog) GetWasThrottledForTime() bool { - if m != nil && m.WasThrottledForTime != nil { - return *m.WasThrottledForTime - } - return false -} - -func (m *RequestLog) GetWasThrottledForRequests() bool { - if m != nil && m.WasThrottledForRequests != nil { - return *m.WasThrottledForRequests - } - return false -} - -func (m *RequestLog) GetThrottledTime() int64 { - if m != nil && m.ThrottledTime != nil { - return *m.ThrottledTime - } - return 0 -} - -func (m *RequestLog) GetServerName() []byte { - if m != nil { - return m.ServerName - } - return nil -} - -type LogModuleVersion struct { - ModuleId *string `protobuf:"bytes,1,opt,name=module_id,def=default" json:"module_id,omitempty"` - VersionId *string `protobuf:"bytes,2,opt,name=version_id" json:"version_id,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogModuleVersion) Reset() { *m = LogModuleVersion{} } -func (m *LogModuleVersion) String() string { return proto.CompactTextString(m) } -func (*LogModuleVersion) ProtoMessage() {} - -const Default_LogModuleVersion_ModuleId string = "default" - -func (m *LogModuleVersion) GetModuleId() string { - if m != nil && m.ModuleId != nil { - return *m.ModuleId - } - return Default_LogModuleVersion_ModuleId -} - -func (m *LogModuleVersion) GetVersionId() string { - if m != nil && m.VersionId != nil { - return *m.VersionId - } - return "" -} - -type LogReadRequest struct { - AppId *string `protobuf:"bytes,1,req,name=app_id" json:"app_id,omitempty"` - VersionId []string `protobuf:"bytes,2,rep,name=version_id" json:"version_id,omitempty"` - ModuleVersion []*LogModuleVersion `protobuf:"bytes,19,rep,name=module_version" json:"module_version,omitempty"` - StartTime *int64 `protobuf:"varint,3,opt,name=start_time" json:"start_time,omitempty"` - EndTime *int64 `protobuf:"varint,4,opt,name=end_time" json:"end_time,omitempty"` - Offset *LogOffset `protobuf:"bytes,5,opt,name=offset" json:"offset,omitempty"` - RequestId [][]byte `protobuf:"bytes,6,rep,name=request_id" json:"request_id,omitempty"` - MinimumLogLevel *int32 `protobuf:"varint,7,opt,name=minimum_log_level" json:"minimum_log_level,omitempty"` - IncludeIncomplete *bool `protobuf:"varint,8,opt,name=include_incomplete" json:"include_incomplete,omitempty"` - Count *int64 `protobuf:"varint,9,opt,name=count" json:"count,omitempty"` - CombinedLogRegex *string `protobuf:"bytes,14,opt,name=combined_log_regex" json:"combined_log_regex,omitempty"` - HostRegex *string `protobuf:"bytes,15,opt,name=host_regex" json:"host_regex,omitempty"` - ReplicaIndex *int32 `protobuf:"varint,16,opt,name=replica_index" json:"replica_index,omitempty"` - IncludeAppLogs *bool `protobuf:"varint,10,opt,name=include_app_logs" json:"include_app_logs,omitempty"` - AppLogsPerRequest *int32 `protobuf:"varint,17,opt,name=app_logs_per_request" json:"app_logs_per_request,omitempty"` - IncludeHost *bool `protobuf:"varint,11,opt,name=include_host" json:"include_host,omitempty"` - IncludeAll *bool `protobuf:"varint,12,opt,name=include_all" json:"include_all,omitempty"` - CacheIterator *bool `protobuf:"varint,13,opt,name=cache_iterator" json:"cache_iterator,omitempty"` - NumShards *int32 `protobuf:"varint,18,opt,name=num_shards" json:"num_shards,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogReadRequest) Reset() { *m = LogReadRequest{} } -func (m *LogReadRequest) String() string { return proto.CompactTextString(m) } -func (*LogReadRequest) ProtoMessage() {} - -func (m *LogReadRequest) GetAppId() string { - if m != nil && m.AppId != nil { - return *m.AppId - } - return "" -} - -func (m *LogReadRequest) GetVersionId() []string { - if m != nil { - return m.VersionId - } - return nil -} - -func (m *LogReadRequest) GetModuleVersion() []*LogModuleVersion { - if m != nil { - return m.ModuleVersion - } - return nil -} - -func (m *LogReadRequest) GetStartTime() int64 { - if m != nil && m.StartTime != nil { - return *m.StartTime - } - return 0 -} - -func (m *LogReadRequest) GetEndTime() int64 { - if m != nil && m.EndTime != nil { - return *m.EndTime - } - return 0 -} - -func (m *LogReadRequest) GetOffset() *LogOffset { - if m != nil { - return m.Offset - } - return nil -} - -func (m *LogReadRequest) GetRequestId() [][]byte { - if m != nil { - return m.RequestId - } - return nil -} - -func (m *LogReadRequest) GetMinimumLogLevel() int32 { - if m != nil && m.MinimumLogLevel != nil { - return *m.MinimumLogLevel - } - return 0 -} - -func (m *LogReadRequest) GetIncludeIncomplete() bool { - if m != nil && m.IncludeIncomplete != nil { - return *m.IncludeIncomplete - } - return false -} - -func (m *LogReadRequest) GetCount() int64 { - if m != nil && m.Count != nil { - return *m.Count - } - return 0 -} - -func (m *LogReadRequest) GetCombinedLogRegex() string { - if m != nil && m.CombinedLogRegex != nil { - return *m.CombinedLogRegex - } - return "" -} - -func (m *LogReadRequest) GetHostRegex() string { - if m != nil && m.HostRegex != nil { - return *m.HostRegex - } - return "" -} - -func (m *LogReadRequest) GetReplicaIndex() int32 { - if m != nil && m.ReplicaIndex != nil { - return *m.ReplicaIndex - } - return 0 -} - -func (m *LogReadRequest) GetIncludeAppLogs() bool { - if m != nil && m.IncludeAppLogs != nil { - return *m.IncludeAppLogs - } - return false -} - -func (m *LogReadRequest) GetAppLogsPerRequest() int32 { - if m != nil && m.AppLogsPerRequest != nil { - return *m.AppLogsPerRequest - } - return 0 -} - -func (m *LogReadRequest) GetIncludeHost() bool { - if m != nil && m.IncludeHost != nil { - return *m.IncludeHost - } - return false -} - -func (m *LogReadRequest) GetIncludeAll() bool { - if m != nil && m.IncludeAll != nil { - return *m.IncludeAll - } - return false -} - -func (m *LogReadRequest) GetCacheIterator() bool { - if m != nil && m.CacheIterator != nil { - return *m.CacheIterator - } - return false -} - -func (m *LogReadRequest) GetNumShards() int32 { - if m != nil && m.NumShards != nil { - return *m.NumShards - } - return 0 -} - -type LogReadResponse struct { - Log []*RequestLog `protobuf:"bytes,1,rep,name=log" json:"log,omitempty"` - Offset *LogOffset `protobuf:"bytes,2,opt,name=offset" json:"offset,omitempty"` - LastEndTime *int64 `protobuf:"varint,3,opt,name=last_end_time" json:"last_end_time,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogReadResponse) Reset() { *m = LogReadResponse{} } -func (m *LogReadResponse) String() string { return proto.CompactTextString(m) } -func (*LogReadResponse) ProtoMessage() {} - -func (m *LogReadResponse) GetLog() []*RequestLog { - if m != nil { - return m.Log - } - return nil -} - -func (m *LogReadResponse) GetOffset() *LogOffset { - if m != nil { - return m.Offset - } - return nil -} - -func (m *LogReadResponse) GetLastEndTime() int64 { - if m != nil && m.LastEndTime != nil { - return *m.LastEndTime - } - return 0 -} - -type LogUsageRecord struct { - VersionId *string `protobuf:"bytes,1,opt,name=version_id" json:"version_id,omitempty"` - StartTime *int32 `protobuf:"varint,2,opt,name=start_time" json:"start_time,omitempty"` - EndTime *int32 `protobuf:"varint,3,opt,name=end_time" json:"end_time,omitempty"` - Count *int64 `protobuf:"varint,4,opt,name=count" json:"count,omitempty"` - TotalSize *int64 `protobuf:"varint,5,opt,name=total_size" json:"total_size,omitempty"` - Records *int32 `protobuf:"varint,6,opt,name=records" json:"records,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogUsageRecord) Reset() { *m = LogUsageRecord{} } -func (m *LogUsageRecord) String() string { return proto.CompactTextString(m) } -func (*LogUsageRecord) ProtoMessage() {} - -func (m *LogUsageRecord) GetVersionId() string { - if m != nil && m.VersionId != nil { - return *m.VersionId - } - return "" -} - -func (m *LogUsageRecord) GetStartTime() int32 { - if m != nil && m.StartTime != nil { - return *m.StartTime - } - return 0 -} - -func (m *LogUsageRecord) GetEndTime() int32 { - if m != nil && m.EndTime != nil { - return *m.EndTime - } - return 0 -} - -func (m *LogUsageRecord) GetCount() int64 { - if m != nil && m.Count != nil { - return *m.Count - } - return 0 -} - -func (m *LogUsageRecord) GetTotalSize() int64 { - if m != nil && m.TotalSize != nil { - return *m.TotalSize - } - return 0 -} - -func (m *LogUsageRecord) GetRecords() int32 { - if m != nil && m.Records != nil { - return *m.Records - } - return 0 -} - -type LogUsageRequest struct { - AppId *string `protobuf:"bytes,1,req,name=app_id" json:"app_id,omitempty"` - VersionId []string `protobuf:"bytes,2,rep,name=version_id" json:"version_id,omitempty"` - StartTime *int32 `protobuf:"varint,3,opt,name=start_time" json:"start_time,omitempty"` - EndTime *int32 `protobuf:"varint,4,opt,name=end_time" json:"end_time,omitempty"` - ResolutionHours *uint32 `protobuf:"varint,5,opt,name=resolution_hours,def=1" json:"resolution_hours,omitempty"` - CombineVersions *bool `protobuf:"varint,6,opt,name=combine_versions" json:"combine_versions,omitempty"` - UsageVersion *int32 `protobuf:"varint,7,opt,name=usage_version" json:"usage_version,omitempty"` - VersionsOnly *bool `protobuf:"varint,8,opt,name=versions_only" json:"versions_only,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogUsageRequest) Reset() { *m = LogUsageRequest{} } -func (m *LogUsageRequest) String() string { return proto.CompactTextString(m) } -func (*LogUsageRequest) ProtoMessage() {} - -const Default_LogUsageRequest_ResolutionHours uint32 = 1 - -func (m *LogUsageRequest) GetAppId() string { - if m != nil && m.AppId != nil { - return *m.AppId - } - return "" -} - -func (m *LogUsageRequest) GetVersionId() []string { - if m != nil { - return m.VersionId - } - return nil -} - -func (m *LogUsageRequest) GetStartTime() int32 { - if m != nil && m.StartTime != nil { - return *m.StartTime - } - return 0 -} - -func (m *LogUsageRequest) GetEndTime() int32 { - if m != nil && m.EndTime != nil { - return *m.EndTime - } - return 0 -} - -func (m *LogUsageRequest) GetResolutionHours() uint32 { - if m != nil && m.ResolutionHours != nil { - return *m.ResolutionHours - } - return Default_LogUsageRequest_ResolutionHours -} - -func (m *LogUsageRequest) GetCombineVersions() bool { - if m != nil && m.CombineVersions != nil { - return *m.CombineVersions - } - return false -} - -func (m *LogUsageRequest) GetUsageVersion() int32 { - if m != nil && m.UsageVersion != nil { - return *m.UsageVersion - } - return 0 -} - -func (m *LogUsageRequest) GetVersionsOnly() bool { - if m != nil && m.VersionsOnly != nil { - return *m.VersionsOnly - } - return false -} - -type LogUsageResponse struct { - Usage []*LogUsageRecord `protobuf:"bytes,1,rep,name=usage" json:"usage,omitempty"` - Summary *LogUsageRecord `protobuf:"bytes,2,opt,name=summary" json:"summary,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *LogUsageResponse) Reset() { *m = LogUsageResponse{} } -func (m *LogUsageResponse) String() string { return proto.CompactTextString(m) } -func (*LogUsageResponse) ProtoMessage() {} - -func (m *LogUsageResponse) GetUsage() []*LogUsageRecord { - if m != nil { - return m.Usage - } - return nil -} - -func (m *LogUsageResponse) GetSummary() *LogUsageRecord { - if m != nil { - return m.Summary - } - return nil -} - -func init() { -} diff --git a/vendor/google.golang.org/appengine/internal/log/log_service.proto b/vendor/google.golang.org/appengine/internal/log/log_service.proto deleted file mode 100644 index 8981dc47577cedcbd5ac1fe11d698c3db24b5d45..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/log/log_service.proto +++ /dev/null @@ -1,150 +0,0 @@ -syntax = "proto2"; -option go_package = "log"; - -package appengine; - -message LogServiceError { - enum ErrorCode { - OK = 0; - INVALID_REQUEST = 1; - STORAGE_ERROR = 2; - } -} - -message UserAppLogLine { - required int64 timestamp_usec = 1; - required int64 level = 2; - required string message = 3; -} - -message UserAppLogGroup { - repeated UserAppLogLine log_line = 2; -} - -message FlushRequest { - optional bytes logs = 1; -} - -message SetStatusRequest { - required string status = 1; -} - - -message LogOffset { - optional bytes request_id = 1; -} - -message LogLine { - required int64 time = 1; - required int32 level = 2; - required string log_message = 3; -} - -message RequestLog { - required string app_id = 1; - optional string module_id = 37 [default="default"]; - required string version_id = 2; - required bytes request_id = 3; - optional LogOffset offset = 35; - required string ip = 4; - optional string nickname = 5; - required int64 start_time = 6; - required int64 end_time = 7; - required int64 latency = 8; - required int64 mcycles = 9; - required string method = 10; - required string resource = 11; - required string http_version = 12; - required int32 status = 13; - required int64 response_size = 14; - optional string referrer = 15; - optional string user_agent = 16; - required string url_map_entry = 17; - required string combined = 18; - optional int64 api_mcycles = 19; - optional string host = 20; - optional double cost = 21; - - optional string task_queue_name = 22; - optional string task_name = 23; - - optional bool was_loading_request = 24; - optional int64 pending_time = 25; - optional int32 replica_index = 26 [default = -1]; - optional bool finished = 27 [default = true]; - optional bytes clone_key = 28; - - repeated LogLine line = 29; - - optional bool lines_incomplete = 36; - optional bytes app_engine_release = 38; - - optional int32 exit_reason = 30; - optional bool was_throttled_for_time = 31; - optional bool was_throttled_for_requests = 32; - optional int64 throttled_time = 33; - - optional bytes server_name = 34; -} - -message LogModuleVersion { - optional string module_id = 1 [default="default"]; - optional string version_id = 2; -} - -message LogReadRequest { - required string app_id = 1; - repeated string version_id = 2; - repeated LogModuleVersion module_version = 19; - - optional int64 start_time = 3; - optional int64 end_time = 4; - optional LogOffset offset = 5; - repeated bytes request_id = 6; - - optional int32 minimum_log_level = 7; - optional bool include_incomplete = 8; - optional int64 count = 9; - - optional string combined_log_regex = 14; - optional string host_regex = 15; - optional int32 replica_index = 16; - - optional bool include_app_logs = 10; - optional int32 app_logs_per_request = 17; - optional bool include_host = 11; - optional bool include_all = 12; - optional bool cache_iterator = 13; - optional int32 num_shards = 18; -} - -message LogReadResponse { - repeated RequestLog log = 1; - optional LogOffset offset = 2; - optional int64 last_end_time = 3; -} - -message LogUsageRecord { - optional string version_id = 1; - optional int32 start_time = 2; - optional int32 end_time = 3; - optional int64 count = 4; - optional int64 total_size = 5; - optional int32 records = 6; -} - -message LogUsageRequest { - required string app_id = 1; - repeated string version_id = 2; - optional int32 start_time = 3; - optional int32 end_time = 4; - optional uint32 resolution_hours = 5 [default = 1]; - optional bool combine_versions = 6; - optional int32 usage_version = 7; - optional bool versions_only = 8; -} - -message LogUsageResponse { - repeated LogUsageRecord usage = 1; - optional LogUsageRecord summary = 2; -} diff --git a/vendor/google.golang.org/appengine/internal/main_vm.go b/vendor/google.golang.org/appengine/internal/main_vm.go deleted file mode 100644 index 822e784a458d9a19ccf50943cb0b20664e265556..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/main_vm.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -// +build !appengine - -package internal - -import ( - "io" - "log" - "net/http" - "net/url" - "os" -) - -func Main() { - installHealthChecker(http.DefaultServeMux) - - port := "8080" - if s := os.Getenv("PORT"); s != "" { - port = s - } - - host := "" - if IsDevAppServer() { - host = "127.0.0.1" - } - if err := http.ListenAndServe(host+":"+port, http.HandlerFunc(handleHTTP)); err != nil { - log.Fatalf("http.ListenAndServe: %v", err) - } -} - -func installHealthChecker(mux *http.ServeMux) { - // If no health check handler has been installed by this point, add a trivial one. - const healthPath = "/_ah/health" - hreq := &http.Request{ - Method: "GET", - URL: &url.URL{ - Path: healthPath, - }, - } - if _, pat := mux.Handler(hreq); pat != healthPath { - mux.HandleFunc(healthPath, func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "ok") - }) - } -} diff --git a/vendor/google.golang.org/appengine/internal/metadata.go b/vendor/google.golang.org/appengine/internal/metadata.go deleted file mode 100644 index 9cc1f71d104d471e04b4986f0c893054edcc5980..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/metadata.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package internal - -// This file has code for accessing metadata. -// -// References: -// https://cloud.google.com/compute/docs/metadata - -import ( - "fmt" - "io/ioutil" - "log" - "net/http" - "net/url" -) - -const ( - metadataHost = "metadata" - metadataPath = "/computeMetadata/v1/" -) - -var ( - metadataRequestHeaders = http.Header{ - "Metadata-Flavor": []string{"Google"}, - } -) - -// TODO(dsymonds): Do we need to support default values, like Python? -func mustGetMetadata(key string) []byte { - b, err := getMetadata(key) - if err != nil { - log.Fatalf("Metadata fetch failed: %v", err) - } - return b -} - -func getMetadata(key string) ([]byte, error) { - // TODO(dsymonds): May need to use url.Parse to support keys with query args. - req := &http.Request{ - Method: "GET", - URL: &url.URL{ - Scheme: "http", - Host: metadataHost, - Path: metadataPath + key, - }, - Header: metadataRequestHeaders, - Host: metadataHost, - } - resp, err := http.DefaultClient.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - if resp.StatusCode != 200 { - return nil, fmt.Errorf("metadata server returned HTTP %d", resp.StatusCode) - } - return ioutil.ReadAll(resp.Body) -} diff --git a/vendor/google.golang.org/appengine/internal/modules/modules_service.pb.go b/vendor/google.golang.org/appengine/internal/modules/modules_service.pb.go deleted file mode 100644 index a0145ed317c1c6749c85f7c03a91f58a4de1c900..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/modules/modules_service.pb.go +++ /dev/null @@ -1,375 +0,0 @@ -// Code generated by protoc-gen-go. -// source: google.golang.org/appengine/internal/modules/modules_service.proto -// DO NOT EDIT! - -/* -Package modules is a generated protocol buffer package. - -It is generated from these files: - google.golang.org/appengine/internal/modules/modules_service.proto - -It has these top-level messages: - ModulesServiceError - GetModulesRequest - GetModulesResponse - GetVersionsRequest - GetVersionsResponse - GetDefaultVersionRequest - GetDefaultVersionResponse - GetNumInstancesRequest - GetNumInstancesResponse - SetNumInstancesRequest - SetNumInstancesResponse - StartModuleRequest - StartModuleResponse - StopModuleRequest - StopModuleResponse - GetHostnameRequest - GetHostnameResponse -*/ -package modules - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type ModulesServiceError_ErrorCode int32 - -const ( - ModulesServiceError_OK ModulesServiceError_ErrorCode = 0 - ModulesServiceError_INVALID_MODULE ModulesServiceError_ErrorCode = 1 - ModulesServiceError_INVALID_VERSION ModulesServiceError_ErrorCode = 2 - ModulesServiceError_INVALID_INSTANCES ModulesServiceError_ErrorCode = 3 - ModulesServiceError_TRANSIENT_ERROR ModulesServiceError_ErrorCode = 4 - ModulesServiceError_UNEXPECTED_STATE ModulesServiceError_ErrorCode = 5 -) - -var ModulesServiceError_ErrorCode_name = map[int32]string{ - 0: "OK", - 1: "INVALID_MODULE", - 2: "INVALID_VERSION", - 3: "INVALID_INSTANCES", - 4: "TRANSIENT_ERROR", - 5: "UNEXPECTED_STATE", -} -var ModulesServiceError_ErrorCode_value = map[string]int32{ - "OK": 0, - "INVALID_MODULE": 1, - "INVALID_VERSION": 2, - "INVALID_INSTANCES": 3, - "TRANSIENT_ERROR": 4, - "UNEXPECTED_STATE": 5, -} - -func (x ModulesServiceError_ErrorCode) Enum() *ModulesServiceError_ErrorCode { - p := new(ModulesServiceError_ErrorCode) - *p = x - return p -} -func (x ModulesServiceError_ErrorCode) String() string { - return proto.EnumName(ModulesServiceError_ErrorCode_name, int32(x)) -} -func (x *ModulesServiceError_ErrorCode) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ModulesServiceError_ErrorCode_value, data, "ModulesServiceError_ErrorCode") - if err != nil { - return err - } - *x = ModulesServiceError_ErrorCode(value) - return nil -} - -type ModulesServiceError struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *ModulesServiceError) Reset() { *m = ModulesServiceError{} } -func (m *ModulesServiceError) String() string { return proto.CompactTextString(m) } -func (*ModulesServiceError) ProtoMessage() {} - -type GetModulesRequest struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetModulesRequest) Reset() { *m = GetModulesRequest{} } -func (m *GetModulesRequest) String() string { return proto.CompactTextString(m) } -func (*GetModulesRequest) ProtoMessage() {} - -type GetModulesResponse struct { - Module []string `protobuf:"bytes,1,rep,name=module" json:"module,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetModulesResponse) Reset() { *m = GetModulesResponse{} } -func (m *GetModulesResponse) String() string { return proto.CompactTextString(m) } -func (*GetModulesResponse) ProtoMessage() {} - -func (m *GetModulesResponse) GetModule() []string { - if m != nil { - return m.Module - } - return nil -} - -type GetVersionsRequest struct { - Module *string `protobuf:"bytes,1,opt,name=module" json:"module,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetVersionsRequest) Reset() { *m = GetVersionsRequest{} } -func (m *GetVersionsRequest) String() string { return proto.CompactTextString(m) } -func (*GetVersionsRequest) ProtoMessage() {} - -func (m *GetVersionsRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -type GetVersionsResponse struct { - Version []string `protobuf:"bytes,1,rep,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetVersionsResponse) Reset() { *m = GetVersionsResponse{} } -func (m *GetVersionsResponse) String() string { return proto.CompactTextString(m) } -func (*GetVersionsResponse) ProtoMessage() {} - -func (m *GetVersionsResponse) GetVersion() []string { - if m != nil { - return m.Version - } - return nil -} - -type GetDefaultVersionRequest struct { - Module *string `protobuf:"bytes,1,opt,name=module" json:"module,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetDefaultVersionRequest) Reset() { *m = GetDefaultVersionRequest{} } -func (m *GetDefaultVersionRequest) String() string { return proto.CompactTextString(m) } -func (*GetDefaultVersionRequest) ProtoMessage() {} - -func (m *GetDefaultVersionRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -type GetDefaultVersionResponse struct { - Version *string `protobuf:"bytes,1,req,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetDefaultVersionResponse) Reset() { *m = GetDefaultVersionResponse{} } -func (m *GetDefaultVersionResponse) String() string { return proto.CompactTextString(m) } -func (*GetDefaultVersionResponse) ProtoMessage() {} - -func (m *GetDefaultVersionResponse) GetVersion() string { - if m != nil && m.Version != nil { - return *m.Version - } - return "" -} - -type GetNumInstancesRequest struct { - Module *string `protobuf:"bytes,1,opt,name=module" json:"module,omitempty"` - Version *string `protobuf:"bytes,2,opt,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetNumInstancesRequest) Reset() { *m = GetNumInstancesRequest{} } -func (m *GetNumInstancesRequest) String() string { return proto.CompactTextString(m) } -func (*GetNumInstancesRequest) ProtoMessage() {} - -func (m *GetNumInstancesRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -func (m *GetNumInstancesRequest) GetVersion() string { - if m != nil && m.Version != nil { - return *m.Version - } - return "" -} - -type GetNumInstancesResponse struct { - Instances *int64 `protobuf:"varint,1,req,name=instances" json:"instances,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetNumInstancesResponse) Reset() { *m = GetNumInstancesResponse{} } -func (m *GetNumInstancesResponse) String() string { return proto.CompactTextString(m) } -func (*GetNumInstancesResponse) ProtoMessage() {} - -func (m *GetNumInstancesResponse) GetInstances() int64 { - if m != nil && m.Instances != nil { - return *m.Instances - } - return 0 -} - -type SetNumInstancesRequest struct { - Module *string `protobuf:"bytes,1,opt,name=module" json:"module,omitempty"` - Version *string `protobuf:"bytes,2,opt,name=version" json:"version,omitempty"` - Instances *int64 `protobuf:"varint,3,req,name=instances" json:"instances,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *SetNumInstancesRequest) Reset() { *m = SetNumInstancesRequest{} } -func (m *SetNumInstancesRequest) String() string { return proto.CompactTextString(m) } -func (*SetNumInstancesRequest) ProtoMessage() {} - -func (m *SetNumInstancesRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -func (m *SetNumInstancesRequest) GetVersion() string { - if m != nil && m.Version != nil { - return *m.Version - } - return "" -} - -func (m *SetNumInstancesRequest) GetInstances() int64 { - if m != nil && m.Instances != nil { - return *m.Instances - } - return 0 -} - -type SetNumInstancesResponse struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *SetNumInstancesResponse) Reset() { *m = SetNumInstancesResponse{} } -func (m *SetNumInstancesResponse) String() string { return proto.CompactTextString(m) } -func (*SetNumInstancesResponse) ProtoMessage() {} - -type StartModuleRequest struct { - Module *string `protobuf:"bytes,1,req,name=module" json:"module,omitempty"` - Version *string `protobuf:"bytes,2,req,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *StartModuleRequest) Reset() { *m = StartModuleRequest{} } -func (m *StartModuleRequest) String() string { return proto.CompactTextString(m) } -func (*StartModuleRequest) ProtoMessage() {} - -func (m *StartModuleRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -func (m *StartModuleRequest) GetVersion() string { - if m != nil && m.Version != nil { - return *m.Version - } - return "" -} - -type StartModuleResponse struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *StartModuleResponse) Reset() { *m = StartModuleResponse{} } -func (m *StartModuleResponse) String() string { return proto.CompactTextString(m) } -func (*StartModuleResponse) ProtoMessage() {} - -type StopModuleRequest struct { - Module *string `protobuf:"bytes,1,opt,name=module" json:"module,omitempty"` - Version *string `protobuf:"bytes,2,opt,name=version" json:"version,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *StopModuleRequest) Reset() { *m = StopModuleRequest{} } -func (m *StopModuleRequest) String() string { return proto.CompactTextString(m) } -func (*StopModuleRequest) ProtoMessage() {} - -func (m *StopModuleRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -func (m *StopModuleRequest) GetVersion() string { - if m != nil && m.Version != nil { - return *m.Version - } - return "" -} - -type StopModuleResponse struct { - XXX_unrecognized []byte `json:"-"` -} - -func (m *StopModuleResponse) Reset() { *m = StopModuleResponse{} } -func (m *StopModuleResponse) String() string { return proto.CompactTextString(m) } -func (*StopModuleResponse) ProtoMessage() {} - -type GetHostnameRequest struct { - Module *string `protobuf:"bytes,1,opt,name=module" json:"module,omitempty"` - Version *string `protobuf:"bytes,2,opt,name=version" json:"version,omitempty"` - Instance *string `protobuf:"bytes,3,opt,name=instance" json:"instance,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetHostnameRequest) Reset() { *m = GetHostnameRequest{} } -func (m *GetHostnameRequest) String() string { return proto.CompactTextString(m) } -func (*GetHostnameRequest) ProtoMessage() {} - -func (m *GetHostnameRequest) GetModule() string { - if m != nil && m.Module != nil { - return *m.Module - } - return "" -} - -func (m *GetHostnameRequest) GetVersion() string { - if m != nil && m.Version != nil { - return *m.Version - } - return "" -} - -func (m *GetHostnameRequest) GetInstance() string { - if m != nil && m.Instance != nil { - return *m.Instance - } - return "" -} - -type GetHostnameResponse struct { - Hostname *string `protobuf:"bytes,1,req,name=hostname" json:"hostname,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *GetHostnameResponse) Reset() { *m = GetHostnameResponse{} } -func (m *GetHostnameResponse) String() string { return proto.CompactTextString(m) } -func (*GetHostnameResponse) ProtoMessage() {} - -func (m *GetHostnameResponse) GetHostname() string { - if m != nil && m.Hostname != nil { - return *m.Hostname - } - return "" -} - -func init() { -} diff --git a/vendor/google.golang.org/appengine/internal/modules/modules_service.proto b/vendor/google.golang.org/appengine/internal/modules/modules_service.proto deleted file mode 100644 index d29f0065a2f807b59ec5e3a6a381137ec54acc3d..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/modules/modules_service.proto +++ /dev/null @@ -1,80 +0,0 @@ -syntax = "proto2"; -option go_package = "modules"; - -package appengine; - -message ModulesServiceError { - enum ErrorCode { - OK = 0; - INVALID_MODULE = 1; - INVALID_VERSION = 2; - INVALID_INSTANCES = 3; - TRANSIENT_ERROR = 4; - UNEXPECTED_STATE = 5; - } -} - -message GetModulesRequest { -} - -message GetModulesResponse { - repeated string module = 1; -} - -message GetVersionsRequest { - optional string module = 1; -} - -message GetVersionsResponse { - repeated string version = 1; -} - -message GetDefaultVersionRequest { - optional string module = 1; -} - -message GetDefaultVersionResponse { - required string version = 1; -} - -message GetNumInstancesRequest { - optional string module = 1; - optional string version = 2; -} - -message GetNumInstancesResponse { - required int64 instances = 1; -} - -message SetNumInstancesRequest { - optional string module = 1; - optional string version = 2; - required int64 instances = 3; -} - -message SetNumInstancesResponse {} - -message StartModuleRequest { - required string module = 1; - required string version = 2; -} - -message StartModuleResponse {} - -message StopModuleRequest { - optional string module = 1; - optional string version = 2; -} - -message StopModuleResponse {} - -message GetHostnameRequest { - optional string module = 1; - optional string version = 2; - optional string instance = 3; -} - -message GetHostnameResponse { - required string hostname = 1; -} - diff --git a/vendor/google.golang.org/appengine/internal/net.go b/vendor/google.golang.org/appengine/internal/net.go deleted file mode 100644 index 3b94cf0c6a8b1bb56666dfffff19620aa7cd2bf7..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/net.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2014 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package internal - -// This file implements a network dialer that limits the number of concurrent connections. -// It is only used for API calls. - -import ( - "log" - "net" - "runtime" - "sync" - "time" -) - -var limitSem = make(chan int, 100) // TODO(dsymonds): Use environment variable. - -func limitRelease() { - // non-blocking - select { - case <-limitSem: - default: - // This should not normally happen. - log.Print("appengine: unbalanced limitSem release!") - } -} - -func limitDial(network, addr string) (net.Conn, error) { - limitSem <- 1 - - // Dial with a timeout in case the API host is MIA. - // The connection should normally be very fast. - conn, err := net.DialTimeout(network, addr, 500*time.Millisecond) - if err != nil { - limitRelease() - return nil, err - } - lc := &limitConn{Conn: conn} - runtime.SetFinalizer(lc, (*limitConn).Close) // shouldn't usually be required - return lc, nil -} - -type limitConn struct { - close sync.Once - net.Conn -} - -func (lc *limitConn) Close() error { - defer lc.close.Do(func() { - limitRelease() - runtime.SetFinalizer(lc, nil) - }) - return lc.Conn.Close() -} diff --git a/vendor/google.golang.org/appengine/internal/regen.sh b/vendor/google.golang.org/appengine/internal/regen.sh deleted file mode 100755 index 2fdb546a63335a08a0c82688066c80291a02a112..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/regen.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -e -# -# This script rebuilds the generated code for the protocol buffers. -# To run this you will need protoc and goprotobuf installed; -# see https://github.com/golang/protobuf for instructions. - -PKG=google.golang.org/appengine - -function die() { - echo 1>&2 $* - exit 1 -} - -# Sanity check that the right tools are accessible. -for tool in go protoc protoc-gen-go; do - q=$(which $tool) || die "didn't find $tool" - echo 1>&2 "$tool: $q" -done - -echo -n 1>&2 "finding package dir... " -pkgdir=$(go list -f '{{.Dir}}' $PKG) -echo 1>&2 $pkgdir -base=$(echo $pkgdir | sed "s,/$PKG\$,,") -echo 1>&2 "base: $base" -cd $base - -# Run protoc once per package. -for dir in $(find $PKG/internal -name '*.proto' | xargs dirname | sort | uniq); do - echo 1>&2 "* $dir" - protoc --go_out=. $dir/*.proto -done - -for f in $(find $PKG/internal -name '*.pb.go'); do - # Remove proto.RegisterEnum calls. - # These cause duplicate registration panics when these packages - # are used on classic App Engine. proto.RegisterEnum only affects - # parsing the text format; we don't care about that. - # https://code.google.com/p/googleappengine/issues/detail?id=11670#c17 - sed -i '/proto.RegisterEnum/d' $f -done diff --git a/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go b/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go deleted file mode 100644 index 526bd39e6d1a23bd69e999e1349d89e5bbbd69ab..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go +++ /dev/null @@ -1,231 +0,0 @@ -// Code generated by protoc-gen-go. -// source: google.golang.org/appengine/internal/remote_api/remote_api.proto -// DO NOT EDIT! - -/* -Package remote_api is a generated protocol buffer package. - -It is generated from these files: - google.golang.org/appengine/internal/remote_api/remote_api.proto - -It has these top-level messages: - Request - ApplicationError - RpcError - Response -*/ -package remote_api - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -type RpcError_ErrorCode int32 - -const ( - RpcError_UNKNOWN RpcError_ErrorCode = 0 - RpcError_CALL_NOT_FOUND RpcError_ErrorCode = 1 - RpcError_PARSE_ERROR RpcError_ErrorCode = 2 - RpcError_SECURITY_VIOLATION RpcError_ErrorCode = 3 - RpcError_OVER_QUOTA RpcError_ErrorCode = 4 - RpcError_REQUEST_TOO_LARGE RpcError_ErrorCode = 5 - RpcError_CAPABILITY_DISABLED RpcError_ErrorCode = 6 - RpcError_FEATURE_DISABLED RpcError_ErrorCode = 7 - RpcError_BAD_REQUEST RpcError_ErrorCode = 8 - RpcError_RESPONSE_TOO_LARGE RpcError_ErrorCode = 9 - RpcError_CANCELLED RpcError_ErrorCode = 10 - RpcError_REPLAY_ERROR RpcError_ErrorCode = 11 - RpcError_DEADLINE_EXCEEDED RpcError_ErrorCode = 12 -) - -var RpcError_ErrorCode_name = map[int32]string{ - 0: "UNKNOWN", - 1: "CALL_NOT_FOUND", - 2: "PARSE_ERROR", - 3: "SECURITY_VIOLATION", - 4: "OVER_QUOTA", - 5: "REQUEST_TOO_LARGE", - 6: "CAPABILITY_DISABLED", - 7: "FEATURE_DISABLED", - 8: "BAD_REQUEST", - 9: "RESPONSE_TOO_LARGE", - 10: "CANCELLED", - 11: "REPLAY_ERROR", - 12: "DEADLINE_EXCEEDED", -} -var RpcError_ErrorCode_value = map[string]int32{ - "UNKNOWN": 0, - "CALL_NOT_FOUND": 1, - "PARSE_ERROR": 2, - "SECURITY_VIOLATION": 3, - "OVER_QUOTA": 4, - "REQUEST_TOO_LARGE": 5, - "CAPABILITY_DISABLED": 6, - "FEATURE_DISABLED": 7, - "BAD_REQUEST": 8, - "RESPONSE_TOO_LARGE": 9, - "CANCELLED": 10, - "REPLAY_ERROR": 11, - "DEADLINE_EXCEEDED": 12, -} - -func (x RpcError_ErrorCode) Enum() *RpcError_ErrorCode { - p := new(RpcError_ErrorCode) - *p = x - return p -} -func (x RpcError_ErrorCode) String() string { - return proto.EnumName(RpcError_ErrorCode_name, int32(x)) -} -func (x *RpcError_ErrorCode) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(RpcError_ErrorCode_value, data, "RpcError_ErrorCode") - if err != nil { - return err - } - *x = RpcError_ErrorCode(value) - return nil -} - -type Request struct { - ServiceName *string `protobuf:"bytes,2,req,name=service_name" json:"service_name,omitempty"` - Method *string `protobuf:"bytes,3,req,name=method" json:"method,omitempty"` - Request []byte `protobuf:"bytes,4,req,name=request" json:"request,omitempty"` - RequestId *string `protobuf:"bytes,5,opt,name=request_id" json:"request_id,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} - -func (m *Request) GetServiceName() string { - if m != nil && m.ServiceName != nil { - return *m.ServiceName - } - return "" -} - -func (m *Request) GetMethod() string { - if m != nil && m.Method != nil { - return *m.Method - } - return "" -} - -func (m *Request) GetRequest() []byte { - if m != nil { - return m.Request - } - return nil -} - -func (m *Request) GetRequestId() string { - if m != nil && m.RequestId != nil { - return *m.RequestId - } - return "" -} - -type ApplicationError struct { - Code *int32 `protobuf:"varint,1,req,name=code" json:"code,omitempty"` - Detail *string `protobuf:"bytes,2,req,name=detail" json:"detail,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *ApplicationError) Reset() { *m = ApplicationError{} } -func (m *ApplicationError) String() string { return proto.CompactTextString(m) } -func (*ApplicationError) ProtoMessage() {} - -func (m *ApplicationError) GetCode() int32 { - if m != nil && m.Code != nil { - return *m.Code - } - return 0 -} - -func (m *ApplicationError) GetDetail() string { - if m != nil && m.Detail != nil { - return *m.Detail - } - return "" -} - -type RpcError struct { - Code *int32 `protobuf:"varint,1,req,name=code" json:"code,omitempty"` - Detail *string `protobuf:"bytes,2,opt,name=detail" json:"detail,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *RpcError) Reset() { *m = RpcError{} } -func (m *RpcError) String() string { return proto.CompactTextString(m) } -func (*RpcError) ProtoMessage() {} - -func (m *RpcError) GetCode() int32 { - if m != nil && m.Code != nil { - return *m.Code - } - return 0 -} - -func (m *RpcError) GetDetail() string { - if m != nil && m.Detail != nil { - return *m.Detail - } - return "" -} - -type Response struct { - Response []byte `protobuf:"bytes,1,opt,name=response" json:"response,omitempty"` - Exception []byte `protobuf:"bytes,2,opt,name=exception" json:"exception,omitempty"` - ApplicationError *ApplicationError `protobuf:"bytes,3,opt,name=application_error" json:"application_error,omitempty"` - JavaException []byte `protobuf:"bytes,4,opt,name=java_exception" json:"java_exception,omitempty"` - RpcError *RpcError `protobuf:"bytes,5,opt,name=rpc_error" json:"rpc_error,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Response) Reset() { *m = Response{} } -func (m *Response) String() string { return proto.CompactTextString(m) } -func (*Response) ProtoMessage() {} - -func (m *Response) GetResponse() []byte { - if m != nil { - return m.Response - } - return nil -} - -func (m *Response) GetException() []byte { - if m != nil { - return m.Exception - } - return nil -} - -func (m *Response) GetApplicationError() *ApplicationError { - if m != nil { - return m.ApplicationError - } - return nil -} - -func (m *Response) GetJavaException() []byte { - if m != nil { - return m.JavaException - } - return nil -} - -func (m *Response) GetRpcError() *RpcError { - if m != nil { - return m.RpcError - } - return nil -} - -func init() { -} diff --git a/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto b/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto deleted file mode 100644 index f21763a4e239ad1ef2daf053725b521d7989e71a..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto +++ /dev/null @@ -1,44 +0,0 @@ -syntax = "proto2"; -option go_package = "remote_api"; - -package remote_api; - -message Request { - required string service_name = 2; - required string method = 3; - required bytes request = 4; - optional string request_id = 5; -} - -message ApplicationError { - required int32 code = 1; - required string detail = 2; -} - -message RpcError { - enum ErrorCode { - UNKNOWN = 0; - CALL_NOT_FOUND = 1; - PARSE_ERROR = 2; - SECURITY_VIOLATION = 3; - OVER_QUOTA = 4; - REQUEST_TOO_LARGE = 5; - CAPABILITY_DISABLED = 6; - FEATURE_DISABLED = 7; - BAD_REQUEST = 8; - RESPONSE_TOO_LARGE = 9; - CANCELLED = 10; - REPLAY_ERROR = 11; - DEADLINE_EXCEEDED = 12; - } - required int32 code = 1; - optional string detail = 2; -} - -message Response { - optional bytes response = 1; - optional bytes exception = 2; - optional ApplicationError application_error = 3; - optional bytes java_exception = 4; - optional RpcError rpc_error = 5; -} diff --git a/vendor/google.golang.org/appengine/internal/transaction.go b/vendor/google.golang.org/appengine/internal/transaction.go deleted file mode 100644 index 28a6d181206149a9e856ac43ce470645268c4dcb..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/internal/transaction.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2014 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package internal - -// This file implements hooks for applying datastore transactions. - -import ( - "errors" - "reflect" - - "github.com/golang/protobuf/proto" - netcontext "golang.org/x/net/context" - - basepb "google.golang.org/appengine/internal/base" - pb "google.golang.org/appengine/internal/datastore" -) - -var transactionSetters = make(map[reflect.Type]reflect.Value) - -// RegisterTransactionSetter registers a function that sets transaction information -// in a protocol buffer message. f should be a function with two arguments, -// the first being a protocol buffer type, and the second being *datastore.Transaction. -func RegisterTransactionSetter(f interface{}) { - v := reflect.ValueOf(f) - transactionSetters[v.Type().In(0)] = v -} - -// applyTransaction applies the transaction t to message pb -// by using the relevant setter passed to RegisterTransactionSetter. -func applyTransaction(pb proto.Message, t *pb.Transaction) { - v := reflect.ValueOf(pb) - if f, ok := transactionSetters[v.Type()]; ok { - f.Call([]reflect.Value{v, reflect.ValueOf(t)}) - } -} - -var transactionKey = "used for *Transaction" - -func transactionFromContext(ctx netcontext.Context) *transaction { - t, _ := ctx.Value(&transactionKey).(*transaction) - return t -} - -func withTransaction(ctx netcontext.Context, t *transaction) netcontext.Context { - return netcontext.WithValue(ctx, &transactionKey, t) -} - -type transaction struct { - transaction pb.Transaction - finished bool -} - -var ErrConcurrentTransaction = errors.New("internal: concurrent transaction") - -func RunTransactionOnce(c netcontext.Context, f func(netcontext.Context) error, xg bool) error { - if transactionFromContext(c) != nil { - return errors.New("nested transactions are not supported") - } - - // Begin the transaction. - t := &transaction{} - req := &pb.BeginTransactionRequest{ - App: proto.String(FullyQualifiedAppID(c)), - } - if xg { - req.AllowMultipleEg = proto.Bool(true) - } - if err := Call(c, "datastore_v3", "BeginTransaction", req, &t.transaction); err != nil { - return err - } - - // Call f, rolling back the transaction if f returns a non-nil error, or panics. - // The panic is not recovered. - defer func() { - if t.finished { - return - } - t.finished = true - // Ignore the error return value, since we are already returning a non-nil - // error (or we're panicking). - Call(c, "datastore_v3", "Rollback", &t.transaction, &basepb.VoidProto{}) - }() - if err := f(withTransaction(c, t)); err != nil { - return err - } - t.finished = true - - // Commit the transaction. - res := &pb.CommitResponse{} - err := Call(c, "datastore_v3", "Commit", &t.transaction, res) - if ae, ok := err.(*APIError); ok { - /* TODO: restore this conditional - if appengine.IsDevAppServer() { - */ - // The Python Dev AppServer raises an ApplicationError with error code 2 (which is - // Error.CONCURRENT_TRANSACTION) and message "Concurrency exception.". - if ae.Code == int32(pb.Error_BAD_REQUEST) && ae.Detail == "ApplicationError: 2 Concurrency exception." { - return ErrConcurrentTransaction - } - if ae.Code == int32(pb.Error_CONCURRENT_TRANSACTION) { - return ErrConcurrentTransaction - } - } - return err -} diff --git a/vendor/google.golang.org/appengine/namespace.go b/vendor/google.golang.org/appengine/namespace.go deleted file mode 100644 index 21860ca08227cde4901f65c0cd82520537d18f68..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/namespace.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2012 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package appengine - -import ( - "fmt" - "regexp" - - "golang.org/x/net/context" - - "google.golang.org/appengine/internal" -) - -// Namespace returns a replacement context that operates within the given namespace. -func Namespace(c context.Context, namespace string) (context.Context, error) { - if !validNamespace.MatchString(namespace) { - return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", namespace, validNamespace) - } - return internal.NamespacedContext(c, namespace), nil -} - -// validNamespace matches valid namespace names. -var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`) diff --git a/vendor/google.golang.org/appengine/timeout.go b/vendor/google.golang.org/appengine/timeout.go deleted file mode 100644 index 05642a992a39eeed3662519c08dd4937f09d6a6c..0000000000000000000000000000000000000000 --- a/vendor/google.golang.org/appengine/timeout.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2013 Google Inc. All rights reserved. -// Use of this source code is governed by the Apache 2.0 -// license that can be found in the LICENSE file. - -package appengine - -import "golang.org/x/net/context" - -// IsTimeoutError reports whether err is a timeout error. -func IsTimeoutError(err error) bool { - if err == context.DeadlineExceeded { - return true - } - if t, ok := err.(interface { - IsTimeout() bool - }); ok { - return t.IsTimeout() - } - return false -} diff --git a/vendor/vendor.json b/vendor/vendor.json index 68e3e8c59e9267f804a1182f599b4fa6e157c81a..192b038101f0788c497ed6c8ba586de8dc158b70 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -532,12 +532,6 @@ "revision": "f6abca593680b2315d2075e0f5e2a9751e3f431a", "revisionTime": "2017-06-01T20:57:54Z" }, - { - "checksumSHA1": "zHXKW3VTfu4Dswo3GTsCGVCZuw4=", - "path": "github.com/strickyak/jsonnet_cgo", - "revision": "04f8990f6dd09242167d7320e3267a4326ffdcfb", - "revisionTime": "2017-06-22T22:16:47Z" - }, { "checksumSHA1": "MxLnUmfrP+r5HfCZM29+WPKebn8=", "path": "github.com/ugorji/go/codec", @@ -790,54 +784,6 @@ "revision": "9b61fcc4c548d69663d915801fc4b42a43b6cd9c", "revisionTime": "2017-10-24T20:47:09Z" }, - { - "checksumSHA1": "WPEbk80NB3Esdh4Yk0PXr2K7xVU=", - "path": "google.golang.org/appengine", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "/XD6hF+tqSNrfPrFmukDeHKFVVA=", - "path": "google.golang.org/appengine/internal", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "x6Thdfyasqd68dWZWqzWWeIfAfI=", - "path": "google.golang.org/appengine/internal/app_identity", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "TsNO8P0xUlLNyh3Ic/tzSp/fDWM=", - "path": "google.golang.org/appengine/internal/base", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "5QsV5oLGSfKZqTCVXP6NRz5T4Tw=", - "path": "google.golang.org/appengine/internal/datastore", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "Gep2T9zmVYV8qZfK2gu3zrmG6QE=", - "path": "google.golang.org/appengine/internal/log", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "eLZVX1EHLclFtQnjDIszsdyWRHo=", - "path": "google.golang.org/appengine/internal/modules", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, - { - "checksumSHA1": "a1XY7rz3BieOVqVI2Et6rKiwQCk=", - "path": "google.golang.org/appengine/internal/remote_api", - "revision": "d9a072cfa7b9736e44311ef77b3e09d804bfa599", - "revisionTime": "2017-08-14T19:09:42Z" - }, { "checksumSHA1": "6f8MEU31llHM1sLM/GGH4/Qxu0A=", "path": "gopkg.in/inf.v0",