OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-assert-interface.c] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* go-assert-interface.c -- interface type assertion for Go.
2
 
3
   Copyright 2010 The Go Authors. All rights reserved.
4
   Use of this source code is governed by a BSD-style
5
   license that can be found in the LICENSE file.  */
6
 
7
#include "go-alloc.h"
8
#include "go-assert.h"
9
#include "go-panic.h"
10
#include "interface.h"
11
 
12
/* This is called by the compiler to implement a type assertion from
13
   one interface type to another.  This returns the value that should
14
   go in the first field of the result tuple.  The result may be an
15
   empty or a non-empty interface.  */
16
 
17
const void *
18
__go_assert_interface (const struct __go_type_descriptor *lhs_descriptor,
19
                       const struct __go_type_descriptor *rhs_descriptor)
20
{
21
  const struct __go_interface_type *lhs_interface;
22
 
23
  if (rhs_descriptor == NULL)
24
    {
25
      struct __go_empty_interface panic_arg;
26
 
27
      /* A type assertion is not permitted with a nil interface.  */
28
 
29
      newTypeAssertionError (NULL,
30
                             NULL,
31
                             lhs_descriptor,
32
                             NULL,
33
                             NULL,
34
                             lhs_descriptor->__reflection,
35
                             NULL,
36
                             &panic_arg);
37
      __go_panic (panic_arg);
38
    }
39
 
40
  /* A type assertion to an empty interface just returns the object
41
     descriptor.  */
42
 
43
  __go_assert (lhs_descriptor->__code == GO_INTERFACE);
44
  lhs_interface = (const struct __go_interface_type *) lhs_descriptor;
45
  if (lhs_interface->__methods.__count == 0)
46
    return rhs_descriptor;
47
 
48
  return __go_convert_interface_2 (lhs_descriptor, rhs_descriptor, 0);
49
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.