OSDN Git Service

Use backend interface for variables.
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / gogo.h
1 // gogo.h -- Go frontend parsed representation.     -*- 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_GOGO_H
8 #define GO_GOGO_H
9
10 class Traverse;
11 class Type;
12 class Type_hash_identical;
13 class Type_equal;
14 class Type_identical;
15 class Typed_identifier;
16 class Typed_identifier_list;
17 class Function_type;
18 class Expression;
19 class Statement;
20 class Temporary_statement;
21 class Block;
22 class Function;
23 class Bindings;
24 class Package;
25 class Variable;
26 class Pointer_type;
27 class Struct_type;
28 class Struct_field;
29 class Struct_field_list;
30 class Array_type;
31 class Map_type;
32 class Channel_type;
33 class Interface_type;
34 class Named_type;
35 class Forward_declaration_type;
36 class Method;
37 class Methods;
38 class Named_object;
39 class Label;
40 class Translate_context;
41 class Backend;
42 class Export;
43 class Import;
44 class Bexpression;
45 class Bstatement;
46 class Bvariable;
47 class Blabel;
48
49 // This file declares the basic classes used to hold the internal
50 // representation of Go which is built by the parser.
51
52 // An initialization function for an imported package.  This is a
53 // magic function which initializes variables and runs the "init"
54 // function.
55
56 class Import_init
57 {
58  public:
59   Import_init(const std::string& package_name, const std::string& init_name,
60               int priority)
61     : package_name_(package_name), init_name_(init_name), priority_(priority)
62   { }
63
64   // The name of the package being imported.
65   const std::string&
66   package_name() const
67   { return this->package_name_; }
68
69   // The name of the package's init function.
70   const std::string&
71   init_name() const
72   { return this->init_name_; }
73
74   // The priority of the initialization function.  Functions with a
75   // lower priority number must be run first.
76   int
77   priority() const
78   { return this->priority_; }
79
80  private:
81   // The name of the package being imported.
82   std::string package_name_;
83   // The name of the package's init function.
84   std::string init_name_;
85   // The priority.
86   int priority_;
87 };
88
89 // For sorting purposes.
90
91 inline bool
92 operator<(const Import_init& i1, const Import_init& i2)
93 {
94   if (i1.priority() < i2.priority())
95     return true;
96   if (i1.priority() > i2.priority())
97     return false;
98   if (i1.package_name() != i2.package_name())
99     return i1.package_name() < i2.package_name();
100   return i1.init_name() < i2.init_name();
101 }
102
103 // The holder for the internal representation of the entire
104 // compilation unit.
105
106 class Gogo
107 {
108  public:
109   // Create the IR, passing in the sizes of the types "int" and
110   // "uintptr" in bits.
111   Gogo(Backend* backend, int int_type_size, int pointer_size);
112
113   // Get the backend generator.
114   Backend*
115   backend()
116   { return this->backend_; }
117
118   // Get the package name.
119   const std::string&
120   package_name() const;
121
122   // Set the package name.
123   void
124   set_package_name(const std::string&, source_location);
125
126   // Return whether this is the "main" package.
127   bool
128   is_main_package() const;
129
130   // If necessary, adjust the name to use for a hidden symbol.  We add
131   // a prefix of the package name, so that hidden symbols in different
132   // packages do not collide.
133   std::string
134   pack_hidden_name(const std::string& name, bool is_exported) const
135   {
136     return (is_exported
137             ? name
138             : ('.' + this->unique_prefix()
139                + '.' + this->package_name()
140                + '.' + name));
141   }
142
143   // Unpack a name which may have been hidden.  Returns the
144   // user-visible name of the object.
145   static std::string
146   unpack_hidden_name(const std::string& name)
147   { return name[0] != '.' ? name : name.substr(name.rfind('.') + 1); }
148
149   // Return whether a possibly packed name is hidden.
150   static bool
151   is_hidden_name(const std::string& name)
152   { return name[0] == '.'; }
153
154   // Return the package prefix of a hidden name.
155   static std::string
156   hidden_name_prefix(const std::string& name)
157   {
158     gcc_assert(Gogo::is_hidden_name(name));
159     return name.substr(1, name.rfind('.') - 1);
160   }
161
162   // Given a name which may or may not have been hidden, return the
163   // name to use in an error message.
164   static std::string
165   message_name(const std::string& name);
166
167   // Return whether a name is the blank identifier _.
168   static bool
169   is_sink_name(const std::string& name)
170   {
171     return (name[0] == '.'
172             && name[name.length() - 1] == '_'
173             && name[name.length() - 2] == '.');
174   }
175
176   // Return the unique prefix to use for all exported symbols.
177   const std::string&
178   unique_prefix() const;
179
180   // Set the unique prefix.
181   void
182   set_unique_prefix(const std::string&);
183
184   // Return the priority to use for the package we are compiling.
185   // This is two more than the largest priority of any package we
186   // import.
187   int
188   package_priority() const;
189
190   // Import a package.  FILENAME is the file name argument, LOCAL_NAME
191   // is the local name to give to the package.  If LOCAL_NAME is empty
192   // the declarations are added to the global scope.
193   void
194   import_package(const std::string& filename, const std::string& local_name,
195                  bool is_local_name_exported, source_location);
196
197   // Whether we are the global binding level.
198   bool
199   in_global_scope() const;
200
201   // Look up a name in the current binding contours.
202   Named_object*
203   lookup(const std::string&, Named_object** pfunction) const;
204
205   // Look up a name in the current block.
206   Named_object*
207   lookup_in_block(const std::string&) const;
208
209   // Look up a name in the global namespace--the universal scope.
210   Named_object*
211   lookup_global(const char*) const;
212
213   // Add a new imported package.  REAL_NAME is the real name of the
214   // package.  ALIAS is the alias of the package; this may be the same
215   // as REAL_NAME.  This sets *PADD_TO_GLOBALS if symbols added to
216   // this package should be added to the global namespace; this is
217   // true if the alias is ".".  LOCATION is the location of the import
218   // statement.  This returns the new package, or NULL on error.
219   Package*
220   add_imported_package(const std::string& real_name, const std::string& alias,
221                        bool is_alias_exported,
222                        const std::string& unique_prefix,
223                        source_location location,
224                        bool* padd_to_globals);
225
226   // Register a package.  This package may or may not be imported.
227   // This returns the Package structure for the package, creating if
228   // it necessary.
229   Package*
230   register_package(const std::string& name, const std::string& unique_prefix,
231                    source_location);
232
233   // Start compiling a function.  ADD_METHOD_TO_TYPE is true if a
234   // method function should be added to the type of its receiver.
235   Named_object*
236   start_function(const std::string& name, Function_type* type,
237                  bool add_method_to_type, source_location);
238
239   // Finish compiling a function.
240   void
241   finish_function(source_location);
242
243   // Return the current function.
244   Named_object*
245   current_function() const;
246
247   // Start a new block.  This is not initially associated with a
248   // function.
249   void
250   start_block(source_location);
251
252   // Finish the current block and return it.
253   Block*
254   finish_block(source_location);
255
256   // Declare an unknown name.  This is used while parsing.  The name
257   // must be resolved by the end of the parse.  Unknown names are
258   // always added at the package level.
259   Named_object*
260   add_unknown_name(const std::string& name, source_location);
261
262   // Declare a function.
263   Named_object*
264   declare_function(const std::string&, Function_type*, source_location);
265
266   // Add a label.
267   Label*
268   add_label_definition(const std::string&, source_location);
269
270   // Add a label reference.
271   Label*
272   add_label_reference(const std::string&);
273
274   // Add a statement to the current block.
275   void
276   add_statement(Statement*);
277
278   // Add a block to the current block.
279   void
280   add_block(Block*, source_location);
281
282   // Add a constant.
283   Named_object*
284   add_constant(const Typed_identifier&, Expression*, int iota_value);
285
286   // Add a type.
287   void
288   add_type(const std::string&, Type*, source_location);
289
290   // Add a named type.  This is used for builtin types, and to add an
291   // imported type to the global scope.
292   void
293   add_named_type(Named_type*);
294
295   // Declare a type.
296   Named_object*
297   declare_type(const std::string&, source_location);
298
299   // Declare a type at the package level.  This is used when the
300   // parser sees an unknown name where a type name is required.
301   Named_object*
302   declare_package_type(const std::string&, source_location);
303
304   // Define a type which was already declared.
305   void
306   define_type(Named_object*, Named_type*);
307
308   // Add a variable.
309   Named_object*
310   add_variable(const std::string&, Variable*);
311
312   // Add a sink--a reference to the blank identifier _.
313   Named_object*
314   add_sink();
315
316   // Add a named object to the current namespace.  This is used for
317   // import . "package".
318   void
319   add_named_object(Named_object*);
320
321   // Return a name to use for a thunk function.  A thunk function is
322   // one we create during the compilation, for a go statement or a
323   // defer statement or a method expression.
324   static std::string
325   thunk_name();
326
327   // Return whether an object is a thunk.
328   static bool
329   is_thunk(const Named_object*);
330
331   // Note that we've seen an interface type.  This is used to build
332   // all required interface method tables.
333   void
334   record_interface_type(Interface_type*);
335
336   // Note that we need an initialization function.
337   void
338   set_need_init_fn()
339   { this->need_init_fn_ = true; }
340
341   // Clear out all names in file scope.  This is called when we start
342   // parsing a new file.
343   void
344   clear_file_scope();
345
346   // Traverse the tree.  See the Traverse class.
347   void
348   traverse(Traverse*);
349
350   // Define the predeclared global names.
351   void
352   define_global_names();
353
354   // Verify and complete all types.
355   void
356   verify_types();
357
358   // Lower the parse tree.
359   void
360   lower_parse_tree();
361
362   // Lower all the statements in a block.
363   void
364   lower_block(Named_object* function, Block*);
365
366   // Lower an expression.
367   void
368   lower_expression(Named_object* function, Expression**);
369
370   // Lower a constant.
371   void
372   lower_constant(Named_object*);
373
374   // Finalize the method lists and build stub methods for named types.
375   void
376   finalize_methods();
377
378   // Work out the types to use for unspecified variables and
379   // constants.
380   void
381   determine_types();
382
383   // Type check the program.
384   void
385   check_types();
386
387   // Check the types in a single block.  This is used for complicated
388   // go statements.
389   void
390   check_types_in_block(Block*);
391
392   // Check for return statements.
393   void
394   check_return_statements();
395
396   // Do all exports.
397   void
398   do_exports();
399
400   // Add an import control function for an imported package to the
401   // list.
402   void
403   add_import_init_fn(const std::string& package_name,
404                      const std::string& init_name, int prio);
405
406   // Turn short-cut operators (&&, ||) into explicit if statements.
407   void
408   remove_shortcuts();
409
410   // Use temporary variables to force order of evaluation.
411   void
412   order_evaluations();
413
414   // Build thunks for functions which call recover.
415   void
416   build_recover_thunks();
417
418   // Simplify statements which might use thunks: go and defer
419   // statements.
420   void
421   simplify_thunk_statements();
422
423   // Convert named types to the backend representation.
424   void
425   convert_named_types();
426
427   // Convert named types in a list of bindings.
428   void
429   convert_named_types_in_bindings(Bindings*);
430
431   // True if named types have been converted to the backend
432   // representation.
433   bool
434   named_types_are_converted() const
435   { return this->named_types_are_converted_; }
436
437   // Write out the global values.
438   void
439   write_globals();
440
441   // Build a call to a builtin function.  PDECL should point to a NULL
442   // initialized static pointer which will hold the fndecl.  NAME is
443   // the name of the function.  NARGS is the number of arguments.
444   // RETTYPE is the return type.  It is followed by NARGS pairs of
445   // type and argument (both trees).
446   static tree
447   call_builtin(tree* pdecl, source_location, const char* name, int nargs,
448                tree rettype, ...);
449
450   // Build a call to the runtime error function.
451   static tree
452   runtime_error(int code, source_location);
453
454   // Build a builtin struct with a list of fields.
455   static tree
456   builtin_struct(tree* ptype, const char* struct_name, tree struct_type,
457                  int nfields, ...);
458
459   // Mark a function declaration as a builtin library function.
460   static void
461   mark_fndecl_as_builtin_library(tree fndecl);
462
463   // Build the type of the struct that holds a slice for the given
464   // element type.
465   tree
466   slice_type_tree(tree element_type_tree);
467
468   // Given a tree for a slice type, return the tree for the element
469   // type.
470   static tree
471   slice_element_type_tree(tree slice_type_tree);
472
473   // Build a constructor for a slice.  SLICE_TYPE_TREE is the type of
474   // the slice.  VALUES points to the values.  COUNT is the size,
475   // CAPACITY is the capacity.  If CAPACITY is NULL, it is set to
476   // COUNT.
477   static tree
478   slice_constructor(tree slice_type_tree, tree values, tree count,
479                     tree capacity);
480
481   // Build a constructor for an empty slice.  SLICE_TYPE_TREE is the
482   // type of the slice.
483   static tree
484   empty_slice_constructor(tree slice_type_tree);
485
486   // Build a map descriptor.
487   tree
488   map_descriptor(Map_type*);
489
490   // Return a tree for the type of a map descriptor.  This is struct
491   // __go_map_descriptor in libgo/runtime/map.h.  This is the same for
492   // all map types.
493   tree
494   map_descriptor_type();
495
496   // Build a type descriptor for TYPE using INITIALIZER as the type
497   // descriptor.  This builds a new decl stored in *PDECL.
498   void
499   build_type_descriptor_decl(const Type*, Expression* initializer,
500                              tree* pdecl);
501
502   // Build required interface method tables.
503   void
504   build_interface_method_tables();
505
506   // Build an interface method table for a type: a list of function
507   // pointers, one for each interface method.  This returns a decl.
508   tree
509   interface_method_table_for_type(const Interface_type*, Named_type*,
510                                   bool is_pointer);
511
512   // Return a tree which allocate SIZE bytes to hold values of type
513   // TYPE.
514   tree
515   allocate_memory(Type *type, tree size, source_location);
516
517   // Return a type to use for pointer to const char.
518   static tree
519   const_char_pointer_type_tree();
520
521   // Build a string constant with the right type.
522   static tree
523   string_constant_tree(const std::string&);
524
525   // Build a Go string constant.  This returns a pointer to the
526   // constant.
527   tree
528   go_string_constant_tree(const std::string&);
529
530   // Receive a value from a channel.
531   static tree
532   receive_from_channel(tree type_tree, tree channel, bool for_select,
533                        source_location);
534
535   // Return a tree for receiving an integer on a channel.
536   static tree
537   receive_as_64bit_integer(tree type, tree channel, bool blocking,
538                            bool for_select);
539
540
541   // Make a trampoline which calls FNADDR passing CLOSURE.
542   tree
543   make_trampoline(tree fnaddr, tree closure, source_location);
544
545  private:
546   // During parsing, we keep a stack of functions.  Each function on
547   // the stack is one that we are currently parsing.  For each
548   // function, we keep track of the current stack of blocks.
549   struct Open_function
550   {
551     // The function.
552     Named_object* function;
553     // The stack of active blocks in the function.
554     std::vector<Block*> blocks;
555   };
556
557   // The stack of functions.
558   typedef std::vector<Open_function> Open_functions;
559
560   // Create trees for implicit builtin functions.
561   void
562   define_builtin_function_trees();
563
564   // Set up the built-in unsafe package.
565   void
566   import_unsafe(const std::string&, bool is_exported, source_location);
567
568   // Add a new imported package.
569   Named_object*
570   add_package(const std::string& real_name, const std::string& alias,
571               const std::string& unique_prefix, source_location location);
572
573   // Return the current binding contour.
574   Bindings*
575   current_bindings();
576
577   const Bindings*
578   current_bindings() const;
579
580   // Return the current block.
581   Block*
582   current_block();
583
584   // Get the name of the magic initialization function.
585   const std::string&
586   get_init_fn_name();
587
588   // Get the decl for the magic initialization function.
589   tree
590   initialization_function_decl();
591
592   // Write the magic initialization function.
593   void
594   write_initialization_function(tree fndecl, tree init_stmt_list);
595
596   // Initialize imported packages.
597   void
598   init_imports(tree*);
599
600   // Register variables with the garbage collector.
601   void
602   register_gc_vars(const std::vector<Named_object*>&, tree*);
603
604   // Build a pointer to a Go string constant.  This returns a pointer
605   // to the pointer.
606   tree
607   ptr_go_string_constant_tree(const std::string&);
608
609   // Return the name to use for a type descriptor decl for an unnamed
610   // type.
611   std::string
612   unnamed_type_descriptor_decl_name(const Type* type);
613
614   // Return the name to use for a type descriptor decl for a type
615   // named NO, defined in IN_FUNCTION.
616   std::string
617   type_descriptor_decl_name(const Named_object* no,
618                             const Named_object* in_function);
619
620   // Where a type descriptor should be defined.
621   enum Type_descriptor_location
622     {
623       // Defined in this file.
624       TYPE_DESCRIPTOR_DEFINED,
625       // Defined in some other file.
626       TYPE_DESCRIPTOR_UNDEFINED,
627       // Common definition which may occur in multiple files.
628       TYPE_DESCRIPTOR_COMMON
629     };
630
631   // Return where the decl for TYPE should be defined.
632   Type_descriptor_location
633   type_descriptor_location(const Type* type);
634
635   // Return the type of a trampoline.
636   static tree
637   trampoline_type_tree();
638
639   // Type used to map import names to packages.
640   typedef std::map<std::string, Package*> Imports;
641
642   // Type used to map package names to packages.
643   typedef std::map<std::string, Package*> Packages;
644
645   // Type used to map special names in the sys package.
646   typedef std::map<std::string, std::string> Sys_names;
647
648   // Hash table mapping map types to map descriptor decls.
649   typedef Unordered_map_hash(const Map_type*, tree, Type_hash_identical,
650                              Type_identical) Map_descriptors;
651
652   // Map unnamed types to type descriptor decls.
653   typedef Unordered_map_hash(const Type*, tree, Type_hash_identical,
654                              Type_identical) Type_descriptor_decls;
655
656   // The backend generator.
657   Backend* backend_;
658   // The package we are compiling.
659   Package* package_;
660   // The list of currently open functions during parsing.
661   Open_functions functions_;
662   // The global binding contour.  This includes the builtin functions
663   // and the package we are compiling.
664   Bindings* globals_;
665   // Mapping from import file names to packages.
666   Imports imports_;
667   // Whether the magic unsafe package was imported.
668   bool imported_unsafe_;
669   // Mapping from package names we have seen to packages.  This does
670   // not include the package we are compiling.
671   Packages packages_;
672   // Mapping from map types to map descriptors.
673   Map_descriptors* map_descriptors_;
674   // Mapping from unnamed types to type descriptor decls.
675   Type_descriptor_decls* type_descriptor_decls_;
676   // The functions named "init", if there are any.
677   std::vector<Named_object*> init_functions_;
678   // Whether we need a magic initialization function.
679   bool need_init_fn_;
680   // The name of the magic initialization function.
681   std::string init_fn_name_;
682   // A list of import control variables for packages that we import.
683   std::set<Import_init> imported_init_fns_;
684   // The unique prefix used for all global symbols.
685   std::string unique_prefix_;
686   // Whether an explicit unique prefix was set by -fgo-prefix.
687   bool unique_prefix_specified_;
688   // A list of interface types defined while parsing.
689   std::vector<Interface_type*> interface_types_;
690   // Whether named types have been converted.
691   bool named_types_are_converted_;
692 };
693
694 // A block of statements.
695
696 class Block
697 {
698  public:
699   Block(Block* enclosing, source_location);
700
701   // Return the enclosing block.
702   const Block*
703   enclosing() const
704   { return this->enclosing_; }
705
706   // Return the bindings of the block.
707   Bindings*
708   bindings()
709   { return this->bindings_; }
710
711   const Bindings*
712   bindings() const
713   { return this->bindings_; }
714
715   // Look at the block's statements.
716   const std::vector<Statement*>*
717   statements() const
718   { return &this->statements_; }
719
720   // Return the start location.  This is normally the location of the
721   // left curly brace which starts the block.
722   source_location
723   start_location() const
724   { return this->start_location_; }
725
726   // Return the end location.  This is normally the location of the
727   // right curly brace which ends the block.
728   source_location
729   end_location() const
730   { return this->end_location_; }
731
732   // Add a statement to the block.
733   void
734   add_statement(Statement*);
735
736   // Add a statement to the front of the block.
737   void
738   add_statement_at_front(Statement*);
739
740   // Replace a statement in a block.
741   void
742   replace_statement(size_t index, Statement*);
743
744   // Add a Statement before statement number INDEX.
745   void
746   insert_statement_before(size_t index, Statement*);
747
748   // Add a Statement after statement number INDEX.
749   void
750   insert_statement_after(size_t index, Statement*);
751
752   // Set the end location of the block.
753   void
754   set_end_location(source_location location)
755   { this->end_location_ = location; }
756
757   // Traverse the tree.
758   int
759   traverse(Traverse*);
760
761   // Set final types for unspecified variables and constants.
762   void
763   determine_types();
764
765   // Return true if execution of this block may fall through to the
766   // next block.
767   bool
768   may_fall_through() const;
769
770   // Return a tree of the code in this block.
771   tree
772   get_tree(Translate_context*);
773
774   // Iterate over statements.
775
776   typedef std::vector<Statement*>::iterator iterator;
777
778   iterator
779   begin()
780   { return this->statements_.begin(); }
781
782   iterator
783   end()
784   { return this->statements_.end(); }
785
786  private:
787   // Enclosing block.
788   Block* enclosing_;
789   // Statements in the block.
790   std::vector<Statement*> statements_;
791   // Binding contour.
792   Bindings* bindings_;
793   // Location of start of block.
794   source_location start_location_;
795   // Location of end of block.
796   source_location end_location_;
797 };
798
799 // A function.
800
801 class Function
802 {
803  public:
804   Function(Function_type* type, Function*, Block*, source_location);
805
806   // Return the function's type.
807   Function_type*
808   type() const
809   { return this->type_; }
810
811   // Return the enclosing function if there is one.
812   Function*
813   enclosing()
814   { return this->enclosing_; }
815
816   // Set the enclosing function.  This is used when building thunks
817   // for functions which call recover.
818   void
819   set_enclosing(Function* enclosing)
820   {
821     gcc_assert(this->enclosing_ == NULL);
822     this->enclosing_ = enclosing;
823   }
824
825   // The result variables.
826   typedef std::vector<Named_object*> Results;
827
828   // Create the result variables in the outer block.
829   void
830   create_result_variables(Gogo*);
831
832   // Update the named result variables when cloning a function which
833   // calls recover.
834   void
835   update_result_variables();
836
837   // Return the result variables.
838   Results*
839   result_variables()
840   { return this->results_; }
841
842   // Whether the result variables have names.
843   bool
844   results_are_named() const
845   { return this->results_are_named_; }
846
847   // Add a new field to the closure variable.
848   void
849   add_closure_field(Named_object* var, source_location loc)
850   { this->closure_fields_.push_back(std::make_pair(var, loc)); }
851
852   // Whether this function needs a closure.
853   bool
854   needs_closure() const
855   { return !this->closure_fields_.empty(); }
856
857   // Return the closure variable, creating it if necessary.  This is
858   // passed to the function as a static chain parameter.
859   Named_object*
860   closure_var();
861
862   // Set the closure variable.  This is used when building thunks for
863   // functions which call recover.
864   void
865   set_closure_var(Named_object* v)
866   {
867     gcc_assert(this->closure_var_ == NULL);
868     this->closure_var_ = v;
869   }
870
871   // Return the variable for a reference to field INDEX in the closure
872   // variable.
873   Named_object*
874   enclosing_var(unsigned int index)
875   {
876     gcc_assert(index < this->closure_fields_.size());
877     return closure_fields_[index].first;
878   }
879
880   // Set the type of the closure variable if there is one.
881   void
882   set_closure_type();
883
884   // Get the block of statements associated with the function.
885   Block*
886   block() const
887   { return this->block_; }
888
889   // Get the location of the start of the function.
890   source_location
891   location() const
892   { return this->location_; }
893
894   // Return whether this function is actually a method.
895   bool
896   is_method() const;
897
898   // Add a label definition to the function.
899   Label*
900   add_label_definition(const std::string& label_name, source_location);
901
902   // Add a label reference to a function.
903   Label*
904   add_label_reference(const std::string& label_name);
905
906   // Warn about labels that are defined but not used.
907   void
908   check_labels() const;
909
910   // Whether this function calls the predeclared recover function.
911   bool
912   calls_recover() const
913   { return this->calls_recover_; }
914
915   // Record that this function calls the predeclared recover function.
916   // This is set during the lowering pass.
917   void
918   set_calls_recover()
919   { this->calls_recover_ = true; }
920
921   // Whether this is a recover thunk function.
922   bool
923   is_recover_thunk() const
924   { return this->is_recover_thunk_; }
925
926   // Record that this is a thunk built for a function which calls
927   // recover.
928   void
929   set_is_recover_thunk()
930   { this->is_recover_thunk_ = true; }
931
932   // Whether this function already has a recover thunk.
933   bool
934   has_recover_thunk() const
935   { return this->has_recover_thunk_; }
936
937   // Record that this function already has a recover thunk.
938   void
939   set_has_recover_thunk()
940   { this->has_recover_thunk_ = true; }
941
942   // Swap with another function.  Used only for the thunk which calls
943   // recover.
944   void
945   swap_for_recover(Function *);
946
947   // Traverse the tree.
948   int
949   traverse(Traverse*);
950
951   // Determine types in the function.
952   void
953   determine_types();
954
955   // Return the function's decl given an identifier.
956   tree
957   get_or_make_decl(Gogo*, Named_object*, tree id);
958
959   // Return the function's decl after it has been built.
960   tree
961   get_decl() const
962   {
963     gcc_assert(this->fndecl_ != NULL);
964     return this->fndecl_;
965   }
966
967   // Set the function decl to hold a tree of the function code.
968   void
969   build_tree(Gogo*, Named_object*);
970
971   // Get the value to return when not explicitly specified.  May also
972   // add statements to execute first to STMT_LIST.
973   tree
974   return_value(Gogo*, Named_object*, source_location, tree* stmt_list) const;
975
976   // Get a tree for the variable holding the defer stack.
977   Expression*
978   defer_stack(source_location);
979
980   // Export the function.
981   void
982   export_func(Export*, const std::string& name) const;
983
984   // Export a function with a type.
985   static void
986   export_func_with_type(Export*, const std::string& name,
987                         const Function_type*);
988
989   // Import a function.
990   static void
991   import_func(Import*, std::string* pname, Typed_identifier** receiver,
992               Typed_identifier_list** pparameters,
993               Typed_identifier_list** presults, bool* is_varargs);
994
995  private:
996   // Type for mapping from label names to Label objects.
997   typedef Unordered_map(std::string, Label*) Labels;
998
999   tree
1000   make_receiver_parm_decl(Gogo*, Named_object*, tree);
1001
1002   tree
1003   copy_parm_to_heap(Gogo*, Named_object*, tree);
1004
1005   void
1006   build_defer_wrapper(Gogo*, Named_object*, tree*, tree*);
1007
1008   typedef std::vector<std::pair<Named_object*,
1009                                 source_location> > Closure_fields;
1010
1011   // The function's type.
1012   Function_type* type_;
1013   // The enclosing function.  This is NULL when there isn't one, which
1014   // is the normal case.
1015   Function* enclosing_;
1016   // The result variables, if any.
1017   Results* results_;
1018   // If there is a closure, this is the list of variables which appear
1019   // in the closure.  This is created by the parser, and then resolved
1020   // to a real type when we lower parse trees.
1021   Closure_fields closure_fields_;
1022   // The closure variable, passed as a parameter using the static
1023   // chain parameter.  Normally NULL.
1024   Named_object* closure_var_;
1025   // The outer block of statements in the function.
1026   Block* block_;
1027   // The source location of the start of the function.
1028   source_location location_;
1029   // Labels defined or referenced in the function.
1030   Labels labels_;
1031   // The function decl.
1032   tree fndecl_;
1033   // The defer stack variable.  A pointer to this variable is used to
1034   // distinguish the defer stack for one function from another.  This
1035   // is NULL unless we actually need a defer stack.
1036   Temporary_statement* defer_stack_;
1037   // True if the result variables are named.
1038   bool results_are_named_;
1039   // True if this function calls the predeclared recover function.
1040   bool calls_recover_;
1041   // True if this a thunk built for a function which calls recover.
1042   bool is_recover_thunk_;
1043   // True if this function already has a recover thunk.
1044   bool has_recover_thunk_;
1045 };
1046
1047 // A function declaration.
1048
1049 class Function_declaration
1050 {
1051  public:
1052   Function_declaration(Function_type* fntype, source_location location)
1053     : fntype_(fntype), location_(location), asm_name_(), fndecl_(NULL)
1054   { }
1055
1056   Function_type*
1057   type() const
1058   { return this->fntype_; }
1059
1060   source_location
1061   location() const
1062   { return this->location_; }
1063
1064   const std::string&
1065   asm_name() const
1066   { return this->asm_name_; }
1067
1068   // Set the assembler name.
1069   void
1070   set_asm_name(const std::string& asm_name)
1071   { this->asm_name_ = asm_name; }
1072
1073   // Return a decl for the function given an identifier.
1074   tree
1075   get_or_make_decl(Gogo*, Named_object*, tree id);
1076
1077   // Export a function declaration.
1078   void
1079   export_func(Export* exp, const std::string& name) const
1080   { Function::export_func_with_type(exp, name, this->fntype_); }
1081
1082  private:
1083   // The type of the function.
1084   Function_type* fntype_;
1085   // The location of the declaration.
1086   source_location location_;
1087   // The assembler name: this is the name to use in references to the
1088   // function.  This is normally empty.
1089   std::string asm_name_;
1090   // The function decl if needed.
1091   tree fndecl_;
1092 };
1093
1094 // A variable.
1095
1096 class Variable
1097 {
1098  public:
1099   Variable(Type*, Expression*, bool is_global, bool is_parameter,
1100            bool is_receiver, source_location);
1101
1102   // Get the type of the variable.
1103   Type*
1104   type();
1105
1106   Type*
1107   type() const;
1108
1109   // Return whether the type is defined yet.
1110   bool
1111   has_type() const
1112   { return this->type_ != NULL; }
1113
1114   // Get the initial value.
1115   Expression*
1116   init() const
1117   { return this->init_; }
1118
1119   // Return whether there are any preinit statements.
1120   bool
1121   has_pre_init() const
1122   { return this->preinit_ != NULL; }
1123
1124   // Return the preinit statements if any.
1125   Block*
1126   preinit() const
1127   { return this->preinit_; }
1128
1129   // Return whether this is a global variable.
1130   bool
1131   is_global() const
1132   { return this->is_global_; }
1133
1134   // Return whether this is a function parameter.
1135   bool
1136   is_parameter() const
1137   { return this->is_parameter_; }
1138
1139   // Return whether this is the receiver parameter of a method.
1140   bool
1141   is_receiver() const
1142   { return this->is_receiver_; }
1143
1144   // Change this parameter to be a receiver.  This is used when
1145   // creating the thunks created for functions which call recover.
1146   void
1147   set_is_receiver()
1148   {
1149     gcc_assert(this->is_parameter_);
1150     this->is_receiver_ = true;
1151   }
1152
1153   // Change this parameter to not be a receiver.  This is used when
1154   // creating the thunks created for functions which call recover.
1155   void
1156   set_is_not_receiver()
1157   {
1158     gcc_assert(this->is_parameter_);
1159     this->is_receiver_ = false;
1160   }
1161
1162   // Return whether this is the varargs parameter of a function.
1163   bool
1164   is_varargs_parameter() const
1165   { return this->is_varargs_parameter_; }
1166
1167   // Whether this variable's address is taken.
1168   bool
1169   is_address_taken() const
1170   { return this->is_address_taken_; }
1171
1172   // Whether this variable should live in the heap.
1173   bool
1174   is_in_heap() const
1175   { return this->is_address_taken_ && !this->is_global_; }
1176
1177   // Get the source location of the variable's declaration.
1178   source_location
1179   location() const
1180   { return this->location_; }
1181
1182   // Record that this is the varargs parameter of a function.
1183   void
1184   set_is_varargs_parameter()
1185   {
1186     gcc_assert(this->is_parameter_);
1187     this->is_varargs_parameter_ = true;
1188   }
1189
1190   // Clear the initial value; used for error handling.
1191   void
1192   clear_init()
1193   { this->init_ = NULL; }
1194
1195   // Set the initial value; used for converting shortcuts.
1196   void
1197   set_init(Expression* init)
1198   { this->init_ = init; }
1199
1200   // Get the preinit block, a block of statements to be run before the
1201   // initialization expression.
1202   Block*
1203   preinit_block(Gogo*);
1204
1205   // Add a statement to be run before the initialization expression.
1206   // This is only used for global variables.
1207   void
1208   add_preinit_statement(Gogo*, Statement*);
1209
1210   // Lower the initialization expression after parsing is complete.
1211   void
1212   lower_init_expression(Gogo*, Named_object*);
1213
1214   // A special case: the init value is used only to determine the
1215   // type.  This is used if the variable is defined using := with the
1216   // comma-ok form of a map index or a receive expression.  The init
1217   // value is actually the map index expression or receive expression.
1218   // We use this because we may not know the right type at parse time.
1219   void
1220   set_type_from_init_tuple()
1221   { this->type_from_init_tuple_ = true; }
1222
1223   // Another special case: the init value is used only to determine
1224   // the type.  This is used if the variable is defined using := with
1225   // a range clause.  The init value is the range expression.  The
1226   // type of the variable is the index type of the range expression
1227   // (i.e., the first value returned by a range).
1228   void
1229   set_type_from_range_index()
1230   { this->type_from_range_index_ = true; }
1231
1232   // Another special case: like set_type_from_range_index, but the
1233   // type is the value type of the range expression (i.e., the second
1234   // value returned by a range).
1235   void
1236   set_type_from_range_value()
1237   { this->type_from_range_value_ = true; }
1238
1239   // Another special case: the init value is used only to determine
1240   // the type.  This is used if the variable is defined using := with
1241   // a case in a select statement.  The init value is the channel.
1242   // The type of the variable is the channel's element type.
1243   void
1244   set_type_from_chan_element()
1245   { this->type_from_chan_element_ = true; }
1246
1247   // After we lower the select statement, we once again set the type
1248   // from the initialization expression.
1249   void
1250   clear_type_from_chan_element()
1251   {
1252     gcc_assert(this->type_from_chan_element_);
1253     this->type_from_chan_element_ = false;
1254   }
1255
1256   // Note that this variable was created for a type switch clause.
1257   void
1258   set_is_type_switch_var()
1259   { this->is_type_switch_var_ = true; }
1260
1261   // Traverse the initializer expression.
1262   int
1263   traverse_expression(Traverse*);
1264
1265   // Determine the type of the variable if necessary.
1266   void
1267   determine_type();
1268
1269   // Note that something takes the address of this variable.
1270   void
1271   set_address_taken()
1272   { this->is_address_taken_ = true; }
1273
1274   // Get the backend representation of the variable.
1275   Bvariable*
1276   get_backend_variable(Gogo*, Named_object*, const Package*,
1277                        const std::string&);
1278
1279   // Get the initial value of the variable as a tree.  This may only
1280   // be called if has_pre_init() returns false.
1281   tree
1282   get_init_tree(Gogo*, Named_object* function);
1283
1284   // Return a series of statements which sets the value of the
1285   // variable in DECL.  This should only be called is has_pre_init()
1286   // returns true.  DECL may be NULL for a sink variable.
1287   tree
1288   get_init_block(Gogo*, Named_object* function, tree decl);
1289
1290   // Export the variable.
1291   void
1292   export_var(Export*, const std::string& name) const;
1293
1294   // Import a variable.
1295   static void
1296   import_var(Import*, std::string* pname, Type** ptype);
1297
1298  private:
1299   // The type of a tuple.
1300   Type*
1301   type_from_tuple(Expression*, bool) const;
1302
1303   // The type of a range.
1304   Type*
1305   type_from_range(Expression*, bool, bool) const;
1306
1307   // The element type of a channel.
1308   Type*
1309   type_from_chan_element(Expression*, bool) const;
1310
1311   // The variable's type.  This may be NULL if the type is set from
1312   // the expression.
1313   Type* type_;
1314   // The initial value.  This may be NULL if the variable should be
1315   // initialized to the default value for the type.
1316   Expression* init_;
1317   // Statements to run before the init statement.
1318   Block* preinit_;
1319   // Location of variable definition.
1320   source_location location_;
1321   // Backend representation.
1322   Bvariable* backend_;
1323   // Whether this is a global variable.
1324   bool is_global_ : 1;
1325   // Whether this is a function parameter.
1326   bool is_parameter_ : 1;
1327   // Whether this is the receiver parameter of a method.
1328   bool is_receiver_ : 1;
1329   // Whether this is the varargs parameter of a function.
1330   bool is_varargs_parameter_ : 1;
1331   // Whether something takes the address of this variable.
1332   bool is_address_taken_ : 1;
1333   // True if we have seen this variable in a traversal.
1334   bool seen_ : 1;
1335   // True if we have lowered the initialization expression.
1336   bool init_is_lowered_ : 1;
1337   // True if init is a tuple used to set the type.
1338   bool type_from_init_tuple_ : 1;
1339   // True if init is a range clause and the type is the index type.
1340   bool type_from_range_index_ : 1;
1341   // True if init is a range clause and the type is the value type.
1342   bool type_from_range_value_ : 1;
1343   // True if init is a channel and the type is the channel's element type.
1344   bool type_from_chan_element_ : 1;
1345   // True if this is a variable created for a type switch case.
1346   bool is_type_switch_var_ : 1;
1347   // True if we have determined types.
1348   bool determined_type_ : 1;
1349 };
1350
1351 // A variable which is really the name for a function return value, or
1352 // part of one.
1353
1354 class Result_variable
1355 {
1356  public:
1357   Result_variable(Type* type, Function* function, int index,
1358                   source_location location)
1359     : type_(type), function_(function), index_(index), location_(location),
1360       backend_(NULL), is_address_taken_(false)
1361   { }
1362
1363   // Get the type of the result variable.
1364   Type*
1365   type() const
1366   { return this->type_; }
1367
1368   // Get the function that this is associated with.
1369   Function*
1370   function() const
1371   { return this->function_; }
1372
1373   // Index in the list of function results.
1374   int
1375   index() const
1376   { return this->index_; }
1377
1378   // The location of the variable definition.
1379   source_location
1380   location() const
1381   { return this->location_; }
1382
1383   // Whether this variable's address is taken.
1384   bool
1385   is_address_taken() const
1386   { return this->is_address_taken_; }
1387
1388   // Note that something takes the address of this variable.
1389   void
1390   set_address_taken()
1391   { this->is_address_taken_ = true; }
1392
1393   // Whether this variable should live in the heap.
1394   bool
1395   is_in_heap() const
1396   { return this->is_address_taken_; }
1397
1398   // Set the function.  This is used when cloning functions which call
1399   // recover.
1400   void
1401   set_function(Function* function)
1402   { this->function_ = function; }
1403
1404   // Get the backend representation of the variable.
1405   Bvariable*
1406   get_backend_variable(Gogo*, Named_object*, const std::string&);
1407
1408  private:
1409   // Type of result variable.
1410   Type* type_;
1411   // Function with which this is associated.
1412   Function* function_;
1413   // Index in list of results.
1414   int index_;
1415   // Where the result variable is defined.
1416   source_location location_;
1417   // Backend representation.
1418   Bvariable* backend_;
1419   // Whether something takes the address of this variable.
1420   bool is_address_taken_;
1421 };
1422
1423 // The value we keep for a named constant.  This lets us hold a type
1424 // and an expression.
1425
1426 class Named_constant
1427 {
1428  public:
1429   Named_constant(Type* type, Expression* expr, int iota_value,
1430                  source_location location)
1431     : type_(type), expr_(expr), iota_value_(iota_value), location_(location),
1432       lowering_(false)
1433   { }
1434
1435   Type*
1436   type() const
1437   { return this->type_; }
1438
1439   Expression*
1440   expr() const
1441   { return this->expr_; }
1442
1443   int
1444   iota_value() const
1445   { return this->iota_value_; }
1446
1447   source_location
1448   location() const
1449   { return this->location_; }
1450
1451   // Whether we are lowering.
1452   bool
1453   lowering() const
1454   { return this->lowering_; }
1455
1456   // Set that we are lowering.
1457   void
1458   set_lowering()
1459   { this->lowering_ = true; }
1460
1461   // We are no longer lowering.
1462   void
1463   clear_lowering()
1464   { this->lowering_ = false; }
1465
1466   // Traverse the expression.
1467   int
1468   traverse_expression(Traverse*);
1469
1470   // Determine the type of the constant if necessary.
1471   void
1472   determine_type();
1473
1474   // Indicate that we found and reported an error for this constant.
1475   void
1476   set_error();
1477
1478   // Export the constant.
1479   void
1480   export_const(Export*, const std::string& name) const;
1481
1482   // Import a constant.
1483   static void
1484   import_const(Import*, std::string*, Type**, Expression**);
1485
1486  private:
1487   // The type of the constant.
1488   Type* type_;
1489   // The expression for the constant.
1490   Expression* expr_;
1491   // If the predeclared constant iota is used in EXPR_, this is the
1492   // value it will have.  We do this because at parse time we don't
1493   // know whether the name "iota" will refer to the predeclared
1494   // constant or to something else.  We put in the right value in when
1495   // we lower.
1496   int iota_value_;
1497   // The location of the definition.
1498   source_location location_;
1499   // Whether we are currently lowering this constant.
1500   bool lowering_;
1501 };
1502
1503 // A type declaration.
1504
1505 class Type_declaration
1506 {
1507  public:
1508   Type_declaration(source_location location)
1509     : location_(location), in_function_(NULL), methods_(),
1510       issued_warning_(false)
1511   { }
1512
1513   // Return the location.
1514   source_location
1515   location() const
1516   { return this->location_; }
1517
1518   // Return the function in which this type is declared.  This will
1519   // return NULL for a type declared in global scope.
1520   Named_object*
1521   in_function()
1522   { return this->in_function_; }
1523
1524   // Set the function in which this type is declared.
1525   void
1526   set_in_function(Named_object* f)
1527   { this->in_function_ = f; }
1528
1529   // Add a method to this type.  This is used when methods are defined
1530   // before the type.
1531   Named_object*
1532   add_method(const std::string& name, Function* function);
1533
1534   // Add a method declaration to this type.
1535   Named_object*
1536   add_method_declaration(const std::string& name, Function_type* type,
1537                          source_location location);
1538
1539   // Return whether any methods were defined.
1540   bool
1541   has_methods() const;
1542
1543   // Define methods when the real type is known.
1544   void
1545   define_methods(Named_type*);
1546
1547   // This is called if we are trying to use this type.  It returns
1548   // true if we should issue a warning.
1549   bool
1550   using_type();
1551
1552  private:
1553   typedef std::vector<Named_object*> Methods;
1554
1555   // The location of the type declaration.
1556   source_location location_;
1557   // If this type is declared in a function, a pointer back to the
1558   // function in which it is defined.
1559   Named_object* in_function_;
1560   // Methods defined before the type is defined.
1561   Methods methods_;
1562   // True if we have issued a warning about a use of this type
1563   // declaration when it is undefined.
1564   bool issued_warning_;
1565 };
1566
1567 // An unknown object.  These are created by the parser for forward
1568 // references to names which have not been seen before.  In a correct
1569 // program, these will always point to a real definition by the end of
1570 // the parse.  Because they point to another Named_object, these may
1571 // only be referenced by Unknown_expression objects.
1572
1573 class Unknown_name
1574 {
1575  public:
1576   Unknown_name(source_location location)
1577     : location_(location), real_named_object_(NULL)
1578   { }
1579
1580   // Return the location where this name was first seen.
1581   source_location
1582   location() const
1583   { return this->location_; }
1584
1585   // Return the real named object that this points to, or NULL if it
1586   // was never resolved.
1587   Named_object*
1588   real_named_object() const
1589   { return this->real_named_object_; }
1590
1591   // Set the real named object that this points to.
1592   void
1593   set_real_named_object(Named_object* no);
1594
1595  private:
1596   // The location where this name was first seen.
1597   source_location location_;
1598   // The real named object when it is known.
1599   Named_object*
1600   real_named_object_;
1601 };
1602
1603 // A named object named.  This is the result of a declaration.  We
1604 // don't use a superclass because they all have to be handled
1605 // differently.
1606
1607 class Named_object
1608 {
1609  public:
1610   enum Classification
1611   {
1612     // An uninitialized Named_object.  We should never see this.
1613     NAMED_OBJECT_UNINITIALIZED,
1614     // An unknown name.  This is used for forward references.  In a
1615     // correct program, these will all be resolved by the end of the
1616     // parse.
1617     NAMED_OBJECT_UNKNOWN,
1618     // A const.
1619     NAMED_OBJECT_CONST,
1620     // A type.
1621     NAMED_OBJECT_TYPE,
1622     // A forward type declaration.
1623     NAMED_OBJECT_TYPE_DECLARATION,
1624     // A var.
1625     NAMED_OBJECT_VAR,
1626     // A result variable in a function.
1627     NAMED_OBJECT_RESULT_VAR,
1628     // The blank identifier--the special variable named _.
1629     NAMED_OBJECT_SINK,
1630     // A func.
1631     NAMED_OBJECT_FUNC,
1632     // A forward func declaration.
1633     NAMED_OBJECT_FUNC_DECLARATION,
1634     // A package.
1635     NAMED_OBJECT_PACKAGE
1636   };
1637
1638   // Return the classification.
1639   Classification
1640   classification() const
1641   { return this->classification_; }
1642
1643   // Classifiers.
1644
1645   bool
1646   is_unknown() const
1647   { return this->classification_ == NAMED_OBJECT_UNKNOWN; }
1648
1649   bool
1650   is_const() const
1651   { return this->classification_ == NAMED_OBJECT_CONST; }
1652
1653   bool
1654   is_type() const
1655   { return this->classification_ == NAMED_OBJECT_TYPE; }
1656
1657   bool
1658   is_type_declaration() const
1659   { return this->classification_ == NAMED_OBJECT_TYPE_DECLARATION; }
1660
1661   bool
1662   is_variable() const
1663   { return this->classification_ == NAMED_OBJECT_VAR; }
1664
1665   bool
1666   is_result_variable() const
1667   { return this->classification_ == NAMED_OBJECT_RESULT_VAR; }
1668
1669   bool
1670   is_sink() const
1671   { return this->classification_ == NAMED_OBJECT_SINK; }
1672
1673   bool
1674   is_function() const
1675   { return this->classification_ == NAMED_OBJECT_FUNC; }
1676
1677   bool
1678   is_function_declaration() const
1679   { return this->classification_ == NAMED_OBJECT_FUNC_DECLARATION; }
1680
1681   bool
1682   is_package() const
1683   { return this->classification_ == NAMED_OBJECT_PACKAGE; }
1684
1685   // Creators.
1686
1687   static Named_object*
1688   make_unknown_name(const std::string& name, source_location);
1689
1690   static Named_object*
1691   make_constant(const Typed_identifier&, const Package*, Expression*,
1692                 int iota_value);
1693
1694   static Named_object*
1695   make_type(const std::string&, const Package*, Type*, source_location);
1696
1697   static Named_object*
1698   make_type_declaration(const std::string&, const Package*, source_location);
1699
1700   static Named_object*
1701   make_variable(const std::string&, const Package*, Variable*);
1702
1703   static Named_object*
1704   make_result_variable(const std::string&, Result_variable*);
1705
1706   static Named_object*
1707   make_sink();
1708
1709   static Named_object*
1710   make_function(const std::string&, const Package*, Function*);
1711
1712   static Named_object*
1713   make_function_declaration(const std::string&, const Package*, Function_type*,
1714                             source_location);
1715
1716   static Named_object*
1717   make_package(const std::string& alias, Package* package);
1718
1719   // Getters.
1720
1721   Unknown_name*
1722   unknown_value()
1723   {
1724     gcc_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
1725     return this->u_.unknown_value;
1726   }
1727
1728   const Unknown_name*
1729   unknown_value() const
1730   {
1731     gcc_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
1732     return this->u_.unknown_value;
1733   }
1734
1735   Named_constant*
1736   const_value()
1737   {
1738     gcc_assert(this->classification_ == NAMED_OBJECT_CONST);
1739     return this->u_.const_value;
1740   }
1741
1742   const Named_constant*
1743   const_value() const
1744   {
1745     gcc_assert(this->classification_ == NAMED_OBJECT_CONST);
1746     return this->u_.const_value;
1747   }
1748
1749   Named_type*
1750   type_value()
1751   {
1752     gcc_assert(this->classification_ == NAMED_OBJECT_TYPE);
1753     return this->u_.type_value;
1754   }
1755
1756   const Named_type*
1757   type_value() const
1758   {
1759     gcc_assert(this->classification_ == NAMED_OBJECT_TYPE);
1760     return this->u_.type_value;
1761   }
1762
1763   Type_declaration*
1764   type_declaration_value()
1765   {
1766     gcc_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
1767     return this->u_.type_declaration;
1768   }
1769
1770   const Type_declaration*
1771   type_declaration_value() const
1772   {
1773     gcc_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
1774     return this->u_.type_declaration;
1775   }
1776
1777   Variable*
1778   var_value()
1779   {
1780     gcc_assert(this->classification_ == NAMED_OBJECT_VAR);
1781     return this->u_.var_value;
1782   }
1783
1784   const Variable*
1785   var_value() const
1786   {
1787     gcc_assert(this->classification_ == NAMED_OBJECT_VAR);
1788     return this->u_.var_value;
1789   }
1790
1791   Result_variable*
1792   result_var_value()
1793   {
1794     gcc_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
1795     return this->u_.result_var_value;
1796   }
1797
1798   const Result_variable*
1799   result_var_value() const
1800   {
1801     gcc_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
1802     return this->u_.result_var_value;
1803   }
1804
1805   Function*
1806   func_value()
1807   {
1808     gcc_assert(this->classification_ == NAMED_OBJECT_FUNC);
1809     return this->u_.func_value;
1810   }
1811
1812   const Function*
1813   func_value() const
1814   {
1815     gcc_assert(this->classification_ == NAMED_OBJECT_FUNC);
1816     return this->u_.func_value;
1817   }
1818
1819   Function_declaration*
1820   func_declaration_value()
1821   {
1822     gcc_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
1823     return this->u_.func_declaration_value;
1824   }
1825
1826   const Function_declaration*
1827   func_declaration_value() const
1828   {
1829     gcc_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
1830     return this->u_.func_declaration_value;
1831   }
1832
1833   Package*
1834   package_value()
1835   {
1836     gcc_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
1837     return this->u_.package_value;
1838   }
1839
1840   const Package*
1841   package_value() const
1842   {
1843     gcc_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
1844     return this->u_.package_value;
1845   }
1846
1847   const std::string&
1848   name() const
1849   { return this->name_; }
1850
1851   // Return the name to use in an error message.  The difference is
1852   // that if this Named_object is defined in a different package, this
1853   // will return PACKAGE.NAME.
1854   std::string
1855   message_name() const;
1856
1857   const Package*
1858   package() const
1859   { return this->package_; }
1860
1861   // Resolve an unknown value if possible.  This returns the same
1862   // Named_object or a new one.
1863   Named_object*
1864   resolve()
1865   {
1866     Named_object* ret = this;
1867     if (this->is_unknown())
1868       {
1869         Named_object* r = this->unknown_value()->real_named_object();
1870         if (r != NULL)
1871           ret = r;
1872       }
1873     return ret;
1874   }
1875
1876   const Named_object*
1877   resolve() const
1878   {
1879     const Named_object* ret = this;
1880     if (this->is_unknown())
1881       {
1882         const Named_object* r = this->unknown_value()->real_named_object();
1883         if (r != NULL)
1884           ret = r;
1885       }
1886     return ret;
1887   }
1888
1889   // The location where this object was defined or referenced.
1890   source_location
1891   location() const;
1892
1893   // Convert a variable to the backend representation.
1894   Bvariable*
1895   get_backend_variable(Gogo*, Named_object* function);
1896
1897   // Return a tree for the external identifier for this object.
1898   tree
1899   get_id(Gogo*);
1900
1901   // Return a tree representing this object.
1902   tree
1903   get_tree(Gogo*, Named_object* function);
1904
1905   // Define a type declaration.
1906   void
1907   set_type_value(Named_type*);
1908
1909   // Define a function declaration.
1910   void
1911   set_function_value(Function*);
1912
1913   // Declare an unknown name as a type declaration.
1914   void
1915   declare_as_type();
1916
1917   // Export this object.
1918   void
1919   export_named_object(Export*) const;
1920
1921  private:
1922   Named_object(const std::string&, const Package*, Classification);
1923
1924   // The name of the object.
1925   std::string name_;
1926   // The package that this object is in.  This is NULL if it is in the
1927   // file we are compiling.
1928   const Package* package_;
1929   // The type of object this is.
1930   Classification classification_;
1931   // The real data.
1932   union
1933   {
1934     Unknown_name* unknown_value;
1935     Named_constant* const_value;
1936     Named_type* type_value;
1937     Type_declaration* type_declaration;
1938     Variable* var_value;
1939     Result_variable* result_var_value;
1940     Function* func_value;
1941     Function_declaration* func_declaration_value;
1942     Package* package_value;
1943   } u_;
1944   // The DECL tree for this object if we have already converted it.
1945   tree tree_;
1946 };
1947
1948 // A binding contour.  This binds names to objects.
1949
1950 class Bindings
1951 {
1952  public:
1953   // Type for mapping from names to objects.
1954   typedef Unordered_map(std::string, Named_object*) Contour;
1955
1956   Bindings(Bindings* enclosing);
1957
1958   // Add an unknown name.
1959   Named_object*
1960   add_unknown_name(const std::string& name, source_location location)
1961   {
1962     return this->add_named_object(Named_object::make_unknown_name(name,
1963                                                                   location));
1964   }
1965
1966   // Add a constant.
1967   Named_object*
1968   add_constant(const Typed_identifier& tid, const Package* package,
1969                Expression* expr, int iota_value)
1970   {
1971     return this->add_named_object(Named_object::make_constant(tid, package,
1972                                                               expr,
1973                                                               iota_value));
1974   }
1975
1976   // Add a type.
1977   Named_object*
1978   add_type(const std::string& name, const Package* package, Type* type,
1979            source_location location)
1980   {
1981     return this->add_named_object(Named_object::make_type(name, package, type,
1982                                                           location));
1983   }
1984
1985   // Add a named type.  This is used for builtin types, and to add an
1986   // imported type to the global scope.
1987   Named_object*
1988   add_named_type(Named_type* named_type);
1989
1990   // Add a type declaration.
1991   Named_object*
1992   add_type_declaration(const std::string& name, const Package* package,
1993                        source_location location)
1994   {
1995     Named_object* no = Named_object::make_type_declaration(name, package,
1996                                                            location);
1997     return this->add_named_object(no);
1998   }
1999
2000   // Add a variable.
2001   Named_object*
2002   add_variable(const std::string& name, const Package* package,
2003                Variable* variable)
2004   {
2005     return this->add_named_object(Named_object::make_variable(name, package,
2006                                                               variable));
2007   }
2008
2009   // Add a result variable.
2010   Named_object*
2011   add_result_variable(const std::string& name, Result_variable* result)
2012   {
2013     return this->add_named_object(Named_object::make_result_variable(name,
2014                                                                      result));
2015   }
2016
2017   // Add a function.
2018   Named_object*
2019   add_function(const std::string& name, const Package*, Function* function);
2020
2021   // Add a function declaration.
2022   Named_object*
2023   add_function_declaration(const std::string& name, const Package* package,
2024                            Function_type* type, source_location location);
2025
2026   // Add a package.  The location is the location of the import
2027   // statement.
2028   Named_object*
2029   add_package(const std::string& alias, Package* package)
2030   {
2031     Named_object* no = Named_object::make_package(alias, package);
2032     return this->add_named_object(no);
2033   }
2034
2035   // Define a type which was already declared.
2036   void
2037   define_type(Named_object*, Named_type*);
2038
2039   // Add a method to the list of objects.  This is not added to the
2040   // lookup table.
2041   void
2042   add_method(Named_object*);
2043
2044   // Add a named object to this binding.
2045   Named_object*
2046   add_named_object(Named_object* no)
2047   { return this->add_named_object_to_contour(&this->bindings_, no); }
2048
2049   // Clear all names in file scope from the bindings.
2050   void
2051   clear_file_scope();
2052
2053   // Look up a name in this binding contour and in any enclosing
2054   // binding contours.  This returns NULL if the name is not found.
2055   Named_object*
2056   lookup(const std::string&) const;
2057
2058   // Look up a name in this binding contour without looking in any
2059   // enclosing binding contours.  Returns NULL if the name is not found.
2060   Named_object*
2061   lookup_local(const std::string&) const;
2062
2063   // Remove a name.
2064   void
2065   remove_binding(Named_object*);
2066
2067   // Traverse the tree.  See the Traverse class.
2068   int
2069   traverse(Traverse*, bool is_global);
2070
2071   // Iterate over definitions.  This does not include things which
2072   // were only declared.
2073
2074   typedef std::vector<Named_object*>::const_iterator
2075     const_definitions_iterator;
2076
2077   const_definitions_iterator
2078   begin_definitions() const
2079   { return this->named_objects_.begin(); }
2080
2081   const_definitions_iterator
2082   end_definitions() const
2083   { return this->named_objects_.end(); }
2084
2085   // Return the number of definitions.
2086   size_t
2087   size_definitions() const
2088   { return this->named_objects_.size(); }
2089
2090   // Return whether there are no definitions.
2091   bool
2092   empty_definitions() const
2093   { return this->named_objects_.empty(); }
2094
2095   // Iterate over declarations.  This is everything that has been
2096   // declared, which includes everything which has been defined.
2097
2098   typedef Contour::const_iterator const_declarations_iterator;
2099
2100   const_declarations_iterator
2101   begin_declarations() const
2102   { return this->bindings_.begin(); }
2103
2104   const_declarations_iterator
2105   end_declarations() const
2106   { return this->bindings_.end(); }
2107
2108   // Return the number of declarations.
2109   size_t
2110   size_declarations() const
2111   { return this->bindings_.size(); }
2112
2113   // Return whether there are no declarations.
2114   bool
2115   empty_declarations() const
2116   { return this->bindings_.empty(); }
2117
2118   // Return the first declaration.
2119   Named_object*
2120   first_declaration()
2121   { return this->bindings_.empty() ? NULL : this->bindings_.begin()->second; }
2122
2123  private:
2124   Named_object*
2125   add_named_object_to_contour(Contour*, Named_object*);
2126
2127   Named_object*
2128   new_definition(Named_object*, Named_object*);
2129
2130   // Enclosing bindings.
2131   Bindings* enclosing_;
2132   // The list of objects.
2133   std::vector<Named_object*> named_objects_;
2134   // The mapping from names to objects.
2135   Contour bindings_;
2136 };
2137
2138 // A label.
2139
2140 class Label
2141 {
2142  public:
2143   Label(const std::string& name)
2144     : name_(name), location_(0), is_used_(false), blabel_(NULL)
2145   { }
2146
2147   // Return the label's name.
2148   const std::string&
2149   name() const
2150   { return this->name_; }
2151
2152   // Return whether the label has been defined.
2153   bool
2154   is_defined() const
2155   { return this->location_ != 0; }
2156
2157   // Return whether the label has been used.
2158   bool
2159   is_used() const
2160   { return this->is_used_; }
2161
2162   // Record that the label is used.
2163   void
2164   set_is_used()
2165   { this->is_used_ = true; }
2166
2167   // Return the location of the definition.
2168   source_location
2169   location() const
2170   { return this->location_; }
2171
2172   // Define the label at LOCATION.
2173   void
2174   define(source_location location)
2175   {
2176     gcc_assert(this->location_ == 0);
2177     this->location_ = location;
2178   }
2179
2180   // Return the backend representation for this label.
2181   Blabel*
2182   get_backend_label(Translate_context*);
2183
2184   // Return an expression for the address of this label.  This is used
2185   // to get the return address of a deferred function to see whether
2186   // the function may call recover.
2187   Bexpression*
2188   get_addr(Translate_context*, source_location location);
2189
2190  private:
2191   // The name of the label.
2192   std::string name_;
2193   // The location of the definition.  This is 0 if the label has not
2194   // yet been defined.
2195   source_location location_;
2196   // Whether the label has been used.
2197   bool is_used_;
2198   // The backend representation.
2199   Blabel* blabel_;
2200 };
2201
2202 // An unnamed label.  These are used when lowering loops.
2203
2204 class Unnamed_label
2205 {
2206  public:
2207   Unnamed_label(source_location location)
2208     : location_(location), blabel_(NULL)
2209   { }
2210
2211   // Get the location where the label is defined.
2212   source_location
2213   location() const
2214   { return this->location_; }
2215
2216   // Set the location where the label is defined.
2217   void
2218   set_location(source_location location)
2219   { this->location_ = location; }
2220
2221   // Return a statement which defines this label.
2222   Bstatement*
2223   get_definition(Translate_context*);
2224
2225   // Return a goto to this label from LOCATION.
2226   Bstatement*
2227   get_goto(Translate_context*, source_location location);
2228
2229  private:
2230   // Return the backend representation.
2231   Blabel*
2232   get_blabel(Translate_context*);
2233
2234   // The location where the label is defined.
2235   source_location location_;
2236   // The backend representation of this label.
2237   Blabel* blabel_;
2238 };
2239
2240 // An imported package.
2241
2242 class Package
2243 {
2244  public:
2245   Package(const std::string& name, const std::string& unique_prefix,
2246           source_location location);
2247
2248   // The real name of this package.  This may be different from the
2249   // name in the associated Named_object if the import statement used
2250   // an alias.
2251   const std::string&
2252   name() const
2253   { return this->name_; }
2254
2255   // Return the location of the import statement.
2256   source_location
2257   location() const
2258   { return this->location_; }
2259
2260   // Get the unique prefix used for all symbols exported from this
2261   // package.
2262   const std::string&
2263   unique_prefix() const
2264   {
2265     gcc_assert(!this->unique_prefix_.empty());
2266     return this->unique_prefix_;
2267   }
2268
2269   // The priority of this package.  The init function of packages with
2270   // lower priority must be run before the init function of packages
2271   // with higher priority.
2272   int
2273   priority() const
2274   { return this->priority_; }
2275
2276   // Set the priority.
2277   void
2278   set_priority(int priority);
2279
2280   // Return the bindings.
2281   Bindings*
2282   bindings()
2283   { return this->bindings_; }
2284
2285   // Whether some symbol from the package was used.
2286   bool
2287   used() const
2288   { return this->used_; }
2289
2290   // Note that some symbol from this package was used.
2291   void
2292   set_used() const
2293   { this->used_ = true; }
2294
2295   // Clear the used field for the next file.
2296   void
2297   clear_used()
2298   { this->used_ = false; }
2299
2300   // Whether this package was imported in the current file.
2301   bool
2302   is_imported() const
2303   { return this->is_imported_; }
2304
2305   // Note that this package was imported in the current file.
2306   void
2307   set_is_imported()
2308   { this->is_imported_ = true; }
2309
2310   // Clear the imported field for the next file.
2311   void
2312   clear_is_imported()
2313   { this->is_imported_ = false; }
2314
2315   // Whether this package was imported with a name of "_".
2316   bool
2317   uses_sink_alias() const
2318   { return this->uses_sink_alias_; }
2319
2320   // Note that this package was imported with a name of "_".
2321   void
2322   set_uses_sink_alias()
2323   { this->uses_sink_alias_ = true; }
2324
2325   // Clear the sink alias field for the next file.
2326   void
2327   clear_uses_sink_alias()
2328   { this->uses_sink_alias_ = false; }
2329
2330   // Look up a name in the package.  Returns NULL if the name is not
2331   // found.
2332   Named_object*
2333   lookup(const std::string& name) const
2334   { return this->bindings_->lookup(name); }
2335
2336   // Set the location of the package.  This is used if it is seen in a
2337   // different import before it is really imported.
2338   void
2339   set_location(source_location location)
2340   { this->location_ = location; }
2341
2342   // Add a constant to the package.
2343   Named_object*
2344   add_constant(const Typed_identifier& tid, Expression* expr)
2345   { return this->bindings_->add_constant(tid, this, expr, 0); }
2346
2347   // Add a type to the package.
2348   Named_object*
2349   add_type(const std::string& name, Type* type, source_location location)
2350   { return this->bindings_->add_type(name, this, type, location); }
2351
2352   // Add a type declaration to the package.
2353   Named_object*
2354   add_type_declaration(const std::string& name, source_location location)
2355   { return this->bindings_->add_type_declaration(name, this, location); }
2356
2357   // Add a variable to the package.
2358   Named_object*
2359   add_variable(const std::string& name, Variable* variable)
2360   { return this->bindings_->add_variable(name, this, variable); }
2361
2362   // Add a function declaration to the package.
2363   Named_object*
2364   add_function_declaration(const std::string& name, Function_type* type,
2365                            source_location loc)
2366   { return this->bindings_->add_function_declaration(name, this, type, loc); }
2367
2368   // Determine types of constants.
2369   void
2370   determine_types();
2371
2372  private:
2373   // The real name of this package.
2374   std::string name_;
2375   // The unique prefix for all exported global symbols.
2376   std::string unique_prefix_;
2377   // The names in this package.
2378   Bindings* bindings_;
2379   // The priority of this package.  A package has a priority higher
2380   // than the priority of all of the packages that it imports.  This
2381   // is used to run init functions in the right order.
2382   int priority_;
2383   // The location of the import statement.
2384   source_location location_;
2385   // True if some name from this package was used.  This is mutable
2386   // because we can use a package even if we have a const pointer to
2387   // it.
2388   mutable bool used_;
2389   // True if this package was imported in the current file.
2390   bool is_imported_;
2391   // True if this package was imported with a name of "_".
2392   bool uses_sink_alias_;
2393 };
2394
2395 // Return codes for the traversal functions.  This is not an enum
2396 // because we want to be able to declare traversal functions in other
2397 // header files without including this one.
2398
2399 // Continue traversal as usual.
2400 const int TRAVERSE_CONTINUE = -1;
2401
2402 // Exit traversal.
2403 const int TRAVERSE_EXIT = 0;
2404
2405 // Continue traversal, but skip components of the current object.
2406 // E.g., if this is returned by Traverse::statement, we do not
2407 // traverse the expressions in the statement even if
2408 // traverse_expressions is set in the traverse_mask.
2409 const int TRAVERSE_SKIP_COMPONENTS = 1;
2410
2411 // This class is used when traversing the parse tree.  The caller uses
2412 // a subclass which overrides functions as desired.
2413
2414 class Traverse
2415 {
2416  public:
2417   // These bitmasks say what to traverse.
2418   static const unsigned int traverse_variables =    0x1;
2419   static const unsigned int traverse_constants =    0x2;
2420   static const unsigned int traverse_functions =    0x4;
2421   static const unsigned int traverse_blocks =       0x8;
2422   static const unsigned int traverse_statements =  0x10;
2423   static const unsigned int traverse_expressions = 0x20;
2424   static const unsigned int traverse_types =       0x40;
2425
2426   Traverse(unsigned int traverse_mask)
2427     : traverse_mask_(traverse_mask), types_seen_(NULL), expressions_seen_(NULL)
2428   { }
2429
2430   virtual ~Traverse();
2431
2432   // The bitmask of what to traverse.
2433   unsigned int
2434   traverse_mask() const
2435   { return this->traverse_mask_; }
2436
2437   // Record that we are going to traverse a type.  This returns true
2438   // if the type has already been seen in this traversal.  This is
2439   // required because types, unlike expressions, can form a circular
2440   // graph.
2441   bool
2442   remember_type(const Type*);
2443
2444   // Record that we are going to see an expression.  This returns true
2445   // if the expression has already been seen in this traversal.  This
2446   // is only needed for cases where multiple expressions can point to
2447   // a single one.
2448   bool
2449   remember_expression(const Expression*);
2450
2451   // These functions return one of the TRAVERSE codes defined above.
2452
2453   // If traverse_variables is set in the mask, this is called for
2454   // every variable in the tree.
2455   virtual int
2456   variable(Named_object*);
2457
2458   // If traverse_constants is set in the mask, this is called for
2459   // every named constant in the tree.  The bool parameter is true for
2460   // a global constant.
2461   virtual int
2462   constant(Named_object*, bool);
2463
2464   // If traverse_functions is set in the mask, this is called for
2465   // every function in the tree.
2466   virtual int
2467   function(Named_object*);
2468
2469   // If traverse_blocks is set in the mask, this is called for every
2470   // block in the tree.
2471   virtual int
2472   block(Block*);
2473
2474   // If traverse_statements is set in the mask, this is called for
2475   // every statement in the tree.
2476   virtual int
2477   statement(Block*, size_t* index, Statement*);
2478
2479   // If traverse_expressions is set in the mask, this is called for
2480   // every expression in the tree.
2481   virtual int
2482   expression(Expression**);
2483
2484   // If traverse_types is set in the mask, this is called for every
2485   // type in the tree.
2486   virtual int
2487   type(Type*);
2488
2489  private:
2490   typedef Unordered_set_hash(const Type*, Type_hash_identical,
2491                              Type_identical) Types_seen;
2492
2493   typedef Unordered_set(const Expression*) Expressions_seen;
2494
2495   // Bitmask of what sort of objects to traverse.
2496   unsigned int traverse_mask_;
2497   // Types which have been seen in this traversal.
2498   Types_seen* types_seen_;
2499   // Expressions which have been seen in this traversal.
2500   Expressions_seen* expressions_seen_;
2501 };
2502
2503 // When translating the gogo IR into the backend data structure, this
2504 // is the context we pass down the blocks and statements.
2505
2506 class Translate_context
2507 {
2508  public:
2509   Translate_context(Gogo* gogo, Named_object* function, Block* block,
2510                     tree block_tree)
2511     : gogo_(gogo), backend_(gogo->backend()), function_(function),
2512       block_(block), block_tree_(block_tree), is_const_(false)
2513   { }
2514
2515   // Accessors.
2516
2517   Gogo*
2518   gogo()
2519   { return this->gogo_; }
2520
2521   Backend*
2522   backend()
2523   { return this->backend_; }
2524
2525   Named_object*
2526   function()
2527   { return this->function_; }
2528
2529   Block*
2530   block()
2531   { return this->block_; }
2532
2533   tree
2534   block_tree()
2535   { return this->block_tree_; }
2536
2537   bool
2538   is_const()
2539   { return this->is_const_; }
2540
2541   // Make a constant context.
2542   void
2543   set_is_const()
2544   { this->is_const_ = true; }
2545
2546  private:
2547   // The IR for the entire compilation unit.
2548   Gogo* gogo_;
2549   // The generator for the backend data structures.
2550   Backend* backend_;
2551   // The function we are currently translating.
2552   Named_object* function_;
2553   // The block we are currently translating.
2554   Block *block_;
2555   // The BLOCK node for the current block.
2556   tree block_tree_;
2557   // Whether this is being evaluated in a constant context.  This is
2558   // used for type descriptor initializers.
2559   bool is_const_;
2560 };
2561
2562 // Runtime error codes.  These must match the values in
2563 // libgo/runtime/go-runtime-error.c.
2564
2565 // Slice index out of bounds: negative or larger than the length of
2566 // the slice.
2567 static const int RUNTIME_ERROR_SLICE_INDEX_OUT_OF_BOUNDS = 0;
2568
2569 // Array index out of bounds.
2570 static const int RUNTIME_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS = 1;
2571
2572 // String index out of bounds.
2573 static const int RUNTIME_ERROR_STRING_INDEX_OUT_OF_BOUNDS = 2;
2574
2575 // Slice slice out of bounds: negative or larger than the length of
2576 // the slice or high bound less than low bound.
2577 static const int RUNTIME_ERROR_SLICE_SLICE_OUT_OF_BOUNDS = 3;
2578
2579 // Array slice out of bounds.
2580 static const int RUNTIME_ERROR_ARRAY_SLICE_OUT_OF_BOUNDS = 4;
2581
2582 // String slice out of bounds.
2583 static const int RUNTIME_ERROR_STRING_SLICE_OUT_OF_BOUNDS = 5;
2584
2585 // Dereference of nil pointer.  This is used when there is a
2586 // dereference of a pointer to a very large struct or array, to ensure
2587 // that a gigantic array is not used a proxy to access random memory
2588 // locations.
2589 static const int RUNTIME_ERROR_NIL_DEREFERENCE = 6;
2590
2591 // Slice length or capacity out of bounds in make: negative or
2592 // overflow or length greater than capacity.
2593 static const int RUNTIME_ERROR_MAKE_SLICE_OUT_OF_BOUNDS = 7;
2594
2595 // Map capacity out of bounds in make: negative or overflow.
2596 static const int RUNTIME_ERROR_MAKE_MAP_OUT_OF_BOUNDS = 8;
2597
2598 // Channel capacity out of bounds in make: negative or overflow.
2599 static const int RUNTIME_ERROR_MAKE_CHAN_OUT_OF_BOUNDS = 9;
2600
2601 // This is used by some of the langhooks.
2602 extern Gogo* go_get_gogo();
2603
2604 // Whether we have seen any errors.  FIXME: Replace with a backend
2605 // interface.
2606 extern bool saw_errors();
2607
2608 #endif // !defined(GO_GOGO_H)