compiler: track //go:nointerface in export data
[official-gcc.git] / gcc / go / gofrontend / gogo.h
blob139df1785d45fa2ae12adfc6babbfaebf005ddf5
1 // gogo.h -- Go frontend parsed representation. -*- C++ -*-
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.
7 #ifndef GO_GOGO_H
8 #define GO_GOGO_H
10 #include "go-linemap.h"
12 class Traverse;
13 class Statement_inserter;
14 class Type;
15 class Type_hash_identical;
16 class Type_equal;
17 class Type_identical;
18 class Typed_identifier;
19 class Typed_identifier_list;
20 class Function_type;
21 class Expression;
22 class Expression_list;
23 class Statement;
24 class Temporary_statement;
25 class Block;
26 class Function;
27 class Bindings;
28 class Bindings_snapshot;
29 class Package;
30 class Variable;
31 class Pointer_type;
32 class Struct_type;
33 class Struct_field;
34 class Struct_field_list;
35 class Array_type;
36 class Map_type;
37 class Channel_type;
38 class Interface_type;
39 class Named_type;
40 class Forward_declaration_type;
41 class Named_object;
42 class Label;
43 class Translate_context;
44 class Backend;
45 class Export;
46 class Import;
47 class Bexpression;
48 class Btype;
49 class Bstatement;
50 class Bblock;
51 class Bvariable;
52 class Blabel;
53 class Bfunction;
54 class Escape_context;
55 class Node;
57 // This file declares the basic classes used to hold the internal
58 // representation of Go which is built by the parser.
60 // An initialization function for an imported package. This is a
61 // magic function which initializes variables and runs the "init"
62 // function.
64 class Import_init
66 public:
67 Import_init(const std::string& package_name, const std::string& init_name,
68 int priority)
69 : package_name_(package_name), init_name_(init_name), priority_(priority)
70 { }
72 // The name of the package being imported.
73 const std::string&
74 package_name() const
75 { return this->package_name_; }
77 // The name of the package's init function.
78 const std::string&
79 init_name() const
80 { return this->init_name_; }
82 // Older V1 export data uses a priority scheme to order
83 // initialization functions; functions with a lower priority number
84 // must be run first. This value will be set to -1 for current
85 // generation objects, and will take on a non-negative value only
86 // when importing a V1-vintage object.
87 int
88 priority() const
89 { return this->priority_; }
91 // Reset priority.
92 void
93 set_priority(int new_priority)
94 { this->priority_ = new_priority; }
96 // Record the fact that some other init fcn must be run before this init fcn.
97 void
98 record_precursor_fcn(std::string init_fcn_name)
99 { this->precursor_functions_.insert(init_fcn_name); }
101 // Return the list of precursor fcns for this fcn (must be run before it).
102 const std::set<std::string>&
103 precursors() const
104 { return this->precursor_functions_; }
106 private:
107 // The name of the package being imported.
108 std::string package_name_;
109 // The name of the package's init function.
110 std::string init_name_;
111 // Names of init functions that must be run before this fcn.
112 std::set<std::string> precursor_functions_;
113 // Priority for this function. See note above on obsolescence.
114 int priority_;
117 // For sorting purposes.
119 struct Import_init_lt {
120 bool operator()(const Import_init* i1, const Import_init* i2) const
122 return i1->init_name() < i2->init_name();
126 // Set of import init objects.
127 class Import_init_set : public std::set<Import_init*, Import_init_lt> {
130 inline bool
131 priority_compare(const Import_init* i1, const Import_init* i2)
133 if (i1->priority() < i2->priority())
134 return true;
135 if (i1->priority() > i2->priority())
136 return false;
137 if (i1->package_name() != i2->package_name())
138 return i1->package_name() < i2->package_name();
139 return i1->init_name() < i2->init_name();
142 // The holder for the internal representation of the entire
143 // compilation unit.
145 class Gogo
147 public:
148 // Create the IR, passing in the sizes of the types "int" and
149 // "uintptr" in bits.
150 Gogo(Backend* backend, Linemap *linemap, int int_type_size, int pointer_size);
152 // Get the backend generator.
153 Backend*
154 backend()
155 { return this->backend_; }
157 // Get the Location generator.
158 Linemap*
159 linemap()
160 { return this->linemap_; }
162 // Get the package name.
163 const std::string&
164 package_name() const;
166 // Set the package name.
167 void
168 set_package_name(const std::string&, Location);
170 // Return whether this is the "main" package.
171 bool
172 is_main_package() const;
174 // If necessary, adjust the name to use for a hidden symbol. We add
175 // the package name, so that hidden symbols in different packages do
176 // not collide.
177 std::string
178 pack_hidden_name(const std::string& name, bool is_exported) const
180 return (is_exported
181 ? name
182 : '.' + this->pkgpath() + '.' + name);
185 // Unpack a name which may have been hidden. Returns the
186 // user-visible name of the object.
187 static std::string
188 unpack_hidden_name(const std::string& name)
189 { return name[0] != '.' ? name : name.substr(name.rfind('.') + 1); }
191 // Return whether a possibly packed name is hidden.
192 static bool
193 is_hidden_name(const std::string& name)
194 { return name[0] == '.'; }
196 // Return the package path of a hidden name.
197 static std::string
198 hidden_name_pkgpath(const std::string& name)
200 go_assert(Gogo::is_hidden_name(name));
201 return name.substr(1, name.rfind('.') - 1);
204 // Given a name which may or may not have been hidden, return the
205 // name to use within a mangled symbol name.
206 static std::string
207 mangle_possibly_hidden_name(const std::string& name)
209 // FIXME: This adds in pkgpath twice for hidden symbols, which is
210 // less than ideal.
211 std::string n;
212 if (!Gogo::is_hidden_name(name))
213 n = name;
214 else
216 n = ".";
217 std::string pkgpath = Gogo::hidden_name_pkgpath(name);
218 n.append(Gogo::pkgpath_for_symbol(pkgpath));
219 n.append(1, '.');
220 n.append(Gogo::unpack_hidden_name(name));
222 return n;
225 // Given a name which may or may not have been hidden, return the
226 // name to use in an error message.
227 static std::string
228 message_name(const std::string& name);
230 // Return whether a name is the blank identifier _.
231 static bool
232 is_sink_name(const std::string& name)
234 return (name[0] == '.'
235 && name[name.length() - 1] == '_'
236 && name[name.length() - 2] == '.');
239 // Convert a pkgpath into a string suitable for a symbol
240 static std::string
241 pkgpath_for_symbol(const std::string& pkgpath);
243 // Return the package path to use for reflect.Type.PkgPath.
244 const std::string&
245 pkgpath() const;
247 // Return the package path to use for a symbol name.
248 const std::string&
249 pkgpath_symbol() const;
251 // Set the package path from a command line option.
252 void
253 set_pkgpath(const std::string&);
255 // Set the prefix from a command line option.
256 void
257 set_prefix(const std::string&);
259 // Return whether pkgpath was set from a command line option.
260 bool
261 pkgpath_from_option() const
262 { return this->pkgpath_from_option_; }
264 // Return the relative import path as set from the command line.
265 // Returns an empty string if it was not set.
266 const std::string&
267 relative_import_path() const
268 { return this->relative_import_path_; }
270 // Set the relative import path from a command line option.
271 void
272 set_relative_import_path(const std::string& s)
273 { this->relative_import_path_ = s; }
275 // Set the C header file to write. This is used for the runtime
276 // package.
277 void
278 set_c_header(const std::string& s)
279 { this->c_header_ = s; }
281 // Return whether to check for division by zero in binary operations.
282 bool
283 check_divide_by_zero() const
284 { return this->check_divide_by_zero_; }
286 // Set the option to check division by zero from a command line option.
287 void
288 set_check_divide_by_zero(bool b)
289 { this->check_divide_by_zero_ = b; }
291 // Return whether to check for division overflow in binary operations.
292 bool
293 check_divide_overflow() const
294 { return this->check_divide_overflow_; }
296 // Set the option to check division overflow from a command line option.
297 void
298 set_check_divide_overflow(bool b)
299 { this->check_divide_overflow_ = b; }
301 // Return whether we are compiling the runtime package.
302 bool
303 compiling_runtime() const
304 { return this->compiling_runtime_; }
306 // Set whether we are compiling the runtime package.
307 void
308 set_compiling_runtime(bool b)
309 { this->compiling_runtime_ = b; }
311 // Return the level of escape analysis debug information to emit.
313 debug_escape_level() const
314 { return this->debug_escape_level_; }
316 // Set the level of escape analysis debugging from a command line option.
317 void
318 set_debug_escape_level(int level)
319 { this->debug_escape_level_ = level; }
321 // Return the hash for debug escape analysis.
322 std::string
323 debug_escape_hash() const
324 { return this->debug_escape_hash_; }
326 // Set the hash value for debug escape analysis.
327 void
328 set_debug_escape_hash(const std::string& s)
329 { this->debug_escape_hash_ = s; }
331 // Return the size threshold used to determine whether to issue
332 // a nil-check for a given pointer dereference. A threshold of -1
333 // implies that all potentially faulting dereference ops should
334 // be nil-checked. A positive threshold of N implies that a deref
335 // of *P where P has size less than N doesn't need a nil check.
336 int64_t
337 nil_check_size_threshold() const
338 { return this->nil_check_size_threshold_; }
340 // Set the nil-check size threshold, as described above.
341 void
342 set_nil_check_size_threshold(int64_t bytes)
343 { this->nil_check_size_threshold_ = bytes; }
345 // Import a package. FILENAME is the file name argument, LOCAL_NAME
346 // is the local name to give to the package. If LOCAL_NAME is empty
347 // the declarations are added to the global scope.
348 void
349 import_package(const std::string& filename, const std::string& local_name,
350 bool is_local_name_exported, bool must_exist, Location);
352 // Whether we are the global binding level.
353 bool
354 in_global_scope() const;
356 // Look up a name in the current binding contours.
357 Named_object*
358 lookup(const std::string&, Named_object** pfunction) const;
360 // Look up a name in the current block.
361 Named_object*
362 lookup_in_block(const std::string&) const;
364 // Look up a name in the global namespace--the universal scope.
365 Named_object*
366 lookup_global(const char*) const;
368 // Add a new imported package. REAL_NAME is the real name of the
369 // package. ALIAS is the alias of the package; this may be the same
370 // as REAL_NAME. This sets *PADD_TO_GLOBALS if symbols added to
371 // this package should be added to the global namespace; this is
372 // true if the alias is ".". LOCATION is the location of the import
373 // statement. This returns the new package, or NULL on error.
374 Package*
375 add_imported_package(const std::string& real_name, const std::string& alias,
376 bool is_alias_exported,
377 const std::string& pkgpath,
378 const std::string& pkgpath_symbol,
379 Location location,
380 bool* padd_to_globals);
382 // Register a package. This package may or may not be imported.
383 // This returns the Package structure for the package, creating if
384 // it necessary.
385 Package*
386 register_package(const std::string& pkgpath,
387 const std::string& pkgpath_symbol, Location);
389 // Look up a package by pkgpath, and return its pkgpath_symbol.
390 std::string
391 pkgpath_symbol_for_package(const std::string&);
393 // Start compiling a function. ADD_METHOD_TO_TYPE is true if a
394 // method function should be added to the type of its receiver.
395 Named_object*
396 start_function(const std::string& name, Function_type* type,
397 bool add_method_to_type, Location);
399 // Finish compiling a function.
400 void
401 finish_function(Location);
403 // Return the current function.
404 Named_object*
405 current_function() const;
407 // Return the current block.
408 Block*
409 current_block();
411 // Start a new block. This is not initially associated with a
412 // function.
413 void
414 start_block(Location);
416 // Finish the current block and return it.
417 Block*
418 finish_block(Location);
420 // Declare an erroneous name. This is used to avoid knock-on errors
421 // after a parsing error.
422 Named_object*
423 add_erroneous_name(const std::string& name);
425 // Declare an unknown name. This is used while parsing. The name
426 // must be resolved by the end of the parse. Unknown names are
427 // always added at the package level.
428 Named_object*
429 add_unknown_name(const std::string& name, Location);
431 // Declare a function.
432 Named_object*
433 declare_function(const std::string&, Function_type*, Location);
435 // Declare a function at the package level. This is used for
436 // functions generated for a type.
437 Named_object*
438 declare_package_function(const std::string&, Function_type*, Location);
440 // Add a label.
441 Label*
442 add_label_definition(const std::string&, Location);
444 // Add a label reference. ISSUE_GOTO_ERRORS is true if we should
445 // report errors for a goto from the current location to the label
446 // location.
447 Label*
448 add_label_reference(const std::string&, Location,
449 bool issue_goto_errors);
451 // An analysis set is a list of functions paired with a boolean that indicates
452 // whether the list of functions are recursive.
453 typedef std::pair<std::vector<Named_object*>, bool> Analysis_set;
455 // Add a GROUP of possibly RECURSIVE functions to the Analysis_set for this
456 // package.
457 void
458 add_analysis_set(const std::vector<Named_object*>& group, bool recursive)
459 { this->analysis_sets_.push_back(std::make_pair(group, recursive)); }
461 // Return a snapshot of the current binding state.
462 Bindings_snapshot*
463 bindings_snapshot(Location);
465 // Add a statement to the current block.
466 void
467 add_statement(Statement*);
469 // Add a block to the current block.
470 void
471 add_block(Block*, Location);
473 // Add a constant.
474 Named_object*
475 add_constant(const Typed_identifier&, Expression*, int iota_value);
477 // Add a type.
478 void
479 add_type(const std::string&, Type*, Location);
481 // Add a named type. This is used for builtin types, and to add an
482 // imported type to the global scope.
483 void
484 add_named_type(Named_type*);
486 // Declare a type.
487 Named_object*
488 declare_type(const std::string&, Location);
490 // Declare a type at the package level. This is used when the
491 // parser sees an unknown name where a type name is required.
492 Named_object*
493 declare_package_type(const std::string&, Location);
495 // Define a type which was already declared.
496 void
497 define_type(Named_object*, Named_type*);
499 // Add a variable.
500 Named_object*
501 add_variable(const std::string&, Variable*);
503 // Add a sink--a reference to the blank identifier _.
504 Named_object*
505 add_sink();
507 // Add a type which needs to be verified. This is used for sink
508 // types, just to give appropriate error messages.
509 void
510 add_type_to_verify(Type* type);
512 // Add a named object to the current namespace. This is used for
513 // import . "package".
514 void
515 add_dot_import_object(Named_object*);
517 // Add an identifier to the list of names seen in the file block.
518 void
519 add_file_block_name(const std::string& name, Location location)
520 { this->file_block_names_[name] = location; }
522 // Add a linkname, from the go:linkname compiler directive. This
523 // changes the externally visible name of go_name to be ext_name.
524 void
525 add_linkname(const std::string& go_name, bool is_exported,
526 const std::string& ext_name, Location location);
528 // Mark all local variables in current bindings as used. This is
529 // used when there is a parse error to avoid useless errors.
530 void
531 mark_locals_used();
533 // Note that we've seen an interface type. This is used to build
534 // all required interface method tables.
535 void
536 record_interface_type(Interface_type*);
538 // Note that we need an initialization function.
539 void
540 set_need_init_fn()
541 { this->need_init_fn_ = true; }
543 // Return whether the current file imported the unsafe package.
544 bool
545 current_file_imported_unsafe() const
546 { return this->current_file_imported_unsafe_; }
548 // Clear out all names in file scope. This is called when we start
549 // parsing a new file.
550 void
551 clear_file_scope();
553 // Record that VAR1 must be initialized after VAR2. This is used
554 // when VAR2 does not appear in VAR1's INIT or PREINIT.
555 void
556 record_var_depends_on(Variable* var1, Named_object* var2)
558 go_assert(this->var_deps_.find(var1) == this->var_deps_.end());
559 this->var_deps_[var1] = var2;
562 // Return the variable that VAR depends on, or NULL if none.
563 Named_object*
564 var_depends_on(Variable* var) const
566 Var_deps::const_iterator p = this->var_deps_.find(var);
567 return p != this->var_deps_.end() ? p->second : NULL;
570 // Queue up a type-specific function to be written out. This is
571 // used when a type-specific function is needed when not at the top
572 // level.
573 void
574 queue_specific_type_function(Type* type, Named_type* name, int64_t size,
575 const std::string& hash_name,
576 Function_type* hash_fntype,
577 const std::string& equal_name,
578 Function_type* equal_fntype);
580 // Write out queued specific type functions.
581 void
582 write_specific_type_functions();
584 // Whether we are done writing out specific type functions.
585 bool
586 specific_type_functions_are_written() const
587 { return this->specific_type_functions_are_written_; }
589 // Add a pointer that needs to be added to the list of objects
590 // traversed by the garbage collector. This should be an expression
591 // of pointer type that points to static storage. It's not
592 // necessary to add global variables to this list, just global
593 // variable initializers that would otherwise not be seen.
594 void
595 add_gc_root(Expression* expr)
597 this->set_need_init_fn();
598 this->gc_roots_.push_back(expr);
601 // Traverse the tree. See the Traverse class.
602 void
603 traverse(Traverse*);
605 // Define the predeclared global names.
606 void
607 define_global_names();
609 // Verify and complete all types.
610 void
611 verify_types();
613 // Lower the parse tree.
614 void
615 lower_parse_tree();
617 // Lower all the statements in a block.
618 void
619 lower_block(Named_object* function, Block*);
621 // Lower an expression.
622 void
623 lower_expression(Named_object* function, Statement_inserter*, Expression**);
625 // Lower a constant.
626 void
627 lower_constant(Named_object*);
629 // Flatten all the statements in a block.
630 void
631 flatten_block(Named_object* function, Block*);
633 // Flatten an expression.
634 void
635 flatten_expression(Named_object* function, Statement_inserter*, Expression**);
637 // Create all necessary function descriptors.
638 void
639 create_function_descriptors();
641 // Finalize the method lists and build stub methods for named types.
642 void
643 finalize_methods();
645 // Work out the types to use for unspecified variables and
646 // constants.
647 void
648 determine_types();
650 // Type check the program.
651 void
652 check_types();
654 // Check the types in a single block. This is used for complicated
655 // go statements.
656 void
657 check_types_in_block(Block*);
659 // Check for return statements.
660 void
661 check_return_statements();
663 // Analyze the program flow for escape information.
664 void
665 analyze_escape();
667 // Discover the groups of possibly recursive functions in this package.
668 void
669 discover_analysis_sets();
671 // Build a connectivity graph between the objects in each analyzed function.
672 void
673 assign_connectivity(Escape_context*, Named_object*);
675 // Traverse the objects in the connecitivty graph from the sink, adjusting the
676 // escape levels of each object.
677 void
678 propagate_escape(Escape_context*, Node*);
680 // Add notes about the escape level of a function's input and output
681 // parameters for exporting and importing top level functions.
682 void
683 tag_function(Escape_context*, Named_object*);
685 // Reclaim memory of escape analysis Nodes.
686 void
687 reclaim_escape_nodes();
689 // Do all exports.
690 void
691 do_exports();
693 // Add an import control function for an imported package to the
694 // list.
695 void
696 add_import_init_fn(const std::string& package_name,
697 const std::string& init_name, int prio);
699 // Return the Import_init for a given init name.
700 Import_init*
701 lookup_init(const std::string& init_name);
703 // Turn short-cut operators (&&, ||) into explicit if statements.
704 void
705 remove_shortcuts();
707 // Use temporary variables to force order of evaluation.
708 void
709 order_evaluations();
711 // Add write barriers as needed.
712 void
713 add_write_barriers();
715 // Return whether an assignment that sets LHS to RHS needs a write
716 // barrier.
717 bool
718 assign_needs_write_barrier(Expression* lhs);
720 // Return an assignment that sets LHS to RHS using a write barrier.
721 // This returns an if statement that checks whether write barriers
722 // are enabled. If not, it does LHS = RHS, otherwise it calls the
723 // appropriate write barrier function.
724 Statement*
725 assign_with_write_barrier(Function*, Block*, Statement_inserter*,
726 Expression* lhs, Expression* rhs, Location);
728 // Flatten parse tree.
729 void
730 flatten();
732 // Build thunks for functions which call recover.
733 void
734 build_recover_thunks();
736 // Return a declaration for __builtin_return_address or
737 // __builtin_frame_address.
738 static Named_object*
739 declare_builtin_rf_address(const char* name);
741 // Simplify statements which might use thunks: go and defer
742 // statements.
743 void
744 simplify_thunk_statements();
746 // Dump AST if -fgo-dump-ast is set
747 void
748 dump_ast(const char* basename);
750 // Dump Call Graph if -fgo-dump-calls is set.
751 void
752 dump_call_graph(const char* basename);
754 // Dump Connection Graphs if -fgo-dump-connections is set.
755 void
756 dump_connection_graphs(const char* basename);
758 // Convert named types to the backend representation.
759 void
760 convert_named_types();
762 // Convert named types in a list of bindings.
763 void
764 convert_named_types_in_bindings(Bindings*);
766 // True if named types have been converted to the backend
767 // representation.
768 bool
769 named_types_are_converted() const
770 { return this->named_types_are_converted_; }
772 // Give an error if the initialization of VAR depends on itself.
773 void
774 check_self_dep(Named_object*);
776 // Write out the global values.
777 void
778 write_globals();
780 // Build a call to the runtime error function.
781 Expression*
782 runtime_error(int code, Location);
784 // Build required interface method tables.
785 void
786 build_interface_method_tables();
788 // Return an expression which allocates memory to hold values of type TYPE.
789 Expression*
790 allocate_memory(Type *type, Location);
792 // Return the assembler name to use for an exported function, a
793 // method, or a function/method declaration.
794 std::string
795 function_asm_name(const std::string& go_name, const Package*,
796 const Type* receiver);
798 // Return the name to use for a function descriptor.
799 std::string
800 function_descriptor_name(Named_object*);
802 // Return the name to use for a generated stub method.
803 std::string
804 stub_method_name(const Package*, const std::string& method_name);
806 // Return the names of the hash and equality functions for TYPE.
807 void
808 specific_type_function_names(const Type*, const Named_type*,
809 std::string* hash_name,
810 std::string* equal_name);
812 // Return the assembler name to use for a global variable.
813 std::string
814 global_var_asm_name(const std::string& go_name, const Package*);
816 // Return a name to use for an error case. This should only be used
817 // after reporting an error, and is used to avoid useless knockon
818 // errors.
819 static std::string
820 erroneous_name();
822 // Return whether the name indicates an error.
823 static bool
824 is_erroneous_name(const std::string&);
826 // Return a name to use for a thunk function. A thunk function is
827 // one we create during the compilation, for a go statement or a
828 // defer statement or a method expression.
829 std::string
830 thunk_name();
832 // Return whether an object is a thunk.
833 static bool
834 is_thunk(const Named_object*);
836 // Return the name to use for an init function.
837 std::string
838 init_function_name();
840 // Return the name to use for a nested function.
841 std::string
842 nested_function_name(Named_object* enclosing);
844 // Return the name to use for a sink funciton.
845 std::string
846 sink_function_name();
848 // Return the name to use for an (erroneous) redefined function.
849 std::string
850 redefined_function_name();
852 // Return the name for use for a recover thunk.
853 std::string
854 recover_thunk_name(const std::string& name, const Type* rtype);
856 // Return the name to use for the GC root variable.
857 std::string
858 gc_root_name();
860 // Return the name to use for a composite literal or string
861 // initializer.
862 std::string
863 initializer_name();
865 // Return the name of the variable used to represent the zero value
866 // of a map.
867 std::string
868 map_zero_value_name();
870 // Get the name of the magic initialization function.
871 const std::string&
872 get_init_fn_name();
874 // Return the name for a type descriptor symbol.
875 std::string
876 type_descriptor_name(Type*, Named_type*);
878 // Return the assembler name for the GC symbol for a type.
879 std::string
880 gc_symbol_name(Type*);
882 // Return the assembler name for a ptrmask variable.
883 std::string
884 ptrmask_symbol_name(const std::string& ptrmask_sym_name);
886 // Return the name to use for an interface method table.
887 std::string
888 interface_method_table_name(Interface_type*, Type*, bool is_pointer);
890 // Return whether NAME is a special name that can not be passed to
891 // unpack_hidden_name. This is needed because various special names
892 // use "..SUFFIX", but unpack_hidden_name just looks for '.'.
893 static bool
894 is_special_name(const std::string& name);
896 private:
897 // During parsing, we keep a stack of functions. Each function on
898 // the stack is one that we are currently parsing. For each
899 // function, we keep track of the current stack of blocks.
900 struct Open_function
902 // The function.
903 Named_object* function;
904 // The stack of active blocks in the function.
905 std::vector<Block*> blocks;
908 // The stack of functions.
909 typedef std::vector<Open_function> Open_functions;
911 // Set up the built-in unsafe package.
912 void
913 import_unsafe(const std::string&, bool is_exported, Location);
915 // Return the current binding contour.
916 Bindings*
917 current_bindings();
919 const Bindings*
920 current_bindings() const;
922 void
923 write_c_header();
925 // Get the decl for the magic initialization function.
926 Named_object*
927 initialization_function_decl();
929 // Create the magic initialization function.
930 Named_object*
931 create_initialization_function(Named_object* fndecl, Bstatement* code_stmt);
933 // Initialize imported packages. BFUNCTION is the function
934 // into which the package init calls will be placed.
935 void
936 init_imports(std::vector<Bstatement*>&, Bfunction* bfunction);
938 // Register variables with the garbage collector.
939 void
940 register_gc_vars(const std::vector<Named_object*>&,
941 std::vector<Bstatement*>&,
942 Bfunction* init_bfunction);
944 Named_object*
945 write_barrier_variable();
947 Statement*
948 check_write_barrier(Block*, Statement*, Statement*);
950 // Type used to map import names to packages.
951 typedef std::map<std::string, Package*> Imports;
953 // Type used to map package names to packages.
954 typedef std::map<std::string, Package*> Packages;
956 // Type used to map variables to the function calls that set them.
957 // This is used for initialization dependency analysis.
958 typedef std::map<Variable*, Named_object*> Var_deps;
960 // Type used to map identifiers in the file block to the location
961 // where they were defined.
962 typedef Unordered_map(std::string, Location) File_block_names;
964 // Type used to queue writing a type specific function.
965 struct Specific_type_function
967 Type* type;
968 Named_type* name;
969 int64_t size;
970 std::string hash_name;
971 Function_type* hash_fntype;
972 std::string equal_name;
973 Function_type* equal_fntype;
975 Specific_type_function(Type* atype, Named_type* aname, int64_t asize,
976 const std::string& ahash_name,
977 Function_type* ahash_fntype,
978 const std::string& aequal_name,
979 Function_type* aequal_fntype)
980 : type(atype), name(aname), size(asize), hash_name(ahash_name),
981 hash_fntype(ahash_fntype), equal_name(aequal_name),
982 equal_fntype(aequal_fntype)
986 // Recompute init priorities.
987 void
988 recompute_init_priorities();
990 // Recursive helper used by the routine above.
991 void
992 update_init_priority(Import_init* ii,
993 std::set<const Import_init *>* visited);
995 // The backend generator.
996 Backend* backend_;
997 // The object used to keep track of file names and line numbers.
998 Linemap* linemap_;
999 // The package we are compiling.
1000 Package* package_;
1001 // The list of currently open functions during parsing.
1002 Open_functions functions_;
1003 // The global binding contour. This includes the builtin functions
1004 // and the package we are compiling.
1005 Bindings* globals_;
1006 // The list of names we have seen in the file block.
1007 File_block_names file_block_names_;
1008 // Mapping from import file names to packages.
1009 Imports imports_;
1010 // Whether the magic unsafe package was imported.
1011 bool imported_unsafe_;
1012 // Whether the magic unsafe package was imported by the current file.
1013 bool current_file_imported_unsafe_;
1014 // Mapping from package names we have seen to packages. This does
1015 // not include the package we are compiling.
1016 Packages packages_;
1017 // The functions named "init", if there are any.
1018 std::vector<Named_object*> init_functions_;
1019 // A mapping from variables to the function calls that initialize
1020 // them, if it is not stored in the variable's init or preinit.
1021 // This is used for dependency analysis.
1022 Var_deps var_deps_;
1023 // Whether we need a magic initialization function.
1024 bool need_init_fn_;
1025 // The name of the magic initialization function.
1026 std::string init_fn_name_;
1027 // A list of import control variables for packages that we import.
1028 Import_init_set imported_init_fns_;
1029 // The package path used for reflection data.
1030 std::string pkgpath_;
1031 // The package path to use for a symbol name.
1032 std::string pkgpath_symbol_;
1033 // The prefix to use for symbols, from the -fgo-prefix option.
1034 std::string prefix_;
1035 // Whether pkgpath_ has been set.
1036 bool pkgpath_set_;
1037 // Whether an explicit package path was set by -fgo-pkgpath.
1038 bool pkgpath_from_option_;
1039 // Whether an explicit prefix was set by -fgo-prefix.
1040 bool prefix_from_option_;
1041 // The relative import path, from the -fgo-relative-import-path
1042 // option.
1043 std::string relative_import_path_;
1044 // The C header file to write, from the -fgo-c-header option.
1045 std::string c_header_;
1046 // Whether or not to check for division by zero, from the
1047 // -fgo-check-divide-zero option.
1048 bool check_divide_by_zero_;
1049 // Whether or not to check for division overflow, from the
1050 // -fgo-check-divide-overflow option.
1051 bool check_divide_overflow_;
1052 // Whether we are compiling the runtime package, from the
1053 // -fgo-compiling-runtime option.
1054 bool compiling_runtime_;
1055 // The level of escape analysis debug information to emit, from the
1056 // -fgo-debug-escape option.
1057 int debug_escape_level_;
1058 // A hash value for debug escape analysis, from the
1059 // -fgo-debug-escape-hash option. The analysis is run only on
1060 // functions with names that hash to the matching value.
1061 std::string debug_escape_hash_;
1062 // Nil-check size threshhold.
1063 int64_t nil_check_size_threshold_;
1064 // A list of types to verify.
1065 std::vector<Type*> verify_types_;
1066 // A list of interface types defined while parsing.
1067 std::vector<Interface_type*> interface_types_;
1068 // Type specific functions to write out.
1069 std::vector<Specific_type_function*> specific_type_functions_;
1070 // Whether we are done writing out specific type functions.
1071 bool specific_type_functions_are_written_;
1072 // Whether named types have been converted.
1073 bool named_types_are_converted_;
1074 // A list containing groups of possibly mutually recursive functions to be
1075 // considered during escape analysis.
1076 std::vector<Analysis_set> analysis_sets_;
1077 // A list of objects to add to the GC roots.
1078 std::vector<Expression*> gc_roots_;
1081 // A block of statements.
1083 class Block
1085 public:
1086 Block(Block* enclosing, Location);
1088 // Return the enclosing block.
1089 const Block*
1090 enclosing() const
1091 { return this->enclosing_; }
1093 // Return the bindings of the block.
1094 Bindings*
1095 bindings()
1096 { return this->bindings_; }
1098 const Bindings*
1099 bindings() const
1100 { return this->bindings_; }
1102 // Look at the block's statements.
1103 const std::vector<Statement*>*
1104 statements() const
1105 { return &this->statements_; }
1107 // Return the start location. This is normally the location of the
1108 // left curly brace which starts the block.
1109 Location
1110 start_location() const
1111 { return this->start_location_; }
1113 // Return the end location. This is normally the location of the
1114 // right curly brace which ends the block.
1115 Location
1116 end_location() const
1117 { return this->end_location_; }
1119 // Add a statement to the block.
1120 void
1121 add_statement(Statement*);
1123 // Add a statement to the front of the block.
1124 void
1125 add_statement_at_front(Statement*);
1127 // Replace a statement in a block.
1128 void
1129 replace_statement(size_t index, Statement*);
1131 // Add a Statement before statement number INDEX.
1132 void
1133 insert_statement_before(size_t index, Statement*);
1135 // Add a Statement after statement number INDEX.
1136 void
1137 insert_statement_after(size_t index, Statement*);
1139 // Set the end location of the block.
1140 void
1141 set_end_location(Location location)
1142 { this->end_location_ = location; }
1144 // Traverse the tree.
1146 traverse(Traverse*);
1148 // Set final types for unspecified variables and constants.
1149 void
1150 determine_types();
1152 // Return true if execution of this block may fall through to the
1153 // next block.
1154 bool
1155 may_fall_through() const;
1157 // Convert the block to the backend representation.
1158 Bblock*
1159 get_backend(Translate_context*);
1161 // Iterate over statements.
1163 typedef std::vector<Statement*>::iterator iterator;
1165 iterator
1166 begin()
1167 { return this->statements_.begin(); }
1169 iterator
1170 end()
1171 { return this->statements_.end(); }
1173 private:
1174 // Enclosing block.
1175 Block* enclosing_;
1176 // Statements in the block.
1177 std::vector<Statement*> statements_;
1178 // Binding contour.
1179 Bindings* bindings_;
1180 // Location of start of block.
1181 Location start_location_;
1182 // Location of end of block.
1183 Location end_location_;
1186 // A function.
1188 class Function
1190 public:
1191 Function(Function_type* type, Named_object*, Block*, Location);
1193 // Return the function's type.
1194 Function_type*
1195 type() const
1196 { return this->type_; }
1198 // Return the enclosing function if there is one.
1199 Named_object*
1200 enclosing() const
1201 { return this->enclosing_; }
1203 // Set the enclosing function. This is used when building thunks
1204 // for functions which call recover.
1205 void
1206 set_enclosing(Named_object* enclosing)
1208 go_assert(this->enclosing_ == NULL);
1209 this->enclosing_ = enclosing;
1212 // The result variables.
1213 typedef std::vector<Named_object*> Results;
1215 // Create the result variables in the outer block.
1216 void
1217 create_result_variables(Gogo*);
1219 // Update the named result variables when cloning a function which
1220 // calls recover.
1221 void
1222 update_result_variables();
1224 // Return the result variables.
1225 Results*
1226 result_variables()
1227 { return this->results_; }
1229 bool
1230 is_sink() const
1231 { return this->is_sink_; }
1233 void
1234 set_is_sink()
1235 { this->is_sink_ = true; }
1237 // Whether the result variables have names.
1238 bool
1239 results_are_named() const
1240 { return this->results_are_named_; }
1242 // Return the assembler name.
1243 const std::string&
1244 asm_name() const
1245 { return this->asm_name_; }
1247 // Set the assembler name.
1248 void
1249 set_asm_name(const std::string& asm_name)
1250 { this->asm_name_ = asm_name; }
1252 // Return the pragmas for this function.
1253 unsigned int
1254 pragmas() const
1255 { return this->pragmas_; }
1257 // Set the pragmas for this function.
1258 void
1259 set_pragmas(unsigned int pragmas)
1261 this->pragmas_ = pragmas;
1264 // Return the index to use for a nested function.
1265 unsigned int
1266 next_nested_function_index()
1268 ++this->nested_functions_;
1269 return this->nested_functions_;
1272 // Whether this method should not be included in the type
1273 // descriptor.
1274 bool
1275 nointerface() const;
1277 // Record that this method should not be included in the type
1278 // descriptor.
1279 void
1280 set_nointerface();
1282 // Record that this function is a stub method created for an unnamed
1283 // type.
1284 void
1285 set_is_unnamed_type_stub_method()
1287 go_assert(this->is_method());
1288 this->is_unnamed_type_stub_method_ = true;
1291 // Return the amount of enclosed variables in this closure.
1292 size_t
1293 closure_field_count() const
1294 { return this->closure_fields_.size(); }
1296 // Add a new field to the closure variable.
1297 void
1298 add_closure_field(Named_object* var, Location loc)
1299 { this->closure_fields_.push_back(std::make_pair(var, loc)); }
1301 // Whether this function needs a closure.
1302 bool
1303 needs_closure() const
1304 { return !this->closure_fields_.empty(); }
1306 // Return the closure variable, creating it if necessary. This is
1307 // passed to the function as a static chain parameter.
1308 Named_object*
1309 closure_var();
1311 // Set the closure variable. This is used when building thunks for
1312 // functions which call recover.
1313 void
1314 set_closure_var(Named_object* v)
1316 go_assert(this->closure_var_ == NULL);
1317 this->closure_var_ = v;
1320 // Return the variable for a reference to field INDEX in the closure
1321 // variable.
1322 Named_object*
1323 enclosing_var(unsigned int index)
1325 go_assert(index < this->closure_fields_.size());
1326 return closure_fields_[index].first;
1329 // Set the type of the closure variable if there is one.
1330 void
1331 set_closure_type();
1333 // Get the block of statements associated with the function.
1334 Block*
1335 block() const
1336 { return this->block_; }
1338 // Get the location of the start of the function.
1339 Location
1340 location() const
1341 { return this->location_; }
1343 // Return whether this function is actually a method.
1344 bool
1345 is_method() const;
1347 // Add a label definition to the function.
1348 Label*
1349 add_label_definition(Gogo*, const std::string& label_name, Location);
1351 // Add a label reference to a function. ISSUE_GOTO_ERRORS is true
1352 // if we should report errors for a goto from the current location
1353 // to the label location.
1354 Label*
1355 add_label_reference(Gogo*, const std::string& label_name,
1356 Location, bool issue_goto_errors);
1358 // Warn about labels that are defined but not used.
1359 void
1360 check_labels() const;
1362 // Note that a new local type has been added. Return its index.
1363 unsigned int
1364 new_local_type_index()
1365 { return this->local_type_count_++; }
1367 // Whether this function calls the predeclared recover function.
1368 bool
1369 calls_recover() const
1370 { return this->calls_recover_; }
1372 // Record that this function calls the predeclared recover function.
1373 // This is set during the lowering pass.
1374 void
1375 set_calls_recover()
1376 { this->calls_recover_ = true; }
1378 // Whether this is a recover thunk function.
1379 bool
1380 is_recover_thunk() const
1381 { return this->is_recover_thunk_; }
1383 // Record that this is a thunk built for a function which calls
1384 // recover.
1385 void
1386 set_is_recover_thunk()
1387 { this->is_recover_thunk_ = true; }
1389 // Whether this function already has a recover thunk.
1390 bool
1391 has_recover_thunk() const
1392 { return this->has_recover_thunk_; }
1394 // Record that this function already has a recover thunk.
1395 void
1396 set_has_recover_thunk()
1397 { this->has_recover_thunk_ = true; }
1399 // Record that this function is a thunk created for a defer
1400 // statement that calls the __go_set_defer_retaddr runtime function.
1401 void
1402 set_calls_defer_retaddr()
1403 { this->calls_defer_retaddr_ = true; }
1405 // Whether this is a type hash or equality function created by the
1406 // compiler.
1407 bool
1408 is_type_specific_function()
1409 { return this->is_type_specific_function_; }
1411 // Record that this function is a type hash or equality function
1412 // created by the compiler.
1413 void
1414 set_is_type_specific_function()
1415 { this->is_type_specific_function_ = true; }
1417 // Mark the function as going into a unique section.
1418 void
1419 set_in_unique_section()
1420 { this->in_unique_section_ = true; }
1422 // Swap with another function. Used only for the thunk which calls
1423 // recover.
1424 void
1425 swap_for_recover(Function *);
1427 // Traverse the tree.
1429 traverse(Traverse*);
1431 // Determine types in the function.
1432 void
1433 determine_types();
1435 // Return an expression for the function descriptor, given the named
1436 // object for this function. This may only be called for functions
1437 // without a closure. This will be an immutable struct with one
1438 // field that points to the function's code.
1439 Expression*
1440 descriptor(Gogo*, Named_object*);
1442 // Set the descriptor for this function. This is used when a
1443 // function declaration is followed by a function definition.
1444 void
1445 set_descriptor(Expression* descriptor)
1447 go_assert(this->descriptor_ == NULL);
1448 this->descriptor_ = descriptor;
1451 // Return the backend representation.
1452 Bfunction*
1453 get_or_make_decl(Gogo*, Named_object*);
1455 // Return the function's decl after it has been built.
1456 Bfunction*
1457 get_decl() const;
1459 // Set the function decl to hold a backend representation of the function
1460 // code.
1461 void
1462 build(Gogo*, Named_object*);
1464 // Get the statement that assigns values to this function's result struct.
1465 Bstatement*
1466 return_value(Gogo*, Named_object*, Location) const;
1468 // Get an expression for the variable holding the defer stack.
1469 Expression*
1470 defer_stack(Location);
1472 // Export the function.
1473 void
1474 export_func(Export*, const std::string& name) const;
1476 // Export a function with a type.
1477 static void
1478 export_func_with_type(Export*, const std::string& name,
1479 const Function_type*, bool nointerface);
1481 // Import a function.
1482 static void
1483 import_func(Import*, std::string* pname, Typed_identifier** receiver,
1484 Typed_identifier_list** pparameters,
1485 Typed_identifier_list** presults, bool* is_varargs,
1486 bool* nointerface);
1488 private:
1489 // Type for mapping from label names to Label objects.
1490 typedef Unordered_map(std::string, Label*) Labels;
1492 void
1493 build_defer_wrapper(Gogo*, Named_object*, Bstatement**, Bstatement**);
1495 typedef std::vector<std::pair<Named_object*,
1496 Location> > Closure_fields;
1498 // The function's type.
1499 Function_type* type_;
1500 // The enclosing function. This is NULL when there isn't one, which
1501 // is the normal case.
1502 Named_object* enclosing_;
1503 // The result variables, if any.
1504 Results* results_;
1505 // If there is a closure, this is the list of variables which appear
1506 // in the closure. This is created by the parser, and then resolved
1507 // to a real type when we lower parse trees.
1508 Closure_fields closure_fields_;
1509 // The closure variable, passed as a parameter using the static
1510 // chain parameter. Normally NULL.
1511 Named_object* closure_var_;
1512 // The outer block of statements in the function.
1513 Block* block_;
1514 // The source location of the start of the function.
1515 Location location_;
1516 // Labels defined or referenced in the function.
1517 Labels labels_;
1518 // The number of local types defined in this function.
1519 unsigned int local_type_count_;
1520 // The assembler name: this is the name that will be put in the object file.
1521 // Set by the go:linkname compiler directive. This is normally empty.
1522 std::string asm_name_;
1523 // The function descriptor, if any.
1524 Expression* descriptor_;
1525 // The function decl.
1526 Bfunction* fndecl_;
1527 // The defer stack variable. A pointer to this variable is used to
1528 // distinguish the defer stack for one function from another. This
1529 // is NULL unless we actually need a defer stack.
1530 Temporary_statement* defer_stack_;
1531 // Pragmas for this function. This is a set of GOPRAGMA bits.
1532 unsigned int pragmas_;
1533 // Number of nested functions defined within this function.
1534 unsigned int nested_functions_;
1535 // True if this function is sink-named. No code is generated.
1536 bool is_sink_ : 1;
1537 // True if the result variables are named.
1538 bool results_are_named_ : 1;
1539 // True if this function is a stub method created for an unnamed
1540 // type.
1541 bool is_unnamed_type_stub_method_ : 1;
1542 // True if this function calls the predeclared recover function.
1543 bool calls_recover_ : 1;
1544 // True if this a thunk built for a function which calls recover.
1545 bool is_recover_thunk_ : 1;
1546 // True if this function already has a recover thunk.
1547 bool has_recover_thunk_ : 1;
1548 // True if this is a thunk built for a defer statement that calls
1549 // the __go_set_defer_retaddr runtime function.
1550 bool calls_defer_retaddr_ : 1;
1551 // True if this is a function built by the compiler to as a hash or
1552 // equality function for some type.
1553 bool is_type_specific_function_ : 1;
1554 // True if this function should be put in a unique section. This is
1555 // turned on for field tracking.
1556 bool in_unique_section_ : 1;
1559 // A snapshot of the current binding state.
1561 class Bindings_snapshot
1563 public:
1564 Bindings_snapshot(const Block*, Location);
1566 // Report any errors appropriate for a goto from the current binding
1567 // state of B to this one.
1568 void
1569 check_goto_from(const Block* b, Location);
1571 // Report any errors appropriate for a goto from this binding state
1572 // to the current state of B.
1573 void
1574 check_goto_to(const Block* b);
1576 private:
1577 bool
1578 check_goto_block(Location, const Block*, const Block*, size_t*);
1580 void
1581 check_goto_defs(Location, const Block*, size_t, size_t);
1583 // The current block.
1584 const Block* block_;
1585 // The number of names currently defined in each open block.
1586 // Element 0 is this->block_, element 1 is
1587 // this->block_->enclosing(), etc.
1588 std::vector<size_t> counts_;
1589 // The location where this snapshot was taken.
1590 Location location_;
1593 // A function declaration.
1595 class Function_declaration
1597 public:
1598 Function_declaration(Function_type* fntype, Location location)
1599 : fntype_(fntype), location_(location), asm_name_(), descriptor_(NULL),
1600 fndecl_(NULL), pragmas_(0)
1603 Function_type*
1604 type() const
1605 { return this->fntype_; }
1607 Location
1608 location() const
1609 { return this->location_; }
1611 // Return whether this function declaration is a method.
1612 bool
1613 is_method() const;
1615 const std::string&
1616 asm_name() const
1617 { return this->asm_name_; }
1619 // Set the assembler name.
1620 void
1621 set_asm_name(const std::string& asm_name)
1622 { this->asm_name_ = asm_name; }
1624 // Return the pragmas for this function.
1625 unsigned int
1626 pragmas() const
1627 { return this->pragmas_; }
1629 // Set the pragmas for this function.
1630 void
1631 set_pragmas(unsigned int pragmas)
1633 this->pragmas_ = pragmas;
1636 // Whether this method should not be included in the type
1637 // descriptor.
1638 bool
1639 nointerface() const;
1641 // Record that this method should not be included in the type
1642 // descriptor.
1643 void
1644 set_nointerface();
1646 // Return an expression for the function descriptor, given the named
1647 // object for this function. This may only be called for functions
1648 // without a closure. This will be an immutable struct with one
1649 // field that points to the function's code.
1650 Expression*
1651 descriptor(Gogo*, Named_object*);
1653 // Return true if we have created a descriptor for this declaration.
1654 bool
1655 has_descriptor() const
1656 { return this->descriptor_ != NULL; }
1658 // Return a backend representation.
1659 Bfunction*
1660 get_or_make_decl(Gogo*, Named_object*);
1662 // If there is a descriptor, build it into the backend
1663 // representation.
1664 void
1665 build_backend_descriptor(Gogo*);
1667 // Export a function declaration.
1668 void
1669 export_func(Export* exp, const std::string& name) const
1671 Function::export_func_with_type(exp, name, this->fntype_,
1672 this->is_method() && this->nointerface());
1675 // Check that the types used in this declaration's signature are defined.
1676 void
1677 check_types() const;
1679 private:
1680 // The type of the function.
1681 Function_type* fntype_;
1682 // The location of the declaration.
1683 Location location_;
1684 // The assembler name: this is the name to use in references to the
1685 // function. This is normally empty.
1686 std::string asm_name_;
1687 // The function descriptor, if any.
1688 Expression* descriptor_;
1689 // The function decl if needed.
1690 Bfunction* fndecl_;
1691 // Pragmas for this function. This is a set of GOPRAGMA bits.
1692 unsigned int pragmas_;
1695 // A variable.
1697 class Variable
1699 public:
1700 Variable(Type*, Expression*, bool is_global, bool is_parameter,
1701 bool is_receiver, Location);
1703 // Get the type of the variable.
1704 Type*
1705 type();
1707 Type*
1708 type() const;
1710 // Return whether the type is defined yet.
1711 bool
1712 has_type() const;
1714 // Get the initial value.
1715 Expression*
1716 init() const
1717 { return this->init_; }
1719 // Return whether there are any preinit statements.
1720 bool
1721 has_pre_init() const
1722 { return this->preinit_ != NULL; }
1724 // Return the preinit statements if any.
1725 Block*
1726 preinit() const
1727 { return this->preinit_; }
1729 // Return whether this is a global variable.
1730 bool
1731 is_global() const
1732 { return this->is_global_; }
1734 // Return whether this is a function parameter.
1735 bool
1736 is_parameter() const
1737 { return this->is_parameter_; }
1739 // Return whether this is a closure (static chain) parameter.
1740 bool
1741 is_closure() const
1742 { return this->is_closure_; }
1744 // Change this parameter to be a closure.
1745 void
1746 set_is_closure()
1748 this->is_closure_ = true;
1751 // Return whether this is the receiver parameter of a method.
1752 bool
1753 is_receiver() const
1754 { return this->is_receiver_; }
1756 // Change this parameter to be a receiver. This is used when
1757 // creating the thunks created for functions which call recover.
1758 void
1759 set_is_receiver()
1761 go_assert(this->is_parameter_);
1762 this->is_receiver_ = true;
1765 // Change this parameter to not be a receiver. This is used when
1766 // creating the thunks created for functions which call recover.
1767 void
1768 set_is_not_receiver()
1770 go_assert(this->is_parameter_);
1771 this->is_receiver_ = false;
1774 // Return whether this is the varargs parameter of a function.
1775 bool
1776 is_varargs_parameter() const
1777 { return this->is_varargs_parameter_; }
1779 // Whether this variable's address is taken.
1780 bool
1781 is_address_taken() const
1782 { return this->is_address_taken_; }
1784 // Whether this variable should live in the heap.
1785 bool
1786 is_in_heap() const
1788 return this->is_address_taken_
1789 && this->escapes_
1790 && !this->is_global_;
1793 // Note that something takes the address of this variable.
1794 void
1795 set_address_taken()
1796 { this->is_address_taken_ = true; }
1798 // Return whether the address is taken but does not escape.
1799 bool
1800 is_non_escaping_address_taken() const
1801 { return this->is_non_escaping_address_taken_; }
1803 // Note that something takes the address of this variable such that
1804 // the address does not escape the function.
1805 void
1806 set_non_escaping_address_taken()
1807 { this->is_non_escaping_address_taken_ = true; }
1809 // Return whether this variable escapes the function it is declared in.
1810 bool
1811 escapes()
1812 { return this->escapes_; }
1814 // Note that this variable does not escape the function it is declared in.
1815 void
1816 set_does_not_escape()
1817 { this->escapes_ = false; }
1819 // Get the source location of the variable's declaration.
1820 Location
1821 location() const
1822 { return this->location_; }
1824 // Record that this is the varargs parameter of a function.
1825 void
1826 set_is_varargs_parameter()
1828 go_assert(this->is_parameter_);
1829 this->is_varargs_parameter_ = true;
1832 // Return whether the variable has been used.
1833 bool
1834 is_used() const
1835 { return this->is_used_; }
1837 // Mark that the variable has been used.
1838 void
1839 set_is_used()
1840 { this->is_used_ = true; }
1842 // Clear the initial value; used for error handling and write barriers.
1843 void
1844 clear_init()
1845 { this->init_ = NULL; }
1847 // Set the initial value; used for converting shortcuts.
1848 void
1849 set_init(Expression* init)
1850 { this->init_ = init; }
1852 // Get the preinit block, a block of statements to be run before the
1853 // initialization expression.
1854 Block*
1855 preinit_block(Gogo*);
1857 // Add a statement to be run before the initialization expression.
1858 // This is only used for global variables.
1859 void
1860 add_preinit_statement(Gogo*, Statement*);
1862 // Lower the initialization expression after parsing is complete.
1863 void
1864 lower_init_expression(Gogo*, Named_object*, Statement_inserter*);
1866 // Flatten the initialization expression after ordering evaluations.
1867 void
1868 flatten_init_expression(Gogo*, Named_object*, Statement_inserter*);
1870 // A special case: the init value is used only to determine the
1871 // type. This is used if the variable is defined using := with the
1872 // comma-ok form of a map index or a receive expression. The init
1873 // value is actually the map index expression or receive expression.
1874 // We use this because we may not know the right type at parse time.
1875 void
1876 set_type_from_init_tuple()
1877 { this->type_from_init_tuple_ = true; }
1879 // Another special case: the init value is used only to determine
1880 // the type. This is used if the variable is defined using := with
1881 // a range clause. The init value is the range expression. The
1882 // type of the variable is the index type of the range expression
1883 // (i.e., the first value returned by a range).
1884 void
1885 set_type_from_range_index()
1886 { this->type_from_range_index_ = true; }
1888 // Another special case: like set_type_from_range_index, but the
1889 // type is the value type of the range expression (i.e., the second
1890 // value returned by a range).
1891 void
1892 set_type_from_range_value()
1893 { this->type_from_range_value_ = true; }
1895 // Another special case: the init value is used only to determine
1896 // the type. This is used if the variable is defined using := with
1897 // a case in a select statement. The init value is the channel.
1898 // The type of the variable is the channel's element type.
1899 void
1900 set_type_from_chan_element()
1901 { this->type_from_chan_element_ = true; }
1903 // After we lower the select statement, we once again set the type
1904 // from the initialization expression.
1905 void
1906 clear_type_from_chan_element()
1908 go_assert(this->type_from_chan_element_);
1909 this->type_from_chan_element_ = false;
1912 // TRUE if this variable was created for a type switch clause.
1913 bool
1914 is_type_switch_var() const
1915 { return this->is_type_switch_var_; }
1917 // Note that this variable was created for a type switch clause.
1918 void
1919 set_is_type_switch_var()
1920 { this->is_type_switch_var_ = true; }
1922 // Mark the variable as going into a unique section.
1923 void
1924 set_in_unique_section()
1926 go_assert(this->is_global_);
1927 this->in_unique_section_ = true;
1930 // Return the top-level declaration for this variable.
1931 Statement*
1932 toplevel_decl()
1933 { return this->toplevel_decl_; }
1935 // Set the top-level declaration for this variable. Only used for local
1936 // variables
1937 void
1938 set_toplevel_decl(Statement* s)
1940 go_assert(!this->is_global_ && !this->is_parameter_ && !this->is_receiver_);
1941 this->toplevel_decl_ = s;
1944 // Traverse the initializer expression.
1946 traverse_expression(Traverse*, unsigned int traverse_mask);
1948 // Determine the type of the variable if necessary.
1949 void
1950 determine_type();
1952 // Get the backend representation of the variable.
1953 Bvariable*
1954 get_backend_variable(Gogo*, Named_object*, const Package*,
1955 const std::string&);
1957 // Get the initial value of the variable. This may only
1958 // be called if has_pre_init() returns false.
1959 Bexpression*
1960 get_init(Gogo*, Named_object* function);
1962 // Return a series of statements which sets the value of the
1963 // variable in DECL. This should only be called is has_pre_init()
1964 // returns true. DECL may be NULL for a sink variable.
1965 Bstatement*
1966 get_init_block(Gogo*, Named_object* function, Bvariable* decl);
1968 // Export the variable.
1969 void
1970 export_var(Export*, const std::string& name) const;
1972 // Import a variable.
1973 static void
1974 import_var(Import*, std::string* pname, Type** ptype);
1976 private:
1977 // The type of a tuple.
1978 Type*
1979 type_from_tuple(Expression*, bool) const;
1981 // The type of a range.
1982 Type*
1983 type_from_range(Expression*, bool, bool) const;
1985 // The element type of a channel.
1986 Type*
1987 type_from_chan_element(Expression*, bool) const;
1989 // The variable's type. This may be NULL if the type is set from
1990 // the expression.
1991 Type* type_;
1992 // The initial value. This may be NULL if the variable should be
1993 // initialized to the default value for the type.
1994 Expression* init_;
1995 // Statements to run before the init statement.
1996 Block* preinit_;
1997 // Location of variable definition.
1998 Location location_;
1999 // Backend representation.
2000 Bvariable* backend_;
2001 // Whether this is a global variable.
2002 bool is_global_ : 1;
2003 // Whether this is a function parameter.
2004 bool is_parameter_ : 1;
2005 // Whether this is a closure parameter.
2006 bool is_closure_ : 1;
2007 // Whether this is the receiver parameter of a method.
2008 bool is_receiver_ : 1;
2009 // Whether this is the varargs parameter of a function.
2010 bool is_varargs_parameter_ : 1;
2011 // Whether this variable is ever referenced.
2012 bool is_used_ : 1;
2013 // Whether something takes the address of this variable. For a
2014 // local variable this implies that the variable has to be on the
2015 // heap if it escapes from its function.
2016 bool is_address_taken_ : 1;
2017 // Whether something takes the address of this variable such that
2018 // the address does not escape the function.
2019 bool is_non_escaping_address_taken_ : 1;
2020 // True if we have seen this variable in a traversal.
2021 bool seen_ : 1;
2022 // True if we have lowered the initialization expression.
2023 bool init_is_lowered_ : 1;
2024 // True if we have flattened the initialization expression.
2025 bool init_is_flattened_ : 1;
2026 // True if init is a tuple used to set the type.
2027 bool type_from_init_tuple_ : 1;
2028 // True if init is a range clause and the type is the index type.
2029 bool type_from_range_index_ : 1;
2030 // True if init is a range clause and the type is the value type.
2031 bool type_from_range_value_ : 1;
2032 // True if init is a channel and the type is the channel's element type.
2033 bool type_from_chan_element_ : 1;
2034 // True if this is a variable created for a type switch case.
2035 bool is_type_switch_var_ : 1;
2036 // True if we have determined types.
2037 bool determined_type_ : 1;
2038 // True if this variable should be put in a unique section. This is
2039 // used for field tracking.
2040 bool in_unique_section_ : 1;
2041 // Whether this variable escapes the function it is created in. This is
2042 // true until shown otherwise.
2043 bool escapes_ : 1;
2044 // The top-level declaration for this variable. Only used for local
2045 // variables. Must be a Temporary_statement if not NULL.
2046 Statement* toplevel_decl_;
2049 // A variable which is really the name for a function return value, or
2050 // part of one.
2052 class Result_variable
2054 public:
2055 Result_variable(Type* type, Function* function, int index,
2056 Location location)
2057 : type_(type), function_(function), index_(index), location_(location),
2058 backend_(NULL), is_address_taken_(false),
2059 is_non_escaping_address_taken_(false), escapes_(true)
2062 // Get the type of the result variable.
2063 Type*
2064 type() const
2065 { return this->type_; }
2067 // Get the function that this is associated with.
2068 Function*
2069 function() const
2070 { return this->function_; }
2072 // Index in the list of function results.
2074 index() const
2075 { return this->index_; }
2077 // The location of the variable definition.
2078 Location
2079 location() const
2080 { return this->location_; }
2082 // Whether this variable's address is taken.
2083 bool
2084 is_address_taken() const
2085 { return this->is_address_taken_; }
2087 // Note that something takes the address of this variable.
2088 void
2089 set_address_taken()
2090 { this->is_address_taken_ = true; }
2092 // Return whether the address is taken but does not escape.
2093 bool
2094 is_non_escaping_address_taken() const
2095 { return this->is_non_escaping_address_taken_; }
2097 // Note that something takes the address of this variable such that
2098 // the address does not escape the function.
2099 void
2100 set_non_escaping_address_taken()
2101 { this->is_non_escaping_address_taken_ = true; }
2103 // Return whether this variable escapes the function it is declared in.
2104 bool
2105 escapes()
2106 { return this->escapes_; }
2108 // Note that this variable does not escape the function it is declared in.
2109 void
2110 set_does_not_escape()
2111 { this->escapes_ = false; }
2113 // Whether this variable should live in the heap.
2114 bool
2115 is_in_heap() const
2117 return this->is_address_taken_
2118 && this->escapes_;
2121 // Set the function. This is used when cloning functions which call
2122 // recover.
2123 void
2124 set_function(Function* function)
2125 { this->function_ = function; }
2127 // Get the backend representation of the variable.
2128 Bvariable*
2129 get_backend_variable(Gogo*, Named_object*, const std::string&);
2131 private:
2132 // Type of result variable.
2133 Type* type_;
2134 // Function with which this is associated.
2135 Function* function_;
2136 // Index in list of results.
2137 int index_;
2138 // Where the result variable is defined.
2139 Location location_;
2140 // Backend representation.
2141 Bvariable* backend_;
2142 // Whether something takes the address of this variable.
2143 bool is_address_taken_;
2144 // Whether something takes the address of this variable such that
2145 // the address does not escape the function.
2146 bool is_non_escaping_address_taken_;
2147 // Whether this variable escapes the function it is created in. This is
2148 // true until shown otherwise.
2149 bool escapes_;
2152 // The value we keep for a named constant. This lets us hold a type
2153 // and an expression.
2155 class Named_constant
2157 public:
2158 Named_constant(Type* type, Expression* expr, int iota_value,
2159 Location location)
2160 : type_(type), expr_(expr), iota_value_(iota_value), location_(location),
2161 lowering_(false), is_sink_(false), bconst_(NULL)
2164 Type*
2165 type() const
2166 { return this->type_; }
2168 void
2169 set_type(Type* t);
2171 Expression*
2172 expr() const
2173 { return this->expr_; }
2176 iota_value() const
2177 { return this->iota_value_; }
2179 Location
2180 location() const
2181 { return this->location_; }
2183 // Whether we are lowering.
2184 bool
2185 lowering() const
2186 { return this->lowering_; }
2188 // Set that we are lowering.
2189 void
2190 set_lowering()
2191 { this->lowering_ = true; }
2193 // We are no longer lowering.
2194 void
2195 clear_lowering()
2196 { this->lowering_ = false; }
2198 bool
2199 is_sink() const
2200 { return this->is_sink_; }
2202 void
2203 set_is_sink()
2204 { this->is_sink_ = true; }
2206 // Traverse the expression.
2208 traverse_expression(Traverse*);
2210 // Determine the type of the constant if necessary.
2211 void
2212 determine_type();
2214 // Indicate that we found and reported an error for this constant.
2215 void
2216 set_error();
2218 // Export the constant.
2219 void
2220 export_const(Export*, const std::string& name) const;
2222 // Import a constant.
2223 static void
2224 import_const(Import*, std::string*, Type**, Expression**);
2226 // Get the backend representation of the constant value.
2227 Bexpression*
2228 get_backend(Gogo*, Named_object*);
2230 private:
2231 // The type of the constant.
2232 Type* type_;
2233 // The expression for the constant.
2234 Expression* expr_;
2235 // If the predeclared constant iota is used in EXPR_, this is the
2236 // value it will have. We do this because at parse time we don't
2237 // know whether the name "iota" will refer to the predeclared
2238 // constant or to something else. We put in the right value in when
2239 // we lower.
2240 int iota_value_;
2241 // The location of the definition.
2242 Location location_;
2243 // Whether we are currently lowering this constant.
2244 bool lowering_;
2245 // Whether this constant is blank named and needs only type checking.
2246 bool is_sink_;
2247 // The backend representation of the constant value.
2248 Bexpression* bconst_;
2251 // A type declaration.
2253 class Type_declaration
2255 public:
2256 Type_declaration(Location location)
2257 : location_(location), in_function_(NULL), in_function_index_(0),
2258 methods_(), issued_warning_(false)
2261 // Return the location.
2262 Location
2263 location() const
2264 { return this->location_; }
2266 // Return the function in which this type is declared. This will
2267 // return NULL for a type declared in global scope.
2268 Named_object*
2269 in_function(unsigned int* pindex)
2271 *pindex = this->in_function_index_;
2272 return this->in_function_;
2275 // Set the function in which this type is declared.
2276 void
2277 set_in_function(Named_object* f, unsigned int index)
2279 this->in_function_ = f;
2280 this->in_function_index_ = index;
2283 // Add a method to this type. This is used when methods are defined
2284 // before the type.
2285 Named_object*
2286 add_method(const std::string& name, Function* function);
2288 // Add a method declaration to this type.
2289 Named_object*
2290 add_method_declaration(const std::string& name, Package*,
2291 Function_type* type, Location location);
2293 // Add an already created object as a method.
2294 void
2295 add_existing_method(Named_object* no)
2296 { this->methods_.push_back(no); }
2298 // Return whether any methods were defined.
2299 bool
2300 has_methods() const;
2302 // Return the methods.
2303 const std::vector<Named_object*>*
2304 methods() const
2305 { return &this->methods_; }
2307 // Define methods when the real type is known.
2308 void
2309 define_methods(Named_type*);
2311 // This is called if we are trying to use this type. It returns
2312 // true if we should issue a warning.
2313 bool
2314 using_type();
2316 private:
2317 // The location of the type declaration.
2318 Location location_;
2319 // If this type is declared in a function, a pointer back to the
2320 // function in which it is defined.
2321 Named_object* in_function_;
2322 // The index of this type in IN_FUNCTION_.
2323 unsigned int in_function_index_;
2324 // Methods defined before the type is defined.
2325 std::vector<Named_object*> methods_;
2326 // True if we have issued a warning about a use of this type
2327 // declaration when it is undefined.
2328 bool issued_warning_;
2331 // An unknown object. These are created by the parser for forward
2332 // references to names which have not been seen before. In a correct
2333 // program, these will always point to a real definition by the end of
2334 // the parse. Because they point to another Named_object, these may
2335 // only be referenced by Unknown_expression objects.
2337 class Unknown_name
2339 public:
2340 Unknown_name(Location location)
2341 : location_(location), real_named_object_(NULL)
2344 // Return the location where this name was first seen.
2345 Location
2346 location() const
2347 { return this->location_; }
2349 // Return the real named object that this points to, or NULL if it
2350 // was never resolved.
2351 Named_object*
2352 real_named_object() const
2353 { return this->real_named_object_; }
2355 // Set the real named object that this points to.
2356 void
2357 set_real_named_object(Named_object* no);
2359 private:
2360 // The location where this name was first seen.
2361 Location location_;
2362 // The real named object when it is known.
2363 Named_object*
2364 real_named_object_;
2367 // A named object named. This is the result of a declaration. We
2368 // don't use a superclass because they all have to be handled
2369 // differently.
2371 class Named_object
2373 public:
2374 enum Classification
2376 // An uninitialized Named_object. We should never see this.
2377 NAMED_OBJECT_UNINITIALIZED,
2378 // An erroneous name. This indicates a parse error, to avoid
2379 // later errors about undefined references.
2380 NAMED_OBJECT_ERRONEOUS,
2381 // An unknown name. This is used for forward references. In a
2382 // correct program, these will all be resolved by the end of the
2383 // parse.
2384 NAMED_OBJECT_UNKNOWN,
2385 // A const.
2386 NAMED_OBJECT_CONST,
2387 // A type.
2388 NAMED_OBJECT_TYPE,
2389 // A forward type declaration.
2390 NAMED_OBJECT_TYPE_DECLARATION,
2391 // A var.
2392 NAMED_OBJECT_VAR,
2393 // A result variable in a function.
2394 NAMED_OBJECT_RESULT_VAR,
2395 // The blank identifier--the special variable named _.
2396 NAMED_OBJECT_SINK,
2397 // A func.
2398 NAMED_OBJECT_FUNC,
2399 // A forward func declaration.
2400 NAMED_OBJECT_FUNC_DECLARATION,
2401 // A package.
2402 NAMED_OBJECT_PACKAGE
2405 // Return the classification.
2406 Classification
2407 classification() const
2408 { return this->classification_; }
2410 // Classifiers.
2412 bool
2413 is_erroneous() const
2414 { return this->classification_ == NAMED_OBJECT_ERRONEOUS; }
2416 bool
2417 is_unknown() const
2418 { return this->classification_ == NAMED_OBJECT_UNKNOWN; }
2420 bool
2421 is_const() const
2422 { return this->classification_ == NAMED_OBJECT_CONST; }
2424 bool
2425 is_type() const
2426 { return this->classification_ == NAMED_OBJECT_TYPE; }
2428 bool
2429 is_type_declaration() const
2430 { return this->classification_ == NAMED_OBJECT_TYPE_DECLARATION; }
2432 bool
2433 is_variable() const
2434 { return this->classification_ == NAMED_OBJECT_VAR; }
2436 bool
2437 is_result_variable() const
2438 { return this->classification_ == NAMED_OBJECT_RESULT_VAR; }
2440 bool
2441 is_sink() const
2442 { return this->classification_ == NAMED_OBJECT_SINK; }
2444 bool
2445 is_function() const
2446 { return this->classification_ == NAMED_OBJECT_FUNC; }
2448 bool
2449 is_function_declaration() const
2450 { return this->classification_ == NAMED_OBJECT_FUNC_DECLARATION; }
2452 bool
2453 is_package() const
2454 { return this->classification_ == NAMED_OBJECT_PACKAGE; }
2456 // Creators.
2458 static Named_object*
2459 make_erroneous_name(const std::string& name)
2460 { return new Named_object(name, NULL, NAMED_OBJECT_ERRONEOUS); }
2462 static Named_object*
2463 make_unknown_name(const std::string& name, Location);
2465 static Named_object*
2466 make_constant(const Typed_identifier&, const Package*, Expression*,
2467 int iota_value);
2469 static Named_object*
2470 make_type(const std::string&, const Package*, Type*, Location);
2472 static Named_object*
2473 make_type_declaration(const std::string&, const Package*, Location);
2475 static Named_object*
2476 make_variable(const std::string&, const Package*, Variable*);
2478 static Named_object*
2479 make_result_variable(const std::string&, Result_variable*);
2481 static Named_object*
2482 make_sink();
2484 static Named_object*
2485 make_function(const std::string&, const Package*, Function*);
2487 static Named_object*
2488 make_function_declaration(const std::string&, const Package*, Function_type*,
2489 Location);
2491 static Named_object*
2492 make_package(const std::string& alias, Package* package);
2494 // Getters.
2496 Unknown_name*
2497 unknown_value()
2499 go_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
2500 return this->u_.unknown_value;
2503 const Unknown_name*
2504 unknown_value() const
2506 go_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
2507 return this->u_.unknown_value;
2510 Named_constant*
2511 const_value()
2513 go_assert(this->classification_ == NAMED_OBJECT_CONST);
2514 return this->u_.const_value;
2517 const Named_constant*
2518 const_value() const
2520 go_assert(this->classification_ == NAMED_OBJECT_CONST);
2521 return this->u_.const_value;
2524 Named_type*
2525 type_value()
2527 go_assert(this->classification_ == NAMED_OBJECT_TYPE);
2528 return this->u_.type_value;
2531 const Named_type*
2532 type_value() const
2534 go_assert(this->classification_ == NAMED_OBJECT_TYPE);
2535 return this->u_.type_value;
2538 Type_declaration*
2539 type_declaration_value()
2541 go_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
2542 return this->u_.type_declaration;
2545 const Type_declaration*
2546 type_declaration_value() const
2548 go_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
2549 return this->u_.type_declaration;
2552 Variable*
2553 var_value()
2555 go_assert(this->classification_ == NAMED_OBJECT_VAR);
2556 return this->u_.var_value;
2559 const Variable*
2560 var_value() const
2562 go_assert(this->classification_ == NAMED_OBJECT_VAR);
2563 return this->u_.var_value;
2566 Result_variable*
2567 result_var_value()
2569 go_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
2570 return this->u_.result_var_value;
2573 const Result_variable*
2574 result_var_value() const
2576 go_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
2577 return this->u_.result_var_value;
2580 Function*
2581 func_value()
2583 go_assert(this->classification_ == NAMED_OBJECT_FUNC);
2584 return this->u_.func_value;
2587 const Function*
2588 func_value() const
2590 go_assert(this->classification_ == NAMED_OBJECT_FUNC);
2591 return this->u_.func_value;
2594 Function_declaration*
2595 func_declaration_value()
2597 go_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
2598 return this->u_.func_declaration_value;
2601 const Function_declaration*
2602 func_declaration_value() const
2604 go_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
2605 return this->u_.func_declaration_value;
2608 Package*
2609 package_value()
2611 go_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
2612 return this->u_.package_value;
2615 const Package*
2616 package_value() const
2618 go_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
2619 return this->u_.package_value;
2622 const std::string&
2623 name() const
2624 { return this->name_; }
2626 // Return the name to use in an error message. The difference is
2627 // that if this Named_object is defined in a different package, this
2628 // will return PACKAGE.NAME.
2629 std::string
2630 message_name() const;
2632 const Package*
2633 package() const
2634 { return this->package_; }
2636 // Resolve an unknown value if possible. This returns the same
2637 // Named_object or a new one.
2638 Named_object*
2639 resolve()
2641 Named_object* ret = this;
2642 if (this->is_unknown())
2644 Named_object* r = this->unknown_value()->real_named_object();
2645 if (r != NULL)
2646 ret = r;
2648 return ret;
2651 const Named_object*
2652 resolve() const
2654 const Named_object* ret = this;
2655 if (this->is_unknown())
2657 const Named_object* r = this->unknown_value()->real_named_object();
2658 if (r != NULL)
2659 ret = r;
2661 return ret;
2664 // The location where this object was defined or referenced.
2665 Location
2666 location() const;
2668 // Convert a variable to the backend representation.
2669 Bvariable*
2670 get_backend_variable(Gogo*, Named_object* function);
2672 // Return the external identifier for this object.
2673 std::string
2674 get_id(Gogo*);
2676 // Get the backend representation of this object.
2677 void
2678 get_backend(Gogo*, std::vector<Bexpression*>&, std::vector<Btype*>&,
2679 std::vector<Bfunction*>&);
2681 // Define a type declaration.
2682 void
2683 set_type_value(Named_type*);
2685 // Define a function declaration.
2686 void
2687 set_function_value(Function*);
2689 // Declare an unknown name as a type declaration.
2690 void
2691 declare_as_type();
2693 // Export this object.
2694 void
2695 export_named_object(Export*) const;
2697 // Mark this named object as an invalid redefinition of another object.
2698 void
2699 set_is_redefinition()
2700 { this->is_redefinition_ = true; }
2702 // Return whether or not this object is a invalid redefinition of another
2703 // object.
2704 bool
2705 is_redefinition() const
2706 { return this->is_redefinition_; }
2708 private:
2709 Named_object(const std::string&, const Package*, Classification);
2711 // The name of the object.
2712 std::string name_;
2713 // The package that this object is in. This is NULL if it is in the
2714 // file we are compiling.
2715 const Package* package_;
2716 // The type of object this is.
2717 Classification classification_;
2718 // The real data.
2719 union
2721 Unknown_name* unknown_value;
2722 Named_constant* const_value;
2723 Named_type* type_value;
2724 Type_declaration* type_declaration;
2725 Variable* var_value;
2726 Result_variable* result_var_value;
2727 Function* func_value;
2728 Function_declaration* func_declaration_value;
2729 Package* package_value;
2730 } u_;
2731 // True if this object is an invalid redefinition of another object.
2732 bool is_redefinition_;
2735 // A binding contour. This binds names to objects.
2737 class Bindings
2739 public:
2740 // Type for mapping from names to objects.
2741 typedef Unordered_map(std::string, Named_object*) Contour;
2743 Bindings(Bindings* enclosing);
2745 // Add an erroneous name.
2746 Named_object*
2747 add_erroneous_name(const std::string& name)
2748 { return this->add_named_object(Named_object::make_erroneous_name(name)); }
2750 // Add an unknown name.
2751 Named_object*
2752 add_unknown_name(const std::string& name, Location location)
2754 return this->add_named_object(Named_object::make_unknown_name(name,
2755 location));
2758 // Add a constant.
2759 Named_object*
2760 add_constant(const Typed_identifier& tid, const Package* package,
2761 Expression* expr, int iota_value)
2763 return this->add_named_object(Named_object::make_constant(tid, package,
2764 expr,
2765 iota_value));
2768 // Add a type.
2769 Named_object*
2770 add_type(const std::string& name, const Package* package, Type* type,
2771 Location location)
2773 return this->add_named_object(Named_object::make_type(name, package, type,
2774 location));
2777 // Add a named type. This is used for builtin types, and to add an
2778 // imported type to the global scope.
2779 Named_object*
2780 add_named_type(Named_type* named_type);
2782 // Add a type declaration.
2783 Named_object*
2784 add_type_declaration(const std::string& name, const Package* package,
2785 Location location)
2787 Named_object* no = Named_object::make_type_declaration(name, package,
2788 location);
2789 return this->add_named_object(no);
2792 // Add a variable.
2793 Named_object*
2794 add_variable(const std::string& name, const Package* package,
2795 Variable* variable)
2797 return this->add_named_object(Named_object::make_variable(name, package,
2798 variable));
2801 // Add a result variable.
2802 Named_object*
2803 add_result_variable(const std::string& name, Result_variable* result)
2805 return this->add_named_object(Named_object::make_result_variable(name,
2806 result));
2809 // Add a function.
2810 Named_object*
2811 add_function(const std::string& name, const Package*, Function* function);
2813 // Add a function declaration.
2814 Named_object*
2815 add_function_declaration(const std::string& name, const Package* package,
2816 Function_type* type, Location location);
2818 // Add a package. The location is the location of the import
2819 // statement.
2820 Named_object*
2821 add_package(const std::string& alias, Package* package)
2823 Named_object* no = Named_object::make_package(alias, package);
2824 return this->add_named_object(no);
2827 // Define a type which was already declared.
2828 void
2829 define_type(Named_object*, Named_type*);
2831 // Add a method to the list of objects. This is not added to the
2832 // lookup table.
2833 void
2834 add_method(Named_object*);
2836 // Add a named object to this binding.
2837 Named_object*
2838 add_named_object(Named_object* no)
2839 { return this->add_named_object_to_contour(&this->bindings_, no); }
2841 // Clear all names in file scope from the bindings.
2842 void
2843 clear_file_scope(Gogo*);
2845 // Look up a name in this binding contour and in any enclosing
2846 // binding contours. This returns NULL if the name is not found.
2847 Named_object*
2848 lookup(const std::string&) const;
2850 // Look up a name in this binding contour without looking in any
2851 // enclosing binding contours. Returns NULL if the name is not found.
2852 Named_object*
2853 lookup_local(const std::string&) const;
2855 // Remove a name.
2856 void
2857 remove_binding(Named_object*);
2859 // Mark all variables as used. This is used for some types of parse
2860 // error.
2861 void
2862 mark_locals_used();
2864 // Traverse the tree. See the Traverse class.
2866 traverse(Traverse*, bool is_global);
2868 // Iterate over definitions. This does not include things which
2869 // were only declared.
2871 typedef std::vector<Named_object*>::const_iterator
2872 const_definitions_iterator;
2874 const_definitions_iterator
2875 begin_definitions() const
2876 { return this->named_objects_.begin(); }
2878 const_definitions_iterator
2879 end_definitions() const
2880 { return this->named_objects_.end(); }
2882 // Return the number of definitions.
2883 size_t
2884 size_definitions() const
2885 { return this->named_objects_.size(); }
2887 // Return whether there are no definitions.
2888 bool
2889 empty_definitions() const
2890 { return this->named_objects_.empty(); }
2892 // Iterate over declarations. This is everything that has been
2893 // declared, which includes everything which has been defined.
2895 typedef Contour::const_iterator const_declarations_iterator;
2897 const_declarations_iterator
2898 begin_declarations() const
2899 { return this->bindings_.begin(); }
2901 const_declarations_iterator
2902 end_declarations() const
2903 { return this->bindings_.end(); }
2905 // Return the number of declarations.
2906 size_t
2907 size_declarations() const
2908 { return this->bindings_.size(); }
2910 // Return whether there are no declarations.
2911 bool
2912 empty_declarations() const
2913 { return this->bindings_.empty(); }
2915 // Return the first declaration.
2916 Named_object*
2917 first_declaration()
2918 { return this->bindings_.empty() ? NULL : this->bindings_.begin()->second; }
2920 private:
2921 Named_object*
2922 add_named_object_to_contour(Contour*, Named_object*);
2924 Named_object*
2925 new_definition(Named_object*, Named_object*);
2927 // Enclosing bindings.
2928 Bindings* enclosing_;
2929 // The list of objects.
2930 std::vector<Named_object*> named_objects_;
2931 // The mapping from names to objects.
2932 Contour bindings_;
2935 // A label.
2937 class Label
2939 public:
2940 Label(const std::string& name)
2941 : name_(name), location_(Linemap::unknown_location()), snapshot_(NULL),
2942 refs_(), is_used_(false), blabel_(NULL), depth_(DEPTH_UNKNOWN)
2945 // Return the label's name.
2946 const std::string&
2947 name() const
2948 { return this->name_; }
2950 // Return whether the label has been defined.
2951 bool
2952 is_defined() const
2953 { return !Linemap::is_unknown_location(this->location_); }
2955 // Return whether the label has been used.
2956 bool
2957 is_used() const
2958 { return this->is_used_; }
2960 // Record that the label is used.
2961 void
2962 set_is_used()
2963 { this->is_used_ = true; }
2965 // Return whether this label is looping.
2966 bool
2967 looping() const
2968 { return this->depth_ == DEPTH_LOOPING; }
2970 // Set this label as looping.
2971 void
2972 set_looping()
2973 { this->depth_ = DEPTH_LOOPING; }
2975 // Return whether this label is nonlooping.
2976 bool
2977 nonlooping() const
2978 { return this->depth_ == DEPTH_NONLOOPING; }
2980 // Set this label as nonlooping.
2981 void
2982 set_nonlooping()
2983 { this->depth_ = DEPTH_NONLOOPING; }
2985 // Return the location of the definition.
2986 Location
2987 location() const
2988 { return this->location_; }
2990 // Return the bindings snapshot.
2991 Bindings_snapshot*
2992 snapshot() const
2993 { return this->snapshot_; }
2995 // Add a snapshot of a goto which refers to this label.
2996 void
2997 add_snapshot_ref(Bindings_snapshot* snapshot)
2999 go_assert(Linemap::is_unknown_location(this->location_));
3000 this->refs_.push_back(snapshot);
3003 // Return the list of snapshots of goto statements which refer to
3004 // this label.
3005 const std::vector<Bindings_snapshot*>&
3006 refs() const
3007 { return this->refs_; }
3009 // Clear the references.
3010 void
3011 clear_refs();
3013 // Define the label at LOCATION with the given bindings snapshot.
3014 void
3015 define(Location location, Bindings_snapshot* snapshot)
3017 if (this->is_dummy_label())
3018 return;
3019 go_assert(Linemap::is_unknown_location(this->location_)
3020 && this->snapshot_ == NULL);
3021 this->location_ = location;
3022 this->snapshot_ = snapshot;
3025 // Return the backend representation for this label.
3026 Blabel*
3027 get_backend_label(Translate_context*);
3029 // Return an expression for the address of this label. This is used
3030 // to get the return address of a deferred function to see whether
3031 // the function may call recover.
3032 Bexpression*
3033 get_addr(Translate_context*, Location location);
3035 // Return a dummy label, representing any instance of the blank label.
3036 static Label*
3037 create_dummy_label();
3039 // Return TRUE if this is a dummy label.
3040 bool
3041 is_dummy_label() const
3042 { return this->name_ == "_"; }
3044 // A classification of a label's looping depth.
3045 enum Loop_depth
3047 DEPTH_UNKNOWN,
3048 // A label never jumped to.
3049 DEPTH_NONLOOPING,
3050 // A label jumped to.
3051 DEPTH_LOOPING
3054 private:
3055 // The name of the label.
3056 std::string name_;
3057 // The location of the definition. This is 0 if the label has not
3058 // yet been defined.
3059 Location location_;
3060 // A snapshot of the set of bindings defined at this label, used to
3061 // issue errors about invalid goto statements.
3062 Bindings_snapshot* snapshot_;
3063 // A list of snapshots of goto statements which refer to this label.
3064 std::vector<Bindings_snapshot*> refs_;
3065 // Whether the label has been used.
3066 bool is_used_;
3067 // The backend representation.
3068 Blabel* blabel_;
3069 // The looping depth of this label, for escape analysis.
3070 Loop_depth depth_;
3073 // An unnamed label. These are used when lowering loops.
3075 class Unnamed_label
3077 public:
3078 Unnamed_label(Location location)
3079 : location_(location), derived_from_(NULL), blabel_(NULL)
3082 // Get the location where the label is defined.
3083 Location
3084 location() const
3085 { return this->location_; }
3087 // Set the location where the label is defined.
3088 void
3089 set_location(Location location)
3090 { this->location_ = location; }
3092 // Get the top level statement this unnamed label is derived from.
3093 Statement*
3094 derived_from() const
3095 { return this->derived_from_; }
3097 // Set the top level statement this unnamed label is derived from.
3098 void
3099 set_derived_from(Statement* s)
3100 { this->derived_from_ = s; }
3102 // Return a statement which defines this label.
3103 Bstatement*
3104 get_definition(Translate_context*);
3106 // Return a goto to this label from LOCATION.
3107 Bstatement*
3108 get_goto(Translate_context*, Location location);
3110 private:
3111 // Return the backend representation.
3112 Blabel*
3113 get_blabel(Translate_context*);
3115 // The location where the label is defined.
3116 Location location_;
3117 // The top-level statement this unnamed label was derived/lowered from.
3118 // This is NULL is this label is not the top-level of a lowered statement.
3119 Statement* derived_from_;
3120 // The backend representation of this label.
3121 Blabel* blabel_;
3124 // An alias for an imported package.
3126 class Package_alias
3128 public:
3129 Package_alias(Location location)
3130 : location_(location), used_(0)
3133 // The location of the import statement.
3134 Location
3135 location()
3136 { return this->location_; }
3138 // How many symbols from the package were used under this alias.
3139 size_t
3140 used() const
3141 { return this->used_; }
3143 // Note that some symbol was used under this alias.
3144 void
3145 note_usage()
3146 { this->used_++; }
3148 private:
3149 // The location of the import statement.
3150 Location location_;
3151 // The amount of times some name from this package was used under this alias.
3152 size_t used_;
3155 // An imported package.
3157 class Package
3159 public:
3160 Package(const std::string& pkgpath, const std::string& pkgpath_symbol,
3161 Location location);
3163 // Get the package path used for all symbols exported from this
3164 // package.
3165 const std::string&
3166 pkgpath() const
3167 { return this->pkgpath_; }
3169 // Return the package path to use for a symbol name.
3170 std::string
3171 pkgpath_symbol() const;
3173 // Set the package path symbol.
3174 void
3175 set_pkgpath_symbol(const std::string&);
3177 // Return the location of the most recent import statement.
3178 Location
3179 location() const
3180 { return this->location_; }
3182 // Return whether we know the name of this package yet.
3183 bool
3184 has_package_name() const
3185 { return !this->package_name_.empty(); }
3187 // The name that this package uses in its package clause. This may
3188 // be different from the name in the associated Named_object if the
3189 // import statement used an alias.
3190 const std::string&
3191 package_name() const
3193 go_assert(!this->package_name_.empty());
3194 return this->package_name_;
3197 // Return the bindings.
3198 Bindings*
3199 bindings()
3200 { return this->bindings_; }
3202 // Type used to map import names to package aliases.
3203 typedef std::map<std::string, Package_alias*> Aliases;
3205 // Return the set of package aliases.
3206 const Aliases&
3207 aliases() const
3208 { return this->aliases_; }
3210 // Note that some symbol from this package was used and qualified by ALIAS.
3211 // For dot imports, the ALIAS should be ".PACKAGE_NAME".
3212 void
3213 note_usage(const std::string& alias) const;
3215 // Note that USAGE might be a fake usage of this package.
3216 void
3217 note_fake_usage(Expression* usage) const
3218 { this->fake_uses_.insert(usage); }
3220 // Forget a given USAGE of this package.
3221 void
3222 forget_usage(Expression* usage) const;
3224 // Clear the used field for the next file.
3225 void
3226 clear_used();
3228 // Look up a name in the package. Returns NULL if the name is not
3229 // found.
3230 Named_object*
3231 lookup(const std::string& name) const
3232 { return this->bindings_->lookup(name); }
3234 // Set the name of the package.
3235 void
3236 set_package_name(const std::string& name, Location);
3238 // Set the location of the package. This is used to record the most
3239 // recent import location.
3240 void
3241 set_location(Location location)
3242 { this->location_ = location; }
3244 // Add a package name as an ALIAS for this package.
3245 Package_alias*
3246 add_alias(const std::string& alias, Location);
3248 // Add a constant to the package.
3249 Named_object*
3250 add_constant(const Typed_identifier& tid, Expression* expr)
3251 { return this->bindings_->add_constant(tid, this, expr, 0); }
3253 // Add a type to the package.
3254 Named_object*
3255 add_type(const std::string& name, Type* type, Location location)
3256 { return this->bindings_->add_type(name, this, type, location); }
3258 // Add a type declaration to the package.
3259 Named_object*
3260 add_type_declaration(const std::string& name, Location location)
3261 { return this->bindings_->add_type_declaration(name, this, location); }
3263 // Add a variable to the package.
3264 Named_object*
3265 add_variable(const std::string& name, Variable* variable)
3266 { return this->bindings_->add_variable(name, this, variable); }
3268 // Add a function declaration to the package.
3269 Named_object*
3270 add_function_declaration(const std::string& name, Function_type* type,
3271 Location loc)
3272 { return this->bindings_->add_function_declaration(name, this, type, loc); }
3274 // Determine types of constants.
3275 void
3276 determine_types();
3278 private:
3279 // The package path for type reflection data.
3280 std::string pkgpath_;
3281 // The package path for symbol names.
3282 std::string pkgpath_symbol_;
3283 // The name that this package uses in the package clause. This may
3284 // be the empty string if it is not yet known.
3285 std::string package_name_;
3286 // The names in this package.
3287 Bindings* bindings_;
3288 // The location of the most recent import statement.
3289 Location location_;
3290 // The set of aliases associated with this package.
3291 Aliases aliases_;
3292 // A set of possibly fake uses of this package. This is mutable because we
3293 // can track fake uses of a package even if we have a const pointer to it.
3294 mutable std::set<Expression*> fake_uses_;
3297 // Return codes for the traversal functions. This is not an enum
3298 // because we want to be able to declare traversal functions in other
3299 // header files without including this one.
3301 // Continue traversal as usual.
3302 const int TRAVERSE_CONTINUE = -1;
3304 // Exit traversal.
3305 const int TRAVERSE_EXIT = 0;
3307 // Continue traversal, but skip components of the current object.
3308 // E.g., if this is returned by Traverse::statement, we do not
3309 // traverse the expressions in the statement even if
3310 // traverse_expressions is set in the traverse_mask.
3311 const int TRAVERSE_SKIP_COMPONENTS = 1;
3313 // This class is used when traversing the parse tree. The caller uses
3314 // a subclass which overrides functions as desired.
3316 class Traverse
3318 public:
3319 // These bitmasks say what to traverse.
3320 static const unsigned int traverse_variables = 0x1;
3321 static const unsigned int traverse_constants = 0x2;
3322 static const unsigned int traverse_functions = 0x4;
3323 static const unsigned int traverse_blocks = 0x8;
3324 static const unsigned int traverse_statements = 0x10;
3325 static const unsigned int traverse_expressions = 0x20;
3326 static const unsigned int traverse_types = 0x40;
3327 static const unsigned int traverse_func_declarations = 0x80;
3329 Traverse(unsigned int traverse_mask)
3330 : traverse_mask_(traverse_mask), types_seen_(NULL), expressions_seen_(NULL)
3333 virtual ~Traverse();
3335 // The bitmask of what to traverse.
3336 unsigned int
3337 traverse_mask() const
3338 { return this->traverse_mask_; }
3340 // Record that we are going to traverse a type. This returns true
3341 // if the type has already been seen in this traversal. This is
3342 // required because types, unlike expressions, can form a circular
3343 // graph.
3344 bool
3345 remember_type(const Type*);
3347 // Record that we are going to see an expression. This returns true
3348 // if the expression has already been seen in this traversal. This
3349 // is only needed for cases where multiple expressions can point to
3350 // a single one.
3351 bool
3352 remember_expression(const Expression*);
3354 // These functions return one of the TRAVERSE codes defined above.
3356 // If traverse_variables is set in the mask, this is called for
3357 // every variable in the tree.
3358 virtual int
3359 variable(Named_object*);
3361 // If traverse_constants is set in the mask, this is called for
3362 // every named constant in the tree. The bool parameter is true for
3363 // a global constant.
3364 virtual int
3365 constant(Named_object*, bool);
3367 // If traverse_functions is set in the mask, this is called for
3368 // every function in the tree.
3369 virtual int
3370 function(Named_object*);
3372 // If traverse_blocks is set in the mask, this is called for every
3373 // block in the tree.
3374 virtual int
3375 block(Block*);
3377 // If traverse_statements is set in the mask, this is called for
3378 // every statement in the tree.
3379 virtual int
3380 statement(Block*, size_t* index, Statement*);
3382 // If traverse_expressions is set in the mask, this is called for
3383 // every expression in the tree.
3384 virtual int
3385 expression(Expression**);
3387 // If traverse_types is set in the mask, this is called for every
3388 // type in the tree.
3389 virtual int
3390 type(Type*);
3392 // If traverse_func_declarations is set in the mask, this is called
3393 // for every function declarations in the tree.
3394 virtual int
3395 function_declaration(Named_object*);
3397 private:
3398 // A hash table for types we have seen during this traversal. Note
3399 // that this uses the default hash functions for pointers rather
3400 // than Type_hash_identical and Type_identical. This is because for
3401 // traversal we care about seeing a specific type structure. If
3402 // there are two separate instances of identical types, we want to
3403 // traverse both.
3404 typedef Unordered_set(const Type*) Types_seen;
3406 typedef Unordered_set(const Expression*) Expressions_seen;
3408 // Bitmask of what sort of objects to traverse.
3409 unsigned int traverse_mask_;
3410 // Types which have been seen in this traversal.
3411 Types_seen* types_seen_;
3412 // Expressions which have been seen in this traversal.
3413 Expressions_seen* expressions_seen_;
3416 // A class which makes it easier to insert new statements before the
3417 // current statement during a traversal.
3419 class Statement_inserter
3421 public:
3422 // Empty constructor.
3423 Statement_inserter()
3424 : block_(NULL), pindex_(NULL), gogo_(NULL), var_(NULL)
3427 // Constructor for a statement in a block.
3428 Statement_inserter(Block* block, size_t *pindex)
3429 : block_(block), pindex_(pindex), gogo_(NULL), var_(NULL)
3432 // Constructor for a global variable.
3433 Statement_inserter(Gogo* gogo, Variable* var)
3434 : block_(NULL), pindex_(NULL), gogo_(gogo), var_(var)
3435 { go_assert(var->is_global()); }
3437 // We use the default copy constructor and assignment operator.
3439 // Insert S before the statement we are traversing, or before the
3440 // initialization expression of a global variable.
3441 void
3442 insert(Statement* s);
3444 private:
3445 // The block that the statement is in.
3446 Block* block_;
3447 // The index of the statement that we are traversing.
3448 size_t* pindex_;
3449 // The IR, needed when looking at an initializer expression for a
3450 // global variable.
3451 Gogo* gogo_;
3452 // The global variable, when looking at an initializer expression.
3453 Variable* var_;
3456 // When translating the gogo IR into the backend data structure, this
3457 // is the context we pass down the blocks and statements.
3459 class Translate_context
3461 public:
3462 Translate_context(Gogo* gogo, Named_object* function, Block* block,
3463 Bblock* bblock)
3464 : gogo_(gogo), backend_(gogo->backend()), function_(function),
3465 block_(block), bblock_(bblock), is_const_(false)
3468 // Accessors.
3470 Gogo*
3471 gogo()
3472 { return this->gogo_; }
3474 Backend*
3475 backend()
3476 { return this->backend_; }
3478 Named_object*
3479 function()
3480 { return this->function_; }
3482 Block*
3483 block()
3484 { return this->block_; }
3486 Bblock*
3487 bblock()
3488 { return this->bblock_; }
3490 bool
3491 is_const()
3492 { return this->is_const_; }
3494 // Make a constant context.
3495 void
3496 set_is_const()
3497 { this->is_const_ = true; }
3499 private:
3500 // The IR for the entire compilation unit.
3501 Gogo* gogo_;
3502 // The generator for the backend data structures.
3503 Backend* backend_;
3504 // The function we are currently translating. NULL if not in a
3505 // function, e.g., the initializer of a global variable.
3506 Named_object* function_;
3507 // The block we are currently translating. NULL if not in a
3508 // function.
3509 Block *block_;
3510 // The backend representation of the current block. NULL if block_
3511 // is NULL.
3512 Bblock* bblock_;
3513 // Whether this is being evaluated in a constant context. This is
3514 // used for type descriptor initializers.
3515 bool is_const_;
3518 // Runtime error codes. These must match the values in
3519 // libgo/runtime/go-runtime-error.c.
3521 // Slice index out of bounds: negative or larger than the length of
3522 // the slice.
3523 static const int RUNTIME_ERROR_SLICE_INDEX_OUT_OF_BOUNDS = 0;
3525 // Array index out of bounds.
3526 static const int RUNTIME_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS = 1;
3528 // String index out of bounds.
3529 static const int RUNTIME_ERROR_STRING_INDEX_OUT_OF_BOUNDS = 2;
3531 // Slice slice out of bounds: negative or larger than the length of
3532 // the slice or high bound less than low bound.
3533 static const int RUNTIME_ERROR_SLICE_SLICE_OUT_OF_BOUNDS = 3;
3535 // Array slice out of bounds.
3536 static const int RUNTIME_ERROR_ARRAY_SLICE_OUT_OF_BOUNDS = 4;
3538 // String slice out of bounds.
3539 static const int RUNTIME_ERROR_STRING_SLICE_OUT_OF_BOUNDS = 5;
3541 // Dereference of nil pointer. This is used when there is a
3542 // dereference of a pointer to a very large struct or array, to ensure
3543 // that a gigantic array is not used a proxy to access random memory
3544 // locations.
3545 static const int RUNTIME_ERROR_NIL_DEREFERENCE = 6;
3547 // Slice length or capacity out of bounds in make: negative or
3548 // overflow or length greater than capacity.
3549 static const int RUNTIME_ERROR_MAKE_SLICE_OUT_OF_BOUNDS = 7;
3551 // Map capacity out of bounds in make: negative or overflow.
3552 static const int RUNTIME_ERROR_MAKE_MAP_OUT_OF_BOUNDS = 8;
3554 // Channel capacity out of bounds in make: negative or overflow.
3555 static const int RUNTIME_ERROR_MAKE_CHAN_OUT_OF_BOUNDS = 9;
3557 // Division by zero.
3558 static const int RUNTIME_ERROR_DIVISION_BY_ZERO = 10;
3560 // Go statement with nil function.
3561 static const int RUNTIME_ERROR_GO_NIL = 11;
3563 // This is used by some of the langhooks.
3564 extern Gogo* go_get_gogo();
3566 // Whether we have seen any errors. FIXME: Replace with a backend
3567 // interface.
3568 extern bool saw_errors();
3570 #endif // !defined(GO_GOGO_H)