How to use Type method of result Package

Best Testkube code snippet using result.Type

eval.go

Source:eval.go Github

copy

Full Screen

...47// debug.Value in program.go.48//49// If an evaluation results in an error, the zero value of result is used.50type result struct {51 d dwarf.Type52 v interface{}53}54// untInt is an untyped integer constant55type untInt struct {56 *big.Int57}58// untRune is an untyped rune constant59type untRune struct {60 *big.Int61}62// untFloat is an untyped floating-point constant63type untFloat struct {64 *big.Float65}66// untComplex is an untyped complex constant67type untComplex struct {68 r *big.Float69 i *big.Float70}71// untString is an untyped string constant72type untString string73// pointerToValue is a pointer to a value in memory.74// The evaluator constructs these as the result of address operations like "&x".75// Unlike debug.Pointer, the DWARF type stored alongside values of this type76// is the type of the variable, not the type of the pointer.77type pointerToValue struct {78 a uint6479}80// addressableValue is the memory location of a value.81// The evaluator constructs these while evaluating the operands of address82// operations like "&x", instead of computing the value of x itself.83type addressableValue struct {84 a uint6485}86// A sliceOf is a slice created by slicing an array.87// Unlike debug.Slice, the DWARF type stored alongside a value of this type is88// the type of the slice's elements, not the type of the slice.89type sliceOf debug.Slice90// ident is a value for representing a special identifier.91type ident string92// identLookup is a built-in function of the expression evaluator which gets the93// value of a global symbol.94var identLookup ident = "lookup"95// evalExpression evaluates a Go expression.96// If the program counter and stack pointer are nonzero, they are used to determine97// what local variables are available and where in memory they are.98func (s *Server) evalExpression(expression string, pc, sp uint64) (debug.Value, error) {99 e := evaluator{server: s, expression: expression, pc: pc, sp: sp}100 node, err := parser.ParseExpr(expression)101 if err != nil {102 return nil, err103 }104 val := e.evalNode(node, false)105 if e.evalError != nil {106 return nil, e.evalError107 }108 // Convert untyped constants to their default types.109 switch v := val.v.(type) {110 case untInt:111 return e.intFromInteger(v)112 case untRune:113 if v.Cmp(bigIntMaxInt32) == +1 {114 return nil, errors.New("constant overflows rune")115 }116 if v.Cmp(bigIntMinInt32) == -1 {117 return nil, errors.New("constant overflows rune")118 }119 return int32(v.Int64()), nil120 case untFloat:121 f, _ := v.Float64()122 if math.IsInf(f, 0) {123 return nil, errors.New("constant overflows float64")124 }125 if math.IsNaN(f) {126 return nil, errors.New("constant is NaN")127 }128 return f, nil129 case untComplex:130 r, _ := v.r.Float64()131 i, _ := v.i.Float64()132 if math.IsInf(r, 0) || math.IsInf(i, 0) {133 return nil, errors.New("constant overflows complex128")134 }135 if math.IsNaN(r) || math.IsNaN(i) {136 return nil, errors.New("constant is NaN")137 }138 return complex(r, i), nil139 case untString:140 return debug.String{Length: uint64(len(v)), String: string(v)}, nil141 case pointerToValue:142 return debug.Pointer{TypeID: uint64(val.d.Common().Offset), Address: v.a}, nil143 case sliceOf:144 return debug.Slice(v), nil145 case nil, addressableValue:146 // This case should not be reachable.147 return nil, errors.New("unknown error")148 }149 return val.v, nil150}151type evaluator struct {152 // expression is the expression being evaluated.153 expression string154 // server interacts with the program being debugged.155 server *Server156 // curNode is the current parse tree node. This is set so that error messages157 // can quote the part of the expression that caused an error.158 curNode ast.Node159 // evalError is the first error that occurred while evaluating the expression,160 // or nil if no error has occurred.161 evalError error162 // pc and sp are the current program counter and stack pointer, used for163 // finding local variables. If either are zero, the expression is evaluated164 // without using local variables.165 pc uint64166 sp uint64167}168// setNode sets curNode, and returns curNode's previous value.169func (e *evaluator) setNode(node ast.Node) (old ast.Node) {170 old, e.curNode = e.curNode, node171 return old172}173// err saves an error that occurred during evaluation.174// It returns a zero result, so that functions can exit and set an error with175// return e.err(...)176func (e *evaluator) err(s string) result {177 if e.evalError != nil {178 return result{}179 }180 // Append the substring of the expression that corresponds to the current AST node.181 start := int(e.curNode.Pos() - 1)182 end := int(e.curNode.End() - 1)183 if start < 0 {184 start = 0185 }186 if end > len(e.expression) {187 end = len(e.expression)188 }189 if start > end {190 start, end = 0, 0191 }192 e.evalError = errors.New(s + `: "` + e.expression[start:end] + `"`)193 return result{}194}195// evalNode computes the value of a node in the expression tree.196// If getAddress is true, the node is the argument of an & operator, so evalNode197// will return a result with a value of type addressableValue if possible.198func (e *evaluator) evalNode(node ast.Node, getAddress bool) result {199 // Set the current node in the evaluator, so that error messages can refer to200 // it. Defer a function call that changes it back.201 defer e.setNode(e.setNode(node))202 switch n := node.(type) {203 case *ast.Ident:204 if e.pc != 0 && e.sp != 0 {205 a, t := e.server.findLocalVar(n.Name, e.pc, e.sp)206 if t != nil {207 return e.resultFrom(a, t, getAddress)208 }209 }210 a, t := e.server.findGlobalVar(n.Name)211 if t != nil {212 return e.resultFrom(a, t, getAddress)213 }214 switch n.Name {215 // Note: these could have been redefined as constants in the code, but we216 // don't have a way to detect that.217 case "true":218 return result{nil, true}219 case "false":220 return result{nil, false}221 case "lookup":222 return result{nil, identLookup}223 }224 return e.err("unknown identifier")225 case *ast.BasicLit:226 switch n.Kind {227 case token.INT:228 i := new(big.Int)229 if _, ok := i.SetString(n.Value, 0); !ok {230 return e.err("invalid integer constant")231 }232 return result{nil, untInt{i}}233 case token.FLOAT:234 r, _, err := big.ParseFloat(n.Value, 10, prec, big.ToNearestEven)235 if err != nil {236 return e.err(err.Error())237 }238 return result{nil, untFloat{r}}239 case token.IMAG:240 if len(n.Value) <= 1 || n.Value[len(n.Value)-1] != 'i' {241 return e.err("invalid imaginary constant")242 }243 r, _, err := big.ParseFloat(n.Value[:len(n.Value)-1], 10, prec, big.ToNearestEven)244 if err != nil {245 return e.err(err.Error())246 }247 return result{nil, untComplex{new(big.Float), r}}248 case token.CHAR:249 // TODO: unescaping250 return result{nil, untRune{new(big.Int).SetInt64(int64(n.Value[1]))}}251 case token.STRING:252 // TODO: unescaping253 if len(n.Value) <= 1 {254 return e.err("invalid string constant")255 }256 return result{nil, untString(n.Value[1 : len(n.Value)-1])}257 }258 case *ast.ParenExpr:259 return e.evalNode(n.X, getAddress)260 case *ast.StarExpr:261 x := e.evalNode(n.X, false)262 switch v := x.v.(type) {263 case debug.Pointer:264 // x.d may be a typedef pointing to a pointer type (or a typedef pointing265 // to a typedef pointing to a pointer type, etc.), so remove typedefs266 // until we get the underlying pointer type.267 t := followTypedefs(x.d)268 if pt, ok := t.(*dwarf.PtrType); ok {269 return e.resultFrom(v.Address, pt.Type, getAddress)270 } else {271 return e.err("invalid DWARF type for pointer")272 }273 case pointerToValue:274 return e.resultFrom(v.a, x.d, getAddress)275 case nil:276 return x277 }278 return e.err("invalid indirect")279 case *ast.SelectorExpr:280 x := e.evalNode(n.X, false)281 sel := n.Sel.Name282 switch v := x.v.(type) {283 case debug.Struct:284 for _, f := range v.Fields {285 if f.Name == sel {286 t, err := e.server.dwarfData.Type(dwarf.Offset(f.Var.TypeID))287 if err != nil {288 return e.err(err.Error())289 }290 return e.resultFrom(f.Var.Address, t, getAddress)291 }292 }293 return e.err("struct field not found")294 case debug.Pointer:295 pt, ok := followTypedefs(x.d).(*dwarf.PtrType) // x.d should be a pointer to struct.296 if !ok {297 return e.err("invalid DWARF information for pointer")298 }299 st, ok := followTypedefs(pt.Type).(*dwarf.StructType)300 if !ok {301 break302 }303 for _, f := range st.Field {304 if f.Name == sel {305 return e.resultFrom(v.Address+uint64(f.ByteOffset), f.Type, getAddress)306 }307 }308 return e.err("struct field not found")309 case pointerToValue:310 st, ok := followTypedefs(x.d).(*dwarf.StructType) // x.d should be a struct.311 if !ok {312 break313 }314 for _, f := range st.Field {315 if f.Name == sel {316 return e.resultFrom(v.a+uint64(f.ByteOffset), f.Type, getAddress)317 }318 }319 return e.err("struct field not found")320 }321 return e.err("invalid selector expression")322 case *ast.IndexExpr:323 x, index := e.evalNode(n.X, false), e.evalNode(n.Index, false)324 if x.v == nil || index.v == nil {325 return result{}326 }327 // The expression is x[index]328 if m, ok := x.v.(debug.Map); ok {329 if getAddress {330 return e.err("can't take address of map value")331 }332 mt, ok := followTypedefs(x.d).(*dwarf.MapType)333 if !ok {334 return e.err("invalid DWARF type for map")335 }336 var (337 found bool // true if the key was found338 value result // the map value for the key339 abort bool // true if an error occurred while searching340 // fn is a function that checks if one (key, value) pair corresponds341 // to the index in the expression.342 fn = func(keyAddr, valAddr uint64, keyType, valType dwarf.Type) bool {343 key := e.resultFrom(keyAddr, keyType, false)344 if key.v == nil {345 abort = true346 return false // stop searching map347 }348 equal, ok := e.evalBinaryOp(token.EQL, index, key).v.(bool)349 if !ok {350 abort = true351 return false // stop searching map352 }353 if equal {354 found = true355 value = e.resultFrom(valAddr, valType, false)356 return false // stop searching map357 }358 return true // continue searching map359 }360 )361 if err := e.server.peekMapValues(mt, m.Address, fn); err != nil {362 return e.err(err.Error())363 }364 if abort {365 // Some operation on individual map keys failed.366 return result{}367 }368 if found {369 return value370 }371 // The key wasn't in the map; return the zero value.372 return e.zero(mt.ElemType)373 }374 // The index should be a non-negative integer for the remaining cases.375 u, err := uint64FromResult(index)376 if err != nil {377 return e.err("invalid index: " + err.Error())378 }379 switch v := x.v.(type) {380 case debug.Array:381 if u >= v.Length {382 return e.err("array index out of bounds")383 }384 elemType, err := e.server.dwarfData.Type(dwarf.Offset(v.ElementTypeID))385 if err != nil {386 return e.err(err.Error())387 }388 return e.resultFrom(v.Element(u).Address, elemType, getAddress)389 case debug.Slice:390 if u >= v.Length {391 return e.err("slice index out of bounds")392 }393 elemType, err := e.server.dwarfData.Type(dwarf.Offset(v.ElementTypeID))394 if err != nil {395 return e.err(err.Error())396 }397 return e.resultFrom(v.Element(u).Address, elemType, getAddress)398 case sliceOf:399 if u >= v.Length {400 return e.err("slice index out of bounds")401 }402 return e.resultFrom(v.Element(u).Address, x.d, getAddress)403 case debug.String:404 if getAddress {405 return e.err("can't take address of string element")406 }407 if u >= v.Length {408 return e.err("string index out of bounds")409 }410 if u >= uint64(len(v.String)) {411 return e.err("string element unavailable")412 }413 return e.uint8Result(v.String[u])414 case untString:415 if getAddress {416 return e.err("can't take address of string element")417 }418 if u >= uint64(len(v)) {419 return e.err("string index out of bounds")420 }421 return e.uint8Result(v[u])422 }423 return e.err("invalid index expression")424 case *ast.SliceExpr:425 if n.Slice3 && n.High == nil {426 return e.err("middle index required in full slice")427 }428 if n.Slice3 && n.Max == nil {429 return e.err("final index required in full slice")430 }431 var (432 low, high, max uint64433 err error434 )435 if n.Low != nil {436 low, err = uint64FromResult(e.evalNode(n.Low, false))437 if err != nil {438 return e.err("invalid slice lower bound: " + err.Error())439 }440 }441 if n.High != nil {442 high, err = uint64FromResult(e.evalNode(n.High, false))443 if err != nil {444 return e.err("invalid slice upper bound: " + err.Error())445 }446 }447 if n.Max != nil {448 max, err = uint64FromResult(e.evalNode(n.Max, false))449 if err != nil {450 return e.err("invalid slice capacity: " + err.Error())451 }452 }453 x := e.evalNode(n.X, false)454 switch v := x.v.(type) {455 case debug.Array, debug.Pointer, pointerToValue:456 // This case handles the slicing of arrays and pointers to arrays.457 var arr debug.Array458 switch v := x.v.(type) {459 case debug.Array:460 arr = v461 case debug.Pointer:462 pt, ok := followTypedefs(x.d).(*dwarf.PtrType)463 if !ok {464 return e.err("invalid DWARF type for pointer")465 }466 a := e.resultFrom(v.Address, pt.Type, false)467 arr, ok = a.v.(debug.Array)468 if !ok {469 // v is a pointer to something other than an array.470 return e.err("cannot slice pointer")471 }472 case pointerToValue:473 a := e.resultFrom(v.a, x.d, false)474 var ok bool475 arr, ok = a.v.(debug.Array)476 if !ok {477 // v is a pointer to something other than an array.478 return e.err("cannot slice pointer")479 }480 }481 elemType, err := e.server.dwarfData.Type(dwarf.Offset(arr.ElementTypeID))482 if err != nil {483 return e.err(err.Error())484 }485 if n.High == nil {486 high = arr.Length487 } else if high > arr.Length {488 return e.err("slice upper bound is too large")489 }490 if n.Max == nil {491 max = arr.Length492 } else if max > arr.Length {493 return e.err("slice capacity is too large")494 }495 if low > high || high > max {496 return e.err("invalid slice index")497 }498 return result{499 d: elemType,500 v: sliceOf{501 Array: debug.Array{502 ElementTypeID: arr.ElementTypeID,503 Address: arr.Element(low).Address,504 Length: high - low,505 StrideBits: uint64(elemType.Common().ByteSize) * 8,506 },507 Capacity: max - low,508 },509 }510 case debug.Slice:511 if n.High == nil {512 high = v.Length513 } else if high > v.Capacity {514 return e.err("slice upper bound is too large")515 }516 if n.Max == nil {517 max = v.Capacity518 } else if max > v.Capacity {519 return e.err("slice capacity is too large")520 }521 if low > high || high > max {522 return e.err("invalid slice index")523 }524 v.Address += low * (v.StrideBits / 8)525 v.Length = high - low526 v.Capacity = max - low527 return result{x.d, v}528 case sliceOf:529 if n.High == nil {530 high = v.Length531 } else if high > v.Capacity {532 return e.err("slice upper bound is too large")533 }534 if n.Max == nil {535 max = v.Capacity536 } else if max > v.Capacity {537 return e.err("slice capacity is too large")538 }539 if low > high || high > max {540 return e.err("invalid slice index")541 }542 v.Address += low * (v.StrideBits / 8)543 v.Length = high - low544 v.Capacity = max - low545 return result{x.d, v}546 case debug.String:547 if n.Max != nil {548 return e.err("full slice of string")549 }550 if n.High == nil {551 high = v.Length552 }553 if low > high || high > v.Length {554 return e.err("invalid slice index")555 }556 v.Length = high - low557 if low > uint64(len(v.String)) {558 // v.String was truncated before the point where this slice starts.559 v.String = ""560 } else {561 if high > uint64(len(v.String)) {562 // v.String was truncated before the point where this slice ends.563 high = uint64(len(v.String))564 }565 v.String = v.String[low:high]566 }567 return result{x.d, v}568 case untString:569 if n.Max != nil {570 return e.err("full slice of string")571 }572 if n.High == nil {573 high = uint64(len(v))574 }575 if low > high {576 return e.err("invalid slice expression")577 }578 if high > uint64(len(v)) {579 return e.err("slice upper bound is too large")580 }581 return e.stringResult(string(v[low:high]))582 default:583 return e.err("invalid slice expression")584 }585 case *ast.CallExpr:586 // Only supports lookup("x"), which gets the value of a global symbol x.587 fun := e.evalNode(n.Fun, false)588 var args []result589 for _, a := range n.Args {590 args = append(args, e.evalNode(a, false))591 }592 if fun.v == identLookup {593 if len(args) != 1 {594 return e.err("lookup should have one argument")595 }596 ident, ok := args[0].v.(untString)597 if !ok {598 return e.err("argument for lookup should be a string constant")599 }600 if a, t := e.server.findGlobalVar(string(ident)); t == nil {601 return e.err("symbol not found")602 } else {603 return e.resultFrom(a, t, getAddress)604 }605 }606 return e.err("function calls not implemented")607 case *ast.UnaryExpr:608 if n.Op == token.AND {609 x := e.evalNode(n.X, true)610 switch v := x.v.(type) {611 case addressableValue:612 return result{x.d, pointerToValue{v.a}}613 case nil:614 return x615 }616 return e.err("can't take address")617 }618 x := e.evalNode(n.X, false)619 if x.v == nil {620 return x621 }622 switch v := x.v.(type) {623 case int8:624 switch n.Op {625 case token.ADD:626 case token.SUB:627 v = -v628 case token.XOR:629 v = ^v630 default:631 return e.err("invalid operation")632 }633 return result{x.d, v}634 case int16:635 switch n.Op {636 case token.ADD:637 case token.SUB:638 v = -v639 case token.XOR:640 v = ^v641 default:642 return e.err("invalid operation")643 }644 return result{x.d, v}645 case int32:646 switch n.Op {647 case token.ADD:648 case token.SUB:649 v = -v650 case token.XOR:651 v = ^v652 default:653 return e.err("invalid operation")654 }655 return result{x.d, v}656 case int64:657 switch n.Op {658 case token.ADD:659 case token.SUB:660 v = -v661 case token.XOR:662 v = ^v663 default:664 return e.err("invalid operation")665 }666 return result{x.d, v}667 case uint8:668 switch n.Op {669 case token.ADD:670 case token.SUB:671 v = -v672 case token.XOR:673 v = ^v674 default:675 return e.err("invalid operation")676 }677 return result{x.d, v}678 case uint16:679 switch n.Op {680 case token.ADD:681 case token.SUB:682 v = -v683 case token.XOR:684 v = ^v685 default:686 return e.err("invalid operation")687 }688 return result{x.d, v}689 case uint32:690 switch n.Op {691 case token.ADD:692 case token.SUB:693 v = -v694 case token.XOR:695 v = ^v696 default:697 return e.err("invalid operation")698 }699 return result{x.d, v}700 case uint64:701 switch n.Op {702 case token.ADD:703 case token.SUB:704 v = -v705 case token.XOR:706 v = ^v707 default:708 return e.err("invalid operation")709 }710 return result{x.d, v}711 case float32:712 switch n.Op {713 case token.ADD:714 case token.SUB:715 v = -v716 default:717 return e.err("invalid operation")718 }719 return result{x.d, v}720 case float64:721 switch n.Op {722 case token.ADD:723 case token.SUB:724 v = -v725 default:726 return e.err("invalid operation")727 }728 return result{x.d, v}729 case complex64:730 switch n.Op {731 case token.ADD:732 case token.SUB:733 v = -v734 default:735 return e.err("invalid operation")736 }737 return result{x.d, v}738 case complex128:739 switch n.Op {740 case token.ADD:741 case token.SUB:742 v = -v743 default:744 return e.err("invalid operation")745 }746 return result{x.d, v}747 case untInt:748 switch n.Op {749 case token.ADD:750 case token.SUB:751 v.Int.Neg(v.Int)752 case token.XOR:753 v.Int.Not(v.Int)754 default:755 return e.err("invalid operation")756 }757 return result{x.d, v}758 case untRune:759 switch n.Op {760 case token.ADD:761 case token.SUB:762 v.Int.Neg(v.Int)763 case token.XOR:764 v.Int.Not(v.Int)765 default:766 return e.err("invalid operation")767 }768 return result{x.d, v}769 case untFloat:770 switch n.Op {771 case token.ADD:772 case token.SUB:773 v.Float.Neg(v.Float)774 default:775 return e.err("invalid operation")776 }777 return result{x.d, v}778 case untComplex:779 switch n.Op {780 case token.ADD:781 case token.SUB:782 v.r.Neg(v.r)783 v.i.Neg(v.i)784 default:785 return e.err("invalid operation")786 }787 return result{x.d, v}788 case bool:789 switch n.Op {790 case token.NOT:791 v = !v792 default:793 return e.err("invalid operation")794 }795 return result{x.d, v}796 }797 case *ast.BinaryExpr:798 x := e.evalNode(n.X, false)799 if x.v == nil {800 return x801 }802 y := e.evalNode(n.Y, false)803 if y.v == nil {804 return y805 }806 return e.evalBinaryOp(n.Op, x, y)807 }808 return e.err("invalid expression")809}810// evalBinaryOp evaluates a binary operator op applied to x and y.811func (e *evaluator) evalBinaryOp(op token.Token, x, y result) result {812 if op == token.NEQ {813 tmp := e.evalBinaryOp(token.EQL, x, y)814 b, ok := tmp.v.(bool)815 if !ok {816 return tmp817 }818 return result{nil, !b}819 }820 if op == token.GTR {821 return e.evalBinaryOp(token.LSS, y, x)822 }823 if op == token.GEQ {824 return e.evalBinaryOp(token.LEQ, x, y)825 }826 x = convertUntyped(x, y)827 y = convertUntyped(y, x)828 switch a := x.v.(type) {829 case int8:830 b, ok := y.v.(int8)831 if !ok {832 return e.err("type mismatch")833 }834 var c int8835 switch op {836 case token.EQL:837 return result{nil, a == b}838 case token.LSS:839 return result{nil, a < b}840 case token.LEQ:841 return result{nil, a <= b}842 case token.ADD:843 c = a + b844 case token.SUB:845 c = a - b846 case token.OR:847 c = a | b848 case token.XOR:849 c = a ^ b850 case token.MUL:851 c = a * b852 case token.QUO:853 if b == 0 {854 return e.err("integer divide by zero")855 }856 c = a / b857 case token.REM:858 if b == 0 {859 return e.err("integer divide by zero")860 }861 c = a % b862 case token.AND:863 c = a & b864 case token.AND_NOT:865 c = a &^ b866 default:867 return e.err("invalid operation")868 }869 return result{x.d, c}870 case int16:871 b, ok := y.v.(int16)872 if !ok {873 return e.err("type mismatch")874 }875 var c int16876 switch op {877 case token.EQL:878 return result{nil, a == b}879 case token.LSS:880 return result{nil, a < b}881 case token.LEQ:882 return result{nil, a <= b}883 case token.ADD:884 c = a + b885 case token.SUB:886 c = a - b887 case token.OR:888 c = a | b889 case token.XOR:890 c = a ^ b891 case token.MUL:892 c = a * b893 case token.QUO:894 if b == 0 {895 return e.err("integer divide by zero")896 }897 c = a / b898 case token.REM:899 if b == 0 {900 return e.err("integer divide by zero")901 }902 c = a % b903 case token.AND:904 c = a & b905 case token.AND_NOT:906 c = a &^ b907 default:908 return e.err("invalid operation")909 }910 return result{x.d, c}911 case int32:912 b, ok := y.v.(int32)913 if !ok {914 return e.err("type mismatch")915 }916 var c int32917 switch op {918 case token.EQL:919 return result{nil, a == b}920 case token.LSS:921 return result{nil, a < b}922 case token.LEQ:923 return result{nil, a <= b}924 case token.ADD:925 c = a + b926 case token.SUB:927 c = a - b928 case token.OR:929 c = a | b930 case token.XOR:931 c = a ^ b932 case token.MUL:933 c = a * b934 case token.QUO:935 if b == 0 {936 return e.err("integer divide by zero")937 }938 c = a / b939 case token.REM:940 if b == 0 {941 return e.err("integer divide by zero")942 }943 c = a % b944 case token.AND:945 c = a & b946 case token.AND_NOT:947 c = a &^ b948 default:949 return e.err("invalid operation")950 }951 return result{x.d, c}952 case int64:953 b, ok := y.v.(int64)954 if !ok {955 return e.err("type mismatch")956 }957 var c int64958 switch op {959 case token.EQL:960 return result{nil, a == b}961 case token.LSS:962 return result{nil, a < b}963 case token.LEQ:964 return result{nil, a <= b}965 case token.ADD:966 c = a + b967 case token.SUB:968 c = a - b969 case token.OR:970 c = a | b971 case token.XOR:972 c = a ^ b973 case token.MUL:974 c = a * b975 case token.QUO:976 if b == 0 {977 return e.err("integer divide by zero")978 }979 c = a / b980 case token.REM:981 if b == 0 {982 return e.err("integer divide by zero")983 }984 c = a % b985 case token.AND:986 c = a & b987 case token.AND_NOT:988 c = a &^ b989 default:990 return e.err("invalid operation")991 }992 return result{x.d, c}993 case uint8:994 b, ok := y.v.(uint8)995 if !ok {996 return e.err("type mismatch")997 }998 var c uint8999 switch op {1000 case token.EQL:1001 return result{nil, a == b}1002 case token.LSS:1003 return result{nil, a < b}1004 case token.LEQ:1005 return result{nil, a <= b}1006 case token.ADD:1007 c = a + b1008 case token.SUB:1009 c = a - b1010 case token.OR:1011 c = a | b1012 case token.XOR:1013 c = a ^ b1014 case token.MUL:1015 c = a * b1016 case token.QUO:1017 if b == 0 {1018 return e.err("integer divide by zero")1019 }1020 c = a / b1021 case token.REM:1022 if b == 0 {1023 return e.err("integer divide by zero")1024 }1025 c = a % b1026 case token.AND:1027 c = a & b1028 case token.AND_NOT:1029 c = a &^ b1030 default:1031 return e.err("invalid operation")1032 }1033 return result{x.d, c}1034 case uint16:1035 b, ok := y.v.(uint16)1036 if !ok {1037 return e.err("type mismatch")1038 }1039 var c uint161040 switch op {1041 case token.EQL:1042 return result{nil, a == b}1043 case token.LSS:1044 return result{nil, a < b}1045 case token.LEQ:1046 return result{nil, a <= b}1047 case token.ADD:1048 c = a + b1049 case token.SUB:1050 c = a - b1051 case token.OR:1052 c = a | b1053 case token.XOR:1054 c = a ^ b1055 case token.MUL:1056 c = a * b1057 case token.QUO:1058 if b == 0 {1059 return e.err("integer divide by zero")1060 }1061 c = a / b1062 case token.REM:1063 if b == 0 {1064 return e.err("integer divide by zero")1065 }1066 c = a % b1067 case token.AND:1068 c = a & b1069 case token.AND_NOT:1070 c = a &^ b1071 default:1072 return e.err("invalid operation")1073 }1074 return result{x.d, c}1075 case uint32:1076 b, ok := y.v.(uint32)1077 if !ok {1078 return e.err("type mismatch")1079 }1080 var c uint321081 switch op {1082 case token.EQL:1083 return result{nil, a == b}1084 case token.LSS:1085 return result{nil, a < b}1086 case token.LEQ:1087 return result{nil, a <= b}1088 case token.ADD:1089 c = a + b1090 case token.SUB:1091 c = a - b1092 case token.OR:1093 c = a | b1094 case token.XOR:1095 c = a ^ b1096 case token.MUL:1097 c = a * b1098 case token.QUO:1099 if b == 0 {1100 return e.err("integer divide by zero")1101 }1102 c = a / b1103 case token.REM:1104 if b == 0 {1105 return e.err("integer divide by zero")1106 }1107 c = a % b1108 case token.AND:1109 c = a & b1110 case token.AND_NOT:1111 c = a &^ b1112 default:1113 return e.err("invalid operation")1114 }1115 return result{x.d, c}1116 case uint64:1117 b, ok := y.v.(uint64)1118 if !ok {1119 return e.err("type mismatch")1120 }1121 var c uint641122 switch op {1123 case token.EQL:1124 return result{nil, a == b}1125 case token.LSS:1126 return result{nil, a < b}1127 case token.LEQ:1128 return result{nil, a <= b}1129 case token.ADD:1130 c = a + b1131 case token.SUB:1132 c = a - b1133 case token.OR:1134 c = a | b1135 case token.XOR:1136 c = a ^ b1137 case token.MUL:1138 c = a * b1139 case token.QUO:1140 if b == 0 {1141 return e.err("integer divide by zero")1142 }1143 c = a / b1144 case token.REM:1145 if b == 0 {1146 return e.err("integer divide by zero")1147 }1148 c = a % b1149 case token.AND:1150 c = a & b1151 case token.AND_NOT:1152 c = a &^ b1153 default:1154 return e.err("invalid operation")1155 }1156 return result{x.d, c}1157 case float32:1158 b, ok := y.v.(float32)1159 if !ok {1160 return e.err("type mismatch")1161 }1162 var c float321163 switch op {1164 case token.EQL:1165 return result{nil, a == b}1166 case token.LSS:1167 return result{nil, a < b}1168 case token.LEQ:1169 return result{nil, a <= b}1170 case token.ADD:1171 c = a + b1172 case token.SUB:1173 c = a - b1174 case token.MUL:1175 c = a * b1176 case token.QUO:1177 c = a / b1178 default:1179 return e.err("invalid operation")1180 }1181 return result{x.d, c}1182 case float64:1183 b, ok := y.v.(float64)1184 if !ok {1185 return e.err("type mismatch")1186 }1187 var c float641188 switch op {1189 case token.EQL:1190 return result{nil, a == b}1191 case token.LSS:1192 return result{nil, a < b}1193 case token.LEQ:1194 return result{nil, a <= b}1195 case token.ADD:1196 c = a + b1197 case token.SUB:1198 c = a - b1199 case token.MUL:1200 c = a * b1201 case token.QUO:1202 c = a / b1203 default:1204 return e.err("invalid operation")1205 }1206 return result{x.d, c}1207 case complex64:1208 b, ok := y.v.(complex64)1209 if !ok {1210 return e.err("type mismatch")1211 }1212 var c complex641213 switch op {1214 case token.EQL:1215 return result{nil, a == b}1216 case token.ADD:1217 c = a + b1218 case token.SUB:1219 c = a - b1220 case token.MUL:1221 c = a * b1222 case token.QUO:1223 c = a / b1224 default:1225 return e.err("invalid operation")1226 }1227 return result{x.d, c}1228 case complex128:1229 b, ok := y.v.(complex128)1230 if !ok {1231 return e.err("type mismatch")1232 }1233 var c complex1281234 switch op {1235 case token.EQL:1236 return result{nil, a == b}1237 case token.ADD:1238 c = a + b1239 case token.SUB:1240 c = a - b1241 case token.MUL:1242 c = a * b1243 case token.QUO:1244 c = a / b1245 default:1246 return e.err("invalid operation")1247 }1248 return result{x.d, c}1249 case bool:1250 b, ok := y.v.(bool)1251 if !ok {1252 return e.err("type mismatch")1253 }1254 var c bool1255 switch op {1256 case token.LOR:1257 c = a || b1258 case token.LAND:1259 c = a && b1260 case token.EQL:1261 c = a == b1262 default:1263 return e.err("invalid operation")1264 }1265 return result{x.d, c}1266 case debug.String:1267 b, ok := y.v.(debug.String)1268 if !ok {1269 return e.err("type mismatch")1270 }1271 var c debug.String1272 switch op {1273 // TODO: these comparison operators only use the part of the string that1274 // was read. Very large strings do not have their entire contents read by1275 // server.value.1276 case token.EQL:1277 return result{nil, a.Length == b.Length && a.String == b.String}1278 case token.LSS:1279 return result{nil, a.String < b.String}1280 case token.LEQ:1281 return result{nil, a.String <= b.String}1282 case token.ADD:1283 c.Length = a.Length + b.Length1284 if a.Length == uint64(len(a.String)) {1285 c.String = a.String + b.String1286 } else {1287 // The first string was truncated at a.Length characters, so the sum1288 // must be truncated there too.1289 c.String = a.String1290 }1291 default:1292 return e.err("invalid operation")1293 }1294 return result{x.d, c}1295 case untString:1296 b, ok := y.v.(untString)1297 if !ok {1298 return e.err("type mismatch")1299 }1300 var c untString1301 switch op {1302 case token.EQL:1303 return result{nil, a == b}1304 case token.LSS:1305 return result{nil, a < b}1306 case token.LEQ:1307 return result{nil, a <= b}1308 case token.ADD:1309 c = a + b1310 default:1311 return e.err("invalid operation")1312 }1313 return result{x.d, c}1314 case untInt:1315 i := a.Int1316 b, ok := y.v.(untInt)1317 if !ok {1318 return e.err("type mismatch")1319 }1320 switch op {1321 case token.EQL:1322 return result{nil, i.Cmp(b.Int) == 0}1323 case token.LSS:1324 return result{nil, i.Cmp(b.Int) < 0}1325 case token.LEQ:1326 return result{nil, i.Cmp(b.Int) <= 0}1327 }1328 c := new(big.Int)1329 switch op {1330 case token.ADD:1331 c.Add(i, b.Int)1332 case token.SUB:1333 c.Sub(i, b.Int)1334 case token.OR:1335 c.Or(i, b.Int)1336 case token.XOR:1337 c.Xor(i, b.Int)1338 case token.MUL:1339 c.Mul(i, b.Int)1340 case token.QUO:1341 if b.Sign() == 0 {1342 return e.err("integer divide by zero")1343 }1344 c.Quo(i, b.Int)1345 case token.REM:1346 if b.Sign() == 0 {1347 return e.err("integer divide by zero")1348 }1349 c.Mod(i, b.Int)1350 case token.AND:1351 c.And(i, b.Int)1352 case token.AND_NOT:1353 c.AndNot(i, b.Int)1354 default:1355 return e.err("invalid operation")1356 }1357 return result{nil, untInt{c}}1358 case untRune:1359 i := a.Int1360 b, ok := y.v.(untRune)1361 if !ok {1362 return e.err("type mismatch")1363 }1364 switch op {1365 case token.EQL:1366 return result{nil, i.Cmp(b.Int) == 0}1367 case token.LSS:1368 return result{nil, i.Cmp(b.Int) < 0}1369 case token.LEQ:1370 return result{nil, i.Cmp(b.Int) <= 0}1371 }1372 c := new(big.Int)1373 switch op {1374 case token.ADD:1375 c.Add(i, b.Int)1376 case token.SUB:1377 c.Sub(i, b.Int)1378 case token.OR:1379 c.Or(i, b.Int)1380 case token.XOR:1381 c.Xor(i, b.Int)1382 case token.MUL:1383 c.Mul(i, b.Int)1384 case token.QUO:1385 if b.Sign() == 0 {1386 return e.err("integer divide by zero")1387 }1388 c.Quo(i, b.Int)1389 case token.REM:1390 if b.Sign() == 0 {1391 return e.err("integer divide by zero")1392 }1393 c.Mod(i, b.Int)1394 case token.AND:1395 c.And(i, b.Int)1396 case token.AND_NOT:1397 c.AndNot(i, b.Int)1398 default:1399 return e.err("invalid operation")1400 }1401 return result{nil, untRune{c}}1402 case untFloat:1403 r := a.Float1404 b, ok := y.v.(untFloat)1405 if !ok {1406 return e.err("type mismatch")1407 }1408 switch op {1409 case token.EQL:1410 return result{nil, r.Cmp(b.Float) == 0}1411 case token.LSS:1412 return result{nil, r.Cmp(b.Float) < 0}1413 case token.LEQ:1414 return result{nil, r.Cmp(b.Float) <= 0}1415 }1416 c := new(big.Float)1417 switch op {1418 case token.ADD:1419 c.Add(r, b.Float)1420 case token.SUB:1421 c.Sub(r, b.Float)1422 case token.MUL:1423 c.Mul(r, b.Float)1424 case token.QUO:1425 if b.Sign() == 0 {1426 return e.err("divide by zero")1427 }1428 c.Quo(r, b.Float)1429 default:1430 return e.err("invalid operation")1431 }1432 return result{nil, untFloat{c}}1433 case untComplex:1434 b, ok := y.v.(untComplex)1435 if !ok {1436 return e.err("type mismatch")1437 }1438 var (1439 ar = a.r1440 br = b.r1441 ai = a.i1442 bi = b.i1443 )1444 if op == token.EQL {1445 return result{nil, ar.Cmp(br) == 0 && ai.Cmp(bi) == 0}1446 }1447 var (1448 cr = new(big.Float)1449 ci = new(big.Float)1450 )1451 switch op {1452 case token.ADD:1453 cr.Add(ar, br)1454 ci.Add(ai, bi)1455 case token.SUB:1456 cr.Sub(ar, br)1457 ci.Sub(ai, bi)1458 case token.MUL:1459 var t0, t1 big.Float1460 t0.Mul(ar, br)1461 t1.Mul(ai, bi)1462 cr.Sub(&t0, &t1)1463 t0.Mul(ar, bi)1464 t1.Mul(ai, br)1465 ci.Add(&t0, &t1)1466 case token.QUO:1467 // a/b = a*conj(b)/|b|^21468 var t0, t1 big.Float1469 cr.Mul(ar, br)1470 t0.Mul(ai, bi)1471 cr.Add(cr, &t0) // cr = Re(a*conj(b))1472 ci.Mul(ai, br)1473 t0.Mul(ar, bi)1474 ci.Sub(ci, &t0) // ci = Im(a*conj(b))1475 t0.Mul(br, br)1476 t1.Mul(bi, bi)1477 t0.Add(&t0, &t1) // t0 = |b|^21478 if t0.Sign() == 0 {1479 return e.err("divide by zero")1480 }1481 cr.Quo(cr, &t0) // cr = Re(a*conj(b))/|b|^2 = Re(a/b)1482 ci.Quo(ci, &t0) // ci = Im(a*conj(b))/|b|^2 = Im(a/b)1483 }1484 return result{nil, untComplex{cr, ci}}1485 }1486 return e.err("invalid operation")1487}1488// findLocalVar finds a local variable (or function parameter) by name, and1489// returns its address and DWARF type. It returns a nil type on failure.1490// The PC and SP are used to determine the current function and stack frame.1491func (s *Server) findLocalVar(name string, pc, sp uint64) (uint64, dwarf.Type) {1492 // Find the DWARF entry for the function at pc.1493 funcEntry, _, err := s.dwarfData.PCToFunction(uint64(pc))1494 if err != nil {1495 return 0, nil1496 }1497 // Compute the stack frame pointer.1498 fpOffset, err := s.dwarfData.PCToSPOffset(uint64(pc))1499 if err != nil {1500 return 0, nil1501 }1502 framePointer := sp + uint64(fpOffset)1503 // Check each child of the function's DWARF entry to see if it is a parameter1504 // or local variable with the right name. If so, return its address and type.1505 r := s.dwarfData.Reader()1506 r.Seek(funcEntry.Offset)1507 for {1508 varEntry, err := r.Next()1509 if err != nil {1510 break1511 }1512 if varEntry.Tag == 0 {1513 // This tag marks the end of the function's DWARF entry's children.1514 break1515 }1516 // Check this entry corresponds to a local variable or function parameter,1517 // that it has the correct name, and that we can get its type and location.1518 // If so, return them.1519 if varEntry.Tag != dwarf.TagFormalParameter && varEntry.Tag != dwarf.TagVariable {1520 continue1521 }1522 varName, ok := varEntry.Val(dwarf.AttrName).(string)1523 if !ok {1524 continue1525 }1526 if varName != name {1527 continue1528 }1529 varTypeOffset, ok := varEntry.Val(dwarf.AttrType).(dwarf.Offset)1530 if !ok {1531 continue1532 }1533 varType, err := s.dwarfData.Type(varTypeOffset)1534 if err != nil {1535 continue1536 }1537 locationAttribute := varEntry.Val(dwarf.AttrLocation)1538 if locationAttribute == nil {1539 continue1540 }1541 locationDescription, ok := locationAttribute.([]uint8)1542 if !ok {1543 continue1544 }1545 frameOffset, err := evalLocation(locationDescription)1546 if err != nil {1547 continue1548 }1549 return framePointer + uint64(frameOffset), varType1550 }1551 return 0, nil1552}1553// findGlobalVar finds a global variable by name, and returns its address and1554// DWARF type. It returns a nil type on failure.1555func (s *Server) findGlobalVar(name string) (uint64, dwarf.Type) {1556 entry, err := s.dwarfData.LookupVariable(name)1557 if err != nil {1558 return 0, nil1559 }1560 loc, err := s.dwarfData.EntryLocation(entry)1561 if err != nil {1562 return 0, nil1563 }1564 ofs, err := s.dwarfData.EntryTypeOffset(entry)1565 if err != nil {1566 return 0, nil1567 }1568 typ, err := s.dwarfData.Type(ofs)1569 if err != nil {1570 return 0, nil1571 }1572 return loc, typ1573}1574// intFromInteger converts an untyped integer constant to an int32 or int64,1575// depending on the int size of the debugged program.1576// It returns an error on overflow, or if it can't determine the int size.1577func (e *evaluator) intFromInteger(v untInt) (interface{}, error) {1578 t, ok := e.getBaseType("int")1579 if !ok {1580 return nil, errors.New("couldn't get int size from DWARF info")1581 }1582 switch t.Common().ByteSize {1583 case 4:1584 if v.Cmp(bigIntMaxInt32) == +1 || v.Cmp(bigIntMinInt32) == -1 {1585 return nil, errors.New("constant overflows int")1586 }1587 return int32(v.Int64()), nil1588 case 8:1589 if v.Cmp(bigIntMaxInt64) == +1 || v.Cmp(bigIntMinInt64) == -1 {1590 return nil, errors.New("constant overflows int")1591 }1592 return v.Int64(), nil1593 }1594 return nil, errors.New("invalid int size in DWARF info")1595}1596// uint8Result constructs a result for a uint8 value.1597func (e *evaluator) uint8Result(v uint8) result {1598 t, ok := e.getBaseType("uint8")1599 if !ok {1600 e.err("couldn't construct uint8")1601 }1602 return result{t, uint8(v)}1603}1604// stringResult constructs a result for a string value.1605func (e *evaluator) stringResult(s string) result {1606 t, ok := e.getBaseType("string")1607 if !ok {1608 e.err("couldn't construct string")1609 }1610 return result{t, debug.String{Length: uint64(len(s)), String: s}}1611}1612// getBaseType returns the *dwarf.Type with a given name.1613// TODO: cache this.1614func (e *evaluator) getBaseType(name string) (dwarf.Type, bool) {1615 entry, err := e.server.dwarfData.LookupEntry(name)1616 if err != nil {1617 return nil, false1618 }1619 t, err := e.server.dwarfData.Type(entry.Offset)1620 if err != nil {1621 return nil, false1622 }1623 return t, true1624}1625// resultFrom constructs a result corresponding to a value in the program with1626// the given address and DWARF type.1627// If getAddress is true, the result will be the operand of an address expression,1628// so resultFrom returns a result containing a value of type addressableValue.1629func (e *evaluator) resultFrom(a uint64, t dwarf.Type, getAddress bool) result {1630 if a == 0 {1631 return e.err("nil pointer dereference")1632 }1633 if getAddress {1634 return result{t, addressableValue{a}}1635 }1636 v, err := e.server.value(t, a)1637 if err != nil {1638 return e.err(err.Error())1639 }1640 return result{t, v}1641}1642// zero returns the zero value of type t.1643// TODO: implement for array and struct.1644func (e *evaluator) zero(t dwarf.Type) result {1645 var v interface{}1646 switch typ := followTypedefs(t).(type) {1647 case *dwarf.CharType, *dwarf.IntType, *dwarf.EnumType:1648 switch typ.Common().ByteSize {1649 case 1:1650 v = int8(0)1651 case 2:1652 v = int16(0)1653 case 4:1654 v = int32(0)1655 case 8:1656 v = int64(0)1657 default:1658 return e.err("invalid integer size " + fmt.Sprint(typ.Common().ByteSize))1659 }1660 case *dwarf.UcharType, *dwarf.UintType:1661 switch typ.Common().ByteSize {1662 case 1:1663 v = uint8(0)1664 case 2:1665 v = uint16(0)1666 case 4:1667 v = uint32(0)1668 case 8:1669 v = uint64(0)1670 default:1671 return e.err("invalid unsigned integer size " + fmt.Sprint(typ.Common().ByteSize))1672 }1673 case *dwarf.FloatType:1674 switch typ.Common().ByteSize {1675 case 4:1676 v = float32(0)1677 case 8:1678 v = float64(0)1679 default:1680 return e.err("invalid float size " + fmt.Sprint(typ.Common().ByteSize))1681 }1682 case *dwarf.ComplexType:1683 switch typ.Common().ByteSize {1684 case 8:1685 v = complex64(0)1686 case 16:1687 v = complex128(0)1688 default:1689 return e.err("invalid complex size " + fmt.Sprint(typ.Common().ByteSize))1690 }1691 case *dwarf.BoolType:1692 v = false1693 case *dwarf.PtrType:1694 v = debug.Pointer{TypeID: uint64(t.Common().Offset)}1695 case *dwarf.SliceType:1696 v = debug.Slice{1697 Array: debug.Array{1698 ElementTypeID: uint64(typ.ElemType.Common().Offset),1699 StrideBits: uint64(typ.ElemType.Common().ByteSize) * 8,1700 },1701 }1702 case *dwarf.StringType:1703 v = debug.String{}1704 case *dwarf.InterfaceType:1705 v = debug.Interface{}1706 case *dwarf.FuncType:1707 v = debug.Func{}1708 case *dwarf.MapType:1709 v = debug.Map{TypeID: uint64(t.Common().Offset)}1710 case *dwarf.ChanType:1711 v = debug.Channel{1712 ElementTypeID: uint64(typ.ElemType.Common().Offset),1713 Stride: uint64(typ.ElemType.Common().ByteSize),1714 }1715 default:1716 return e.err("can't get zero value of this type")1717 }1718 return result{t, v}1719}1720// convertUntyped converts x to be the same type as y, if x is untyped and the1721// conversion is possible.1722//1723// An untyped bool can be converted to a boolean type.1724// An untyped string can be converted to a string type.1725// An untyped integer, rune, float or complex value can be converted to a1726// numeric type, or to an untyped value later in that list.1727//1728// x is returned unchanged if none of these cases apply.1729func convertUntyped(x, y result) result {1730 switch a := x.v.(type) {1731 case untInt:1732 i := a.Int1733 switch y.v.(type) {1734 case int8:1735 return result{y.d, int8(i.Int64())}1736 case int16:1737 return result{y.d, int16(i.Int64())}1738 case int32:1739 return result{y.d, int32(i.Int64())}1740 case int64:1741 return result{y.d, int64(i.Int64())}1742 case uint8:1743 return result{y.d, uint8(i.Uint64())}1744 case uint16:1745 return result{y.d, uint16(i.Uint64())}1746 case uint32:1747 return result{y.d, uint32(i.Uint64())}1748 case uint64:1749 return result{y.d, uint64(i.Uint64())}1750 case float32:1751 f, _ := new(big.Float).SetInt(i).Float32()1752 return result{y.d, f}1753 case float64:1754 f, _ := new(big.Float).SetInt(i).Float64()1755 return result{y.d, f}1756 case complex64:1757 f, _ := new(big.Float).SetInt(i).Float32()1758 return result{y.d, complex(f, 0)}1759 case complex128:1760 f, _ := new(big.Float).SetInt(i).Float64()1761 return result{y.d, complex(f, 0)}1762 case untRune:1763 return result{nil, untRune{i}}1764 case untFloat:1765 return result{nil, untFloat{new(big.Float).SetPrec(prec).SetInt(i)}}1766 case untComplex:1767 return result{nil, untComplex{new(big.Float).SetPrec(prec).SetInt(i), new(big.Float)}}1768 }1769 case untRune:1770 i := a.Int1771 switch y.v.(type) {1772 case int8:1773 return result{y.d, int8(i.Int64())}1774 case int16:1775 return result{y.d, int16(i.Int64())}1776 case int32:1777 return result{y.d, int32(i.Int64())}1778 case int64:1779 return result{y.d, int64(i.Int64())}1780 case uint8:1781 return result{y.d, uint8(i.Uint64())}1782 case uint16:1783 return result{y.d, uint16(i.Uint64())}1784 case uint32:1785 return result{y.d, uint32(i.Uint64())}1786 case uint64:1787 return result{y.d, uint64(i.Uint64())}1788 case float32:1789 f, _ := new(big.Float).SetInt(i).Float32()1790 return result{y.d, f}1791 case float64:1792 f, _ := new(big.Float).SetInt(i).Float64()1793 return result{y.d, f}1794 case complex64:1795 f, _ := new(big.Float).SetInt(i).Float32()1796 return result{y.d, complex(f, 0)}1797 case complex128:1798 f, _ := new(big.Float).SetInt(i).Float64()1799 return result{y.d, complex(f, 0)}1800 case untRune:1801 return result{nil, untRune{i}}1802 case untFloat:1803 return result{nil, untFloat{new(big.Float).SetPrec(prec).SetInt(i)}}1804 case untComplex:1805 return result{nil, untComplex{new(big.Float).SetPrec(prec).SetInt(i), new(big.Float)}}1806 }1807 case untFloat:1808 if a.IsInt() {1809 i, _ := a.Int(nil)1810 switch y.v.(type) {1811 case int8:1812 return result{y.d, int8(i.Int64())}1813 case int16:1814 return result{y.d, int16(i.Int64())}1815 case int32:1816 return result{y.d, int32(i.Int64())}1817 case int64:1818 return result{y.d, int64(i.Int64())}1819 case uint8:1820 return result{y.d, uint8(i.Uint64())}1821 case uint16:1822 return result{y.d, uint16(i.Uint64())}1823 case uint32:1824 return result{y.d, uint32(i.Uint64())}1825 case uint64:1826 return result{y.d, uint64(i.Uint64())}1827 }1828 }1829 switch y.v.(type) {1830 case float32:1831 f, _ := a.Float32()1832 return result{y.d, float32(f)}1833 case float64:1834 f, _ := a.Float64()1835 return result{y.d, float64(f)}1836 case complex64:1837 f, _ := a.Float32()1838 return result{y.d, complex(f, 0)}1839 case complex128:1840 f, _ := a.Float64()1841 return result{y.d, complex(f, 0)}1842 case untComplex:1843 return result{nil, untComplex{a.Float, new(big.Float)}}1844 }1845 case untComplex:1846 if a.i.Sign() == 0 {1847 // a is a real number.1848 if a.r.IsInt() {1849 // a is an integer.1850 i, _ := a.r.Int(nil)1851 switch y.v.(type) {1852 case int8:1853 return result{y.d, int8(i.Int64())}1854 case int16:1855 return result{y.d, int16(i.Int64())}1856 case int32:1857 return result{y.d, int32(i.Int64())}1858 case int64:1859 return result{y.d, int64(i.Int64())}1860 case uint8:1861 return result{y.d, uint8(i.Uint64())}1862 case uint16:1863 return result{y.d, uint16(i.Uint64())}1864 case uint32:1865 return result{y.d, uint32(i.Uint64())}1866 case uint64:1867 return result{y.d, uint64(i.Uint64())}1868 }1869 }1870 switch y.v.(type) {1871 case float32:1872 f, _ := a.r.Float32()1873 return result{y.d, float32(f)}1874 case float64:1875 f, _ := a.r.Float64()1876 return result{y.d, float64(f)}1877 }1878 }1879 switch y.v.(type) {1880 case complex64:1881 r, _ := a.r.Float32()1882 i, _ := a.i.Float32()1883 return result{y.d, complex(r, i)}1884 case complex128:1885 r, _ := a.r.Float64()1886 i, _ := a.i.Float64()1887 return result{y.d, complex(r, i)}1888 }1889 case bool:1890 if x.d != nil {1891 // x is a typed bool, not an untyped bool.1892 break1893 }1894 switch y.v.(type) {1895 case bool:1896 return result{y.d, bool(a)}1897 }1898 case untString:1899 switch y.v.(type) {1900 case debug.String:1901 return result{y.d, debug.String{Length: uint64(len(a)), String: string(a)}}1902 }1903 }1904 return x1905}1906// uint64FromResult converts a result into a uint64 for slice or index expressions.1907// It returns an error if the conversion cannot be done.1908func uint64FromResult(x result) (uint64, error) {1909 switch v := x.v.(type) {1910 case int8:1911 if v < 0 {1912 return 0, errors.New("value is negative")1913 }1914 return uint64(v), nil1915 case int16:1916 if v < 0 {1917 return 0, errors.New("value is negative")1918 }1919 return uint64(v), nil1920 case int32:1921 if v < 0 {1922 return 0, errors.New("value is negative")1923 }1924 return uint64(v), nil1925 case int64:1926 if v < 0 {1927 return 0, errors.New("value is negative")1928 }1929 return uint64(v), nil1930 case uint8:1931 return uint64(v), nil1932 case uint16:1933 return uint64(v), nil1934 case uint32:1935 return uint64(v), nil1936 case uint64:1937 return v, nil1938 case untInt:1939 if v.Int.Sign() == -1 {1940 return 0, errors.New("value is negative")1941 }1942 if v.Int.Cmp(bigIntMaxUint64) == +1 {1943 return 0, errors.New("value is too large")1944 }1945 return v.Int.Uint64(), nil1946 case untRune:1947 if v.Sign() == -1 {1948 return 0, errors.New("value is negative")1949 }1950 if v.Cmp(bigIntMaxUint64) == +1 {1951 return 0, errors.New("value is too large")1952 }1953 return v.Uint64(), nil1954 case untFloat:1955 if !v.IsInt() {1956 return 0, errors.New("value is not an integer")1957 }1958 if v.Sign() == -1 {1959 return 0, errors.New("value is negative")1960 }1961 i, _ := v.Int(nil)1962 if i.Cmp(bigIntMaxUint64) == +1 {1963 return 0, errors.New("value is too large")1964 }1965 return i.Uint64(), nil1966 case untComplex:1967 if v.i.Sign() != 0 {1968 return 0, errors.New("value is complex")1969 }1970 if !v.r.IsInt() {1971 return 0, errors.New("value is not an integer")1972 }1973 if v.r.Sign() == -1 {1974 return 0, errors.New("value is negative")1975 }1976 i, _ := v.r.Int(nil)1977 if i.Cmp(bigIntMaxUint64) == +1 {1978 return 0, errors.New("value is too large")1979 }1980 return i.Uint64(), nil1981 }1982 return 0, fmt.Errorf("cannot convert to unsigned integer")1983}1984// followTypedefs returns the underlying type of t, removing any typedefs.1985// If t leads to a cycle of typedefs, followTypedefs returns nil.1986func followTypedefs(t dwarf.Type) dwarf.Type {1987 // If t is a *dwarf.TypedefType, next returns t.Type, otherwise it returns t.1988 // The bool returned is true when the argument was a typedef.1989 next := func(t dwarf.Type) (dwarf.Type, bool) {1990 tt, ok := t.(*dwarf.TypedefType)1991 if !ok {1992 return t, false1993 }1994 return tt.Type, true1995 }1996 // Advance two pointers, one at twice the speed, so we can detect if we get1997 // stuck in a cycle.1998 slow, fast := t, t1999 for {2000 var wasTypedef bool2001 fast, wasTypedef = next(fast)2002 if !wasTypedef {2003 return fast2004 }2005 fast, wasTypedef = next(fast)2006 if !wasTypedef {2007 return fast2008 }2009 slow, _ = next(slow)2010 if slow == fast {2011 return nil2012 }2013 }2014}...

