OSDN Git Service

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