OSDN Git Service

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