Full Screen

Full Screen

consensus.go

Source:consensus.go Github

copy

Full Screen

1/* ----------------------------------------------------------------------------2 * This file was automatically generated by SWIG (http://www.swig.org).3 * Version 3.0.84 *5 * This file is not intended to be easily readable and contains a number of6 * coding conventions designed to improve portability and efficiency. Do not make7 * changes to this file unless you know what you are doing--modify the SWIG8 * interface file instead.9 * ----------------------------------------------------------------------------- */10// source: consensus.swg11package consensus12/*13#define intgo swig_intgo14typedef void *swig_voidp;15#include <stdint.h>16typedef int intgo;17typedef unsigned int uintgo;18typedef struct { char *p; intgo n; } _gostring_;19typedef struct { void* array; intgo len; intgo cap; } _goslice_;20typedef long long swig_type_1;21typedef long long swig_type_2;22extern void _wrap_Swig_free_consensus_0731991c73947514(uintptr_t arg1);23extern swig_intgo _wrap_verify_result_eval_false_consensus_0731991c73947514(void);24extern swig_intgo _wrap_verify_result_eval_true_consensus_0731991c73947514(void);25extern swig_intgo _wrap_verify_result_script_size_consensus_0731991c73947514(void);26extern swig_intgo _wrap_verify_result_push_size_consensus_0731991c73947514(void);27extern swig_intgo _wrap_verify_result_op_count_consensus_0731991c73947514(void);28extern swig_intgo _wrap_verify_result_stack_size_consensus_0731991c73947514(void);29extern swig_intgo _wrap_verify_result_sig_count_consensus_0731991c73947514(void);30extern swig_intgo _wrap_verify_result_pubkey_count_consensus_0731991c73947514(void);31extern swig_intgo _wrap_verify_result_verify_consensus_0731991c73947514(void);32extern swig_intgo _wrap_verify_result_equalverify_consensus_0731991c73947514(void);33extern swig_intgo _wrap_verify_result_checkmultisigverify_consensus_0731991c73947514(void);34extern swig_intgo _wrap_verify_result_checksigverify_consensus_0731991c73947514(void);35extern swig_intgo _wrap_verify_result_numequalverify_consensus_0731991c73947514(void);36extern swig_intgo _wrap_verify_result_bad_opcode_consensus_0731991c73947514(void);37extern swig_intgo _wrap_verify_result_disabled_opcode_consensus_0731991c73947514(void);38extern swig_intgo _wrap_verify_result_invalid_stack_operation_consensus_0731991c73947514(void);39extern swig_intgo _wrap_verify_result_invalid_altstack_operation_consensus_0731991c73947514(void);40extern swig_intgo _wrap_verify_result_unbalanced_conditional_consensus_0731991c73947514(void);41extern swig_intgo _wrap_verify_result_sig_hashtype_consensus_0731991c73947514(void);42extern swig_intgo _wrap_verify_result_sig_der_consensus_0731991c73947514(void);43extern swig_intgo _wrap_verify_result_minimaldata_consensus_0731991c73947514(void);44extern swig_intgo _wrap_verify_result_sig_pushonly_consensus_0731991c73947514(void);45extern swig_intgo _wrap_verify_result_sig_high_s_consensus_0731991c73947514(void);46extern swig_intgo _wrap_verify_result_sig_nulldummy_consensus_0731991c73947514(void);47extern swig_intgo _wrap_verify_result_pubkeytype_consensus_0731991c73947514(void);48extern swig_intgo _wrap_verify_result_cleanstack_consensus_0731991c73947514(void);49extern swig_intgo _wrap_verify_result_discourage_upgradable_nops_consensus_0731991c73947514(void);50extern swig_intgo _wrap_verify_result_op_return_consensus_0731991c73947514(void);51extern swig_intgo _wrap_verify_result_unknown_error_consensus_0731991c73947514(void);52extern swig_intgo _wrap_verify_result_tx_invalid_consensus_0731991c73947514(void);53extern swig_intgo _wrap_verify_result_tx_size_invalid_consensus_0731991c73947514(void);54extern swig_intgo _wrap_verify_result_tx_input_invalid_consensus_0731991c73947514(void);55extern swig_intgo _wrap_verify_result_negative_locktime_consensus_0731991c73947514(void);56extern swig_intgo _wrap_verify_result_unsatisfied_locktime_consensus_0731991c73947514(void);57extern swig_intgo _wrap_verify_flags_none_consensus_0731991c73947514(void);58extern swig_intgo _wrap_verify_flags_p2sh_consensus_0731991c73947514(void);59extern swig_intgo _wrap_verify_flags_strictenc_consensus_0731991c73947514(void);60extern swig_intgo _wrap_verify_flags_dersig_consensus_0731991c73947514(void);61extern swig_intgo _wrap_verify_flags_low_s_consensus_0731991c73947514(void);62extern swig_intgo _wrap_verify_flags_nulldummy_consensus_0731991c73947514(void);63extern swig_intgo _wrap_verify_flags_sigpushonly_consensus_0731991c73947514(void);64extern swig_intgo _wrap_verify_flags_minimaldata_consensus_0731991c73947514(void);65extern swig_intgo _wrap_verify_flags_discourage_upgradable_nops_consensus_0731991c73947514(void);66extern swig_intgo _wrap_verify_flags_cleanstack_consensus_0731991c73947514(void);67extern swig_intgo _wrap_verify_flags_checklocktimeverify_consensus_0731991c73947514(void);68extern swig_intgo _wrap_verify_script_consensus_0731991c73947514(swig_voidp arg1, swig_type_1 arg2, swig_voidp arg3, swig_type_2 arg4, swig_intgo arg5, swig_intgo arg6);69#undef intgo70*/71import "C"72import "unsafe"73import _ "runtime/cgo"74import "sync"75type _ unsafe.Pointer76var Swig_escape_always_false bool77var Swig_escape_val interface{}78type _swig_fnptr *byte79type _swig_memberptr *byte80type _ sync.Mutex81func Swig_free(arg1 uintptr) {82 _swig_i_0 := arg183 C._wrap_Swig_free_consensus_0731991c73947514(C.uintptr_t(_swig_i_0))84}85const LIBBITCOIN_CONSENSUS_VERSION string = "2.0.0"86const LIBBITCOIN_CONSENSUS_MAJOR_VERSION int = 287const LIBBITCOIN_CONSENSUS_MINOR_VERSION int = 088const LIBBITCOIN_CONSENSUS_PATCH_VERSION int = 089type LibbitcoinConsensusVerify_result_type int90func _swig_getverify_result_eval_false() (_swig_ret LibbitcoinConsensusVerify_result_type) {91 var swig_r LibbitcoinConsensusVerify_result_type92 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_eval_false_consensus_0731991c73947514())93 return swig_r94}95var Verify_result_eval_false LibbitcoinConsensusVerify_result_type = _swig_getverify_result_eval_false()96func _swig_getverify_result_eval_true() (_swig_ret LibbitcoinConsensusVerify_result_type) {97 var swig_r LibbitcoinConsensusVerify_result_type98 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_eval_true_consensus_0731991c73947514())99 return swig_r100}101var Verify_result_eval_true LibbitcoinConsensusVerify_result_type = _swig_getverify_result_eval_true()102func _swig_getverify_result_script_size() (_swig_ret LibbitcoinConsensusVerify_result_type) {103 var swig_r LibbitcoinConsensusVerify_result_type104 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_script_size_consensus_0731991c73947514())105 return swig_r106}107var Verify_result_script_size LibbitcoinConsensusVerify_result_type = _swig_getverify_result_script_size()108func _swig_getverify_result_push_size() (_swig_ret LibbitcoinConsensusVerify_result_type) {109 var swig_r LibbitcoinConsensusVerify_result_type110 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_push_size_consensus_0731991c73947514())111 return swig_r112}113var Verify_result_push_size LibbitcoinConsensusVerify_result_type = _swig_getverify_result_push_size()114func _swig_getverify_result_op_count() (_swig_ret LibbitcoinConsensusVerify_result_type) {115 var swig_r LibbitcoinConsensusVerify_result_type116 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_op_count_consensus_0731991c73947514())117 return swig_r118}119var Verify_result_op_count LibbitcoinConsensusVerify_result_type = _swig_getverify_result_op_count()120func _swig_getverify_result_stack_size() (_swig_ret LibbitcoinConsensusVerify_result_type) {121 var swig_r LibbitcoinConsensusVerify_result_type122 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_stack_size_consensus_0731991c73947514())123 return swig_r124}125var Verify_result_stack_size LibbitcoinConsensusVerify_result_type = _swig_getverify_result_stack_size()126func _swig_getverify_result_sig_count() (_swig_ret LibbitcoinConsensusVerify_result_type) {127 var swig_r LibbitcoinConsensusVerify_result_type128 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_sig_count_consensus_0731991c73947514())129 return swig_r130}131var Verify_result_sig_count LibbitcoinConsensusVerify_result_type = _swig_getverify_result_sig_count()132func _swig_getverify_result_pubkey_count() (_swig_ret LibbitcoinConsensusVerify_result_type) {133 var swig_r LibbitcoinConsensusVerify_result_type134 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_pubkey_count_consensus_0731991c73947514())135 return swig_r136}137var Verify_result_pubkey_count LibbitcoinConsensusVerify_result_type = _swig_getverify_result_pubkey_count()138func _swig_getverify_result_verify() (_swig_ret LibbitcoinConsensusVerify_result_type) {139 var swig_r LibbitcoinConsensusVerify_result_type140 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_verify_consensus_0731991c73947514())141 return swig_r142}143var Verify_result_verify LibbitcoinConsensusVerify_result_type = _swig_getverify_result_verify()144func _swig_getverify_result_equalverify() (_swig_ret LibbitcoinConsensusVerify_result_type) {145 var swig_r LibbitcoinConsensusVerify_result_type146 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_equalverify_consensus_0731991c73947514())147 return swig_r148}149var Verify_result_equalverify LibbitcoinConsensusVerify_result_type = _swig_getverify_result_equalverify()150func _swig_getverify_result_checkmultisigverify() (_swig_ret LibbitcoinConsensusVerify_result_type) {151 var swig_r LibbitcoinConsensusVerify_result_type152 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_checkmultisigverify_consensus_0731991c73947514())153 return swig_r154}155var Verify_result_checkmultisigverify LibbitcoinConsensusVerify_result_type = _swig_getverify_result_checkmultisigverify()156func _swig_getverify_result_checksigverify() (_swig_ret LibbitcoinConsensusVerify_result_type) {157 var swig_r LibbitcoinConsensusVerify_result_type158 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_checksigverify_consensus_0731991c73947514())159 return swig_r160}161var Verify_result_checksigverify LibbitcoinConsensusVerify_result_type = _swig_getverify_result_checksigverify()162func _swig_getverify_result_numequalverify() (_swig_ret LibbitcoinConsensusVerify_result_type) {163 var swig_r LibbitcoinConsensusVerify_result_type164 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_numequalverify_consensus_0731991c73947514())165 return swig_r166}167var Verify_result_numequalverify LibbitcoinConsensusVerify_result_type = _swig_getverify_result_numequalverify()168func _swig_getverify_result_bad_opcode() (_swig_ret LibbitcoinConsensusVerify_result_type) {169 var swig_r LibbitcoinConsensusVerify_result_type170 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_bad_opcode_consensus_0731991c73947514())171 return swig_r172}173var Verify_result_bad_opcode LibbitcoinConsensusVerify_result_type = _swig_getverify_result_bad_opcode()174func _swig_getverify_result_disabled_opcode() (_swig_ret LibbitcoinConsensusVerify_result_type) {175 var swig_r LibbitcoinConsensusVerify_result_type176 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_disabled_opcode_consensus_0731991c73947514())177 return swig_r178}179var Verify_result_disabled_opcode LibbitcoinConsensusVerify_result_type = _swig_getverify_result_disabled_opcode()180func _swig_getverify_result_invalid_stack_operation() (_swig_ret LibbitcoinConsensusVerify_result_type) {181 var swig_r LibbitcoinConsensusVerify_result_type182 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_invalid_stack_operation_consensus_0731991c73947514())183 return swig_r184}185var Verify_result_invalid_stack_operation LibbitcoinConsensusVerify_result_type = _swig_getverify_result_invalid_stack_operation()186func _swig_getverify_result_invalid_altstack_operation() (_swig_ret LibbitcoinConsensusVerify_result_type) {187 var swig_r LibbitcoinConsensusVerify_result_type188 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_invalid_altstack_operation_consensus_0731991c73947514())189 return swig_r190}191var Verify_result_invalid_altstack_operation LibbitcoinConsensusVerify_result_type = _swig_getverify_result_invalid_altstack_operation()192func _swig_getverify_result_unbalanced_conditional() (_swig_ret LibbitcoinConsensusVerify_result_type) {193 var swig_r LibbitcoinConsensusVerify_result_type194 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_unbalanced_conditional_consensus_0731991c73947514())195 return swig_r196}197var Verify_result_unbalanced_conditional LibbitcoinConsensusVerify_result_type = _swig_getverify_result_unbalanced_conditional()198func _swig_getverify_result_sig_hashtype() (_swig_ret LibbitcoinConsensusVerify_result_type) {199 var swig_r LibbitcoinConsensusVerify_result_type200 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_sig_hashtype_consensus_0731991c73947514())201 return swig_r202}203var Verify_result_sig_hashtype LibbitcoinConsensusVerify_result_type = _swig_getverify_result_sig_hashtype()204func _swig_getverify_result_sig_der() (_swig_ret LibbitcoinConsensusVerify_result_type) {205 var swig_r LibbitcoinConsensusVerify_result_type206 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_sig_der_consensus_0731991c73947514())207 return swig_r208}209var Verify_result_sig_der LibbitcoinConsensusVerify_result_type = _swig_getverify_result_sig_der()210func _swig_getverify_result_minimaldata() (_swig_ret LibbitcoinConsensusVerify_result_type) {211 var swig_r LibbitcoinConsensusVerify_result_type212 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_minimaldata_consensus_0731991c73947514())213 return swig_r214}215var Verify_result_minimaldata LibbitcoinConsensusVerify_result_type = _swig_getverify_result_minimaldata()216func _swig_getverify_result_sig_pushonly() (_swig_ret LibbitcoinConsensusVerify_result_type) {217 var swig_r LibbitcoinConsensusVerify_result_type218 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_sig_pushonly_consensus_0731991c73947514())219 return swig_r220}221var Verify_result_sig_pushonly LibbitcoinConsensusVerify_result_type = _swig_getverify_result_sig_pushonly()222func _swig_getverify_result_sig_high_s() (_swig_ret LibbitcoinConsensusVerify_result_type) {223 var swig_r LibbitcoinConsensusVerify_result_type224 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_sig_high_s_consensus_0731991c73947514())225 return swig_r226}227var Verify_result_sig_high_s LibbitcoinConsensusVerify_result_type = _swig_getverify_result_sig_high_s()228func _swig_getverify_result_sig_nulldummy() (_swig_ret LibbitcoinConsensusVerify_result_type) {229 var swig_r LibbitcoinConsensusVerify_result_type230 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_sig_nulldummy_consensus_0731991c73947514())231 return swig_r232}233var Verify_result_sig_nulldummy LibbitcoinConsensusVerify_result_type = _swig_getverify_result_sig_nulldummy()234func _swig_getverify_result_pubkeytype() (_swig_ret LibbitcoinConsensusVerify_result_type) {235 var swig_r LibbitcoinConsensusVerify_result_type236 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_pubkeytype_consensus_0731991c73947514())237 return swig_r238}239var Verify_result_pubkeytype LibbitcoinConsensusVerify_result_type = _swig_getverify_result_pubkeytype()240func _swig_getverify_result_cleanstack() (_swig_ret LibbitcoinConsensusVerify_result_type) {241 var swig_r LibbitcoinConsensusVerify_result_type242 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_cleanstack_consensus_0731991c73947514())243 return swig_r244}245var Verify_result_cleanstack LibbitcoinConsensusVerify_result_type = _swig_getverify_result_cleanstack()246func _swig_getverify_result_discourage_upgradable_nops() (_swig_ret LibbitcoinConsensusVerify_result_type) {247 var swig_r LibbitcoinConsensusVerify_result_type248 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_discourage_upgradable_nops_consensus_0731991c73947514())249 return swig_r250}251var Verify_result_discourage_upgradable_nops LibbitcoinConsensusVerify_result_type = _swig_getverify_result_discourage_upgradable_nops()252func _swig_getverify_result_op_return() (_swig_ret LibbitcoinConsensusVerify_result_type) {253 var swig_r LibbitcoinConsensusVerify_result_type254 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_op_return_consensus_0731991c73947514())255 return swig_r256}257var Verify_result_op_return LibbitcoinConsensusVerify_result_type = _swig_getverify_result_op_return()258func _swig_getverify_result_unknown_error() (_swig_ret LibbitcoinConsensusVerify_result_type) {259 var swig_r LibbitcoinConsensusVerify_result_type260 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_unknown_error_consensus_0731991c73947514())261 return swig_r262}263var Verify_result_unknown_error LibbitcoinConsensusVerify_result_type = _swig_getverify_result_unknown_error()264func _swig_getverify_result_tx_invalid() (_swig_ret LibbitcoinConsensusVerify_result_type) {265 var swig_r LibbitcoinConsensusVerify_result_type266 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_tx_invalid_consensus_0731991c73947514())267 return swig_r268}269var Verify_result_tx_invalid LibbitcoinConsensusVerify_result_type = _swig_getverify_result_tx_invalid()270func _swig_getverify_result_tx_size_invalid() (_swig_ret LibbitcoinConsensusVerify_result_type) {271 var swig_r LibbitcoinConsensusVerify_result_type272 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_tx_size_invalid_consensus_0731991c73947514())273 return swig_r274}275var Verify_result_tx_size_invalid LibbitcoinConsensusVerify_result_type = _swig_getverify_result_tx_size_invalid()276func _swig_getverify_result_tx_input_invalid() (_swig_ret LibbitcoinConsensusVerify_result_type) {277 var swig_r LibbitcoinConsensusVerify_result_type278 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_tx_input_invalid_consensus_0731991c73947514())279 return swig_r280}281var Verify_result_tx_input_invalid LibbitcoinConsensusVerify_result_type = _swig_getverify_result_tx_input_invalid()282func _swig_getverify_result_negative_locktime() (_swig_ret LibbitcoinConsensusVerify_result_type) {283 var swig_r LibbitcoinConsensusVerify_result_type284 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_negative_locktime_consensus_0731991c73947514())285 return swig_r286}287var Verify_result_negative_locktime LibbitcoinConsensusVerify_result_type = _swig_getverify_result_negative_locktime()288func _swig_getverify_result_unsatisfied_locktime() (_swig_ret LibbitcoinConsensusVerify_result_type) {289 var swig_r LibbitcoinConsensusVerify_result_type290 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_result_unsatisfied_locktime_consensus_0731991c73947514())291 return swig_r292}293var Verify_result_unsatisfied_locktime LibbitcoinConsensusVerify_result_type = _swig_getverify_result_unsatisfied_locktime()294type LibbitcoinConsensusVerify_flags_type int295func _swig_getverify_flags_none() (_swig_ret LibbitcoinConsensusVerify_flags_type) {296 var swig_r LibbitcoinConsensusVerify_flags_type297 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_none_consensus_0731991c73947514())298 return swig_r299}300var Verify_flags_none LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_none()301func _swig_getverify_flags_p2sh() (_swig_ret LibbitcoinConsensusVerify_flags_type) {302 var swig_r LibbitcoinConsensusVerify_flags_type303 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_p2sh_consensus_0731991c73947514())304 return swig_r305}306var Verify_flags_p2sh LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_p2sh()307func _swig_getverify_flags_strictenc() (_swig_ret LibbitcoinConsensusVerify_flags_type) {308 var swig_r LibbitcoinConsensusVerify_flags_type309 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_strictenc_consensus_0731991c73947514())310 return swig_r311}312var Verify_flags_strictenc LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_strictenc()313func _swig_getverify_flags_dersig() (_swig_ret LibbitcoinConsensusVerify_flags_type) {314 var swig_r LibbitcoinConsensusVerify_flags_type315 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_dersig_consensus_0731991c73947514())316 return swig_r317}318var Verify_flags_dersig LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_dersig()319func _swig_getverify_flags_low_s() (_swig_ret LibbitcoinConsensusVerify_flags_type) {320 var swig_r LibbitcoinConsensusVerify_flags_type321 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_low_s_consensus_0731991c73947514())322 return swig_r323}324var Verify_flags_low_s LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_low_s()325func _swig_getverify_flags_nulldummy() (_swig_ret LibbitcoinConsensusVerify_flags_type) {326 var swig_r LibbitcoinConsensusVerify_flags_type327 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_nulldummy_consensus_0731991c73947514())328 return swig_r329}330var Verify_flags_nulldummy LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_nulldummy()331func _swig_getverify_flags_sigpushonly() (_swig_ret LibbitcoinConsensusVerify_flags_type) {332 var swig_r LibbitcoinConsensusVerify_flags_type333 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_sigpushonly_consensus_0731991c73947514())334 return swig_r335}336var Verify_flags_sigpushonly LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_sigpushonly()337func _swig_getverify_flags_minimaldata() (_swig_ret LibbitcoinConsensusVerify_flags_type) {338 var swig_r LibbitcoinConsensusVerify_flags_type339 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_minimaldata_consensus_0731991c73947514())340 return swig_r341}342var Verify_flags_minimaldata LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_minimaldata()343func _swig_getverify_flags_discourage_upgradable_nops() (_swig_ret LibbitcoinConsensusVerify_flags_type) {344 var swig_r LibbitcoinConsensusVerify_flags_type345 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_discourage_upgradable_nops_consensus_0731991c73947514())346 return swig_r347}348var Verify_flags_discourage_upgradable_nops LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_discourage_upgradable_nops()349func _swig_getverify_flags_cleanstack() (_swig_ret LibbitcoinConsensusVerify_flags_type) {350 var swig_r LibbitcoinConsensusVerify_flags_type351 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_cleanstack_consensus_0731991c73947514())352 return swig_r353}354var Verify_flags_cleanstack LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_cleanstack()355func _swig_getverify_flags_checklocktimeverify() (_swig_ret LibbitcoinConsensusVerify_flags_type) {356 var swig_r LibbitcoinConsensusVerify_flags_type357 swig_r = (LibbitcoinConsensusVerify_flags_type)(C._wrap_verify_flags_checklocktimeverify_consensus_0731991c73947514())358 return swig_r359}360var Verify_flags_checklocktimeverify LibbitcoinConsensusVerify_flags_type = _swig_getverify_flags_checklocktimeverify()361func Verify_script(arg1 *byte, arg2 int64, arg3 *byte, arg4 int64, arg5 uint, arg6 uint) (_swig_ret LibbitcoinConsensusVerify_result_type) {362 var swig_r LibbitcoinConsensusVerify_result_type363 _swig_i_0 := arg1364 _swig_i_1 := arg2365 _swig_i_2 := arg3366 _swig_i_3 := arg4367 _swig_i_4 := arg5368 _swig_i_5 := arg6369 swig_r = (LibbitcoinConsensusVerify_result_type)(C._wrap_verify_script_consensus_0731991c73947514(C.swig_voidp(_swig_i_0), C.swig_type_1(_swig_i_1), C.swig_voidp(_swig_i_2), C.swig_type_2(_swig_i_3), C.swig_intgo(_swig_i_4), C.swig_intgo(_swig_i_5)))370 return swig_r371}...

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 xlFile, err := xlsx.OpenFile("Book1.xlsx")4 if err != nil {5 fmt.Println(err)6 }7 for _, sheet := range xlFile.Sheets {8 for _, row := range sheet.Rows {9 for _, cell := range row.Cells {10 text := cell.String()11 fmt.Printf("%s12 }13 }14 }15}16import (17func main() {18 xlFile, err := xlsx.OpenFile("Book1.xlsx")19 if err != nil {20 fmt.Println(err)21 }22 for _, sheet := range xlFile.Sheets {23 for _, row := range sheet.Rows {24 for _, cell := range row.Cells {25 text := cell.String()26 fmt.Printf("%s27 }28 }29 }30}31import (32func main() {33 xlFile, err := xlsx.OpenFile("Book1.xlsx")34 if err != nil {35 fmt.Println(err)36 }37 for _, sheet := range xlFile.Sheets {38 for _, row := range sheet.Rows {39 for _, cell := range row.Cells {40 text := cell.String()41 fmt.Printf("%s42 }43 }44 }45}46import (47func main() {48 xlFile, err := xlsx.OpenFile("Book1.xlsx")49 if err != nil {50 fmt.Println(err)51 }52 for _, sheet := range xlFile.Sheets {53 for _, row := range sheet.Rows {54 for _, cell := range row.Cells {55 text := cell.String()56 fmt.Printf("%s57 }58 }59 }60}

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1import (2type Result struct {3}4func (r *Result) Type() string {5}6func main() {7 r := &Result{"foo"}8 fmt.Println(r.Type())9}

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println(result.Type)3}4func main() {5 fmt.Println(result.Type())6}7func main() {8 fmt.Println(result.Type)9}10func main() {11 fmt.Println(result.Type())12}13func main() {14 fmt.Println(result.Type())15}16func main() {17 fmt.Println(result.Type())18}19func main() {20 fmt.Println(result.Type())21}22func main() {23 fmt.Println(result.Type())24}25func main() {26 fmt.Println(result.Type())27}28func main() {29 fmt.Println(result.Type())30}31func main() {32 fmt.Println(result.Type())33}34func main() {35 fmt.Println(result.Type())36}37func main() {

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1import (2type Result struct {3}4func (r Result) Type() string {5}6func main() {7 router := httprouter.New()8 router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {9 w.Header().Set("Content-Type", "application/json")10 w.WriteHeader(http.StatusOK)11 w.Write([]byte(`{"Type":"Result"}`))12 })13 http.ListenAndServe(":8080", router)14}15import (16type Result struct {17}18func (r Result) Type() string {19}20func main() {21 router := httprouter.New()22 router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {23 w.Header().Set("Content-Type", "application/json")24 w.WriteHeader(http.StatusOK)25 w.Write([]byte(`{"Type":"Result"}`))26 })27 http.ListenAndServe(":8080", router)28}29import (30type Result struct {31}32func (r Result) Type() string {33}34func main() {35 router := httprouter.New()36 router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {37 w.Header().Set("Content-Type", "application/json")38 w.WriteHeader(http.StatusOK)39 w.Write([]byte(`{"Type":"Result"}`))40 })41 http.ListenAndServe(":8080", router)42}43import (44type Result struct {45}46func (r Result) Type() string {

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := result.New("Hello")4 fmt.Println(r.Type())5}6import (7type Result struct {8 value interface{}9}10func New(value interface{}) *Result {11 return &Result{value}12}13func (r *Result) Type() string {14 return reflect.TypeOf(r.value).String()15}

Full Screen

Full Screen

Type

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 result = Result{1, 2}4 fmt.Println(result.Type())5}6func (r Result) Type() int {7 return int(r)8}9func (r Result) Type() int {10 return int(r)11}12func (r Result) Type() int {13 return int(r)14}15func (r Result) Type() int {16 return int(r)17}18func (r Result) Type() int {19 return int(r)20}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful