OSDN Git Service

compiler: add error to list of built-in types.
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / export.h
1 // export.h -- Export declarations in Go frontend.     -*- C++ -*-
2
3 // Copyright 2009 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_EXPORT_H
8 #define GO_EXPORT_H
9
10 #include "string-dump.h"
11
12 struct sha1_ctx;
13 class Gogo;
14 class Import_init;
15 class Bindings;
16 class Type;
17
18 // Codes used for the builtin types.  These are all negative to make
19 // them easily distinct from the codes assigned by Export::write_type.
20 // Note that these codes may not be changed!  Changing them would
21 // break existing export data.
22
23 enum Builtin_code
24 {
25   BUILTIN_INT8 = -1,
26   BUILTIN_INT16 = -2,
27   BUILTIN_INT32 = -3,
28   BUILTIN_INT64 = -4,
29   BUILTIN_UINT8 = -5,
30   BUILTIN_UINT16 = -6,
31   BUILTIN_UINT32 = -7,
32   BUILTIN_UINT64 = -8,
33   BUILTIN_FLOAT32 = -9,
34   BUILTIN_FLOAT64 = -10,
35   BUILTIN_INT = -11,
36   BUILTIN_UINT = -12,
37   BUILTIN_UINTPTR = -13,
38   BUILTIN_BOOL = -15,
39   BUILTIN_STRING = -16,
40   BUILTIN_COMPLEX64 = -17,
41   BUILTIN_COMPLEX128 = -18,
42   BUILTIN_ERROR = -19,
43
44   SMALLEST_BUILTIN_CODE = -19
45 };
46
47 // This class manages exporting Go declarations.  It handles the main
48 // loop of exporting.  A pointer to this class is also passed to the
49 // various specific export implementations.
50
51 class Export : public String_dump
52 {
53  public:
54   // The Stream class is an interface used to output the exported
55   // information.  The caller should instantiate a child of this
56   // class.
57   class Stream
58   {
59    public:
60     Stream();
61     virtual ~Stream();
62
63     // Write a string. Implements the String_dump interface.
64     void
65     write_string(const std::string& s)
66     { this->write_and_sum_bytes(s.data(), s.length()); }
67
68     // Write a nul terminated string. Implements the String_dump interface.
69     void
70     write_c_string(const char* s)
71     { this->write_and_sum_bytes(s, strlen(s)); }
72
73     // Write some bytes.
74     void
75     write_bytes(const char* bytes, size_t length)
76     { this->write_and_sum_bytes(bytes, length); }
77
78     // Return the raw bytes of the checksum data.
79     std::string
80     checksum();
81
82     // Write a checksum string to the stream.  This will be called at
83     // the end of the other output.
84     void
85     write_checksum(const std::string&);
86
87    protected:
88     // This function is called with data to export.  This data must be
89     // made available as a contiguous stream for the importer.
90     virtual void
91     do_write(const char* bytes, size_t length) = 0;
92
93   private:
94     void
95     write_and_sum_bytes(const char*, size_t);
96
97     // The checksum.
98     sha1_ctx* checksum_;
99   };
100
101   Export(Stream*);
102
103   // The magic code for version 1 export data.
104   static const int v1_magic_len = 4;
105   static const char v1_magic[v1_magic_len];
106
107   // The length of the v1 checksum string.
108   static const int v1_checksum_len = 20;
109
110   // Register the builtin types.
111   void
112   register_builtin_types(Gogo*);
113
114   // Export the identifiers in BINDINGS which are marked for export.
115   // The exporting is done via a series of calls to THIS->STREAM_.  If
116   // is nothing to export, this->stream_->write will not be called.
117   // UNIQUE_PREFIX is a prefix for all global symbols.
118   // PACKAGE_PRIORITY is the priority to use for this package.
119   // IMPORT_INIT_FN is the name of the import initialization function
120   // for this package; it will be empty if none is needed.
121   // IMPORTED_INIT_FNS is the list of initialization functions for
122   // imported packages.
123   void
124   export_globals(const std::string& package_name,
125                  const std::string& unique_prefix,
126                  int package_priority,
127                  const std::string& import_init_fn,
128                  const std::set<Import_init>& imported_init_fns,
129                  const Bindings* bindings);
130
131   // Write a string to the export stream.
132   void
133   write_string(const std::string& s)
134   { this->stream_->write_string(s); }
135
136   // Write a nul terminated string to the export stream.
137   void
138   write_c_string(const char* s)
139   { this->stream_->write_c_string(s); }
140
141   // Write some bytes to the export stream.
142   void
143   write_bytes(const char* bytes, size_t length)
144   { this->stream_->write_bytes(bytes, length); }
145
146   // Write out a type.  This handles references back to previous
147   // definitions.
148   void
149   write_type(const Type*);
150
151  private:
152   Export(const Export&);
153   Export& operator=(const Export&);
154
155   // Write out the imported initialization functions.
156   void
157   write_imported_init_fns(const std::string& package_name, int priority,
158                           const std::string&, const std::set<Import_init>&);
159
160   // Register one builtin type.
161   void
162   register_builtin_type(Gogo*, const char* name, Builtin_code);
163
164   // Mapping from Type objects to a constant index.
165   typedef Unordered_map(const Type*, int) Type_refs;
166
167   // The stream to which we are writing data.
168   Stream* stream_;
169   // Type mappings.
170   Type_refs type_refs_;
171   // Index number of next type.
172   int type_index_;
173 };
174
175 // An export streamer which puts the export stream in a named section.
176
177 class Stream_to_section : public Export::Stream
178 {
179  public:
180   Stream_to_section();
181
182  protected:
183   void
184   do_write(const char*, size_t);
185 };
186
187 #endif // !defined(GO_EXPORT_H)