OSDN Git Service

Use backend interface for return statements.
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / backend.h
1 // backend.h -- Go frontend interface to backend  -*- C++ -*-
2
3 // Copyright 2011 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 #ifndef GO_BACKEND_H
8 #define GO_BACKEND_H
9
10 class Function_type;
11 class Struct_type;
12 class Interface_type;
13
14 // Pointers to these types are created by the backend, passed to the
15 // frontend, and passed back to the backend.  The types must be
16 // defined by the backend using these names.
17
18 // The backend representation of a type.
19 class Btype;
20
21 // The backend represention of an expression.
22 class Bexpression;
23
24 // The backend representation of a statement.
25 class Bstatement;
26
27 // The backend representation of a function definition.
28 class Bfunction;
29
30 // A list of backend types.
31 typedef std::vector<Btype*> Btypes;
32
33 // The backend interface.  This is a pure abstract class that a
34 // specific backend will implement.
35
36 class Backend
37 {
38  public:
39   virtual ~Backend() { }
40
41   // Types.
42
43   // Produce an error type.  Actually the backend could probably just
44   // crash if this is called.
45   virtual Btype*
46   error_type() = 0;
47
48   // Get a void type.  This is used in (at least) two ways: 1) as the
49   // return type of a function with no result parameters; 2)
50   // unsafe.Pointer is represented as *void.
51   virtual Btype*
52   void_type() = 0;
53
54   // Get the unnamed boolean type.
55   virtual Btype*
56   bool_type() = 0;
57
58   // Get an unnamed integer type with the given signedness and number
59   // of bits.
60   virtual Btype*
61   integer_type(bool is_unsigned, int bits) = 0;
62
63   // Get an unnamed floating point type with the given number of bits.
64   virtual Btype*
65   float_type(int bits) = 0;
66
67   // Get the unnamed string type.
68   virtual Btype*
69   string_type() = 0;
70
71   // Get a function type.  The receiver, parameter, and results are
72   // generated from the types in the Function_type.  The Function_type
73   // is provided so that the names are available.
74   virtual Btype*
75   function_type(const Function_type*, Btype* receiver,
76                 const Btypes* parameters,
77                 const Btypes* results) = 0;
78
79   // Get a struct type.  The Struct_type is provided to get the field
80   // names.
81   virtual Btype*
82   struct_type(const Struct_type*, const Btypes* field_types) = 0;
83
84   // Get an array type.
85   virtual Btype*
86   array_type(const Btype* element_type, const Bexpression* length) = 0;
87
88   // Get a slice type.
89   virtual Btype*
90   slice_type(const Btype* element_type) = 0;
91
92   // Get a map type.
93   virtual Btype*
94   map_type(const Btype* key_type, const Btype* value_type, source_location) = 0;
95
96   // Get a channel type.
97   virtual Btype*
98   channel_type(const Btype* element_type) = 0;
99
100   // Get an interface type.  The Interface_type is provided to get the
101   // method names.
102   virtual Btype*
103   interface_type(const Interface_type*, const Btypes* method_types) = 0;
104
105   // Statements.
106
107   // Create an assignment statement.
108   virtual Bstatement*
109   assignment_statement(Bexpression* lhs, Bexpression* rhs,
110                        source_location) = 0;
111
112   // Create a return statement, passing the representation of the
113   // function and the list of values to return.
114   virtual Bstatement*
115   return_statement(Bfunction*, const std::vector<Bexpression*>&,
116                    source_location) = 0;
117 };
118
119 // The backend interface has to define this function.
120
121 extern Backend* go_get_backend();
122
123 // FIXME: Temporary helper functions while converting to new backend
124 // interface.
125
126 extern Bexpression* tree_to_expr(tree);
127 extern Bfunction* tree_to_function(tree);
128 extern tree statement_to_tree(Bstatement*);
129
130 #endif // !defined(GO_BACKEND_H)