github.com/google/grumpy@v0.0.0-20171122020858-3ec87959189c/runtime/traceback.go (about)

     1  // Copyright 2016 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package grumpy
    16  
    17  import (
    18  	"reflect"
    19  )
    20  
    21  // Traceback represents Python 'traceback' objects.
    22  type Traceback struct {
    23  	Object
    24  	frame  *Frame     `attr:"tb_frame"`
    25  	next   *Traceback `attr:"tb_next"`
    26  	lineno int        `attr:"tb_lineno"`
    27  }
    28  
    29  func newTraceback(f *Frame, next *Traceback) *Traceback {
    30  	f.taken = true
    31  	return &Traceback{Object{typ: TracebackType}, f, next, f.lineno}
    32  }
    33  
    34  func toTracebackUnsafe(o *Object) *Traceback {
    35  	return (*Traceback)(o.toPointer())
    36  }
    37  
    38  // ToObject upcasts f to an Object.
    39  func (f *Traceback) ToObject() *Object {
    40  	return &f.Object
    41  }
    42  
    43  // TracebackType is the object representing the Python 'traceback' type.
    44  var TracebackType = newBasisType("traceback", reflect.TypeOf(Traceback{}), toTracebackUnsafe, ObjectType)
    45  
    46  func initTracebackType(map[string]*Object) {
    47  	TracebackType.flags &^= typeFlagInstantiable | typeFlagBasetype
    48  }