1 // dataflow.h -- Go frontend dataflow. -*- 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.
14 // Dataflow information about the Go program.
19 // A variable definition.
22 // The statement where the variable is defined.
24 // The value to which the variable is set. This may be NULL.
26 // Whether this is an initialization of the variable.
30 // A variable reference.
33 // The statement where the variable is referenced.
38 typedef std::vector
<Def
> Defs
;
41 typedef std::vector
<Ref
> Refs
;
45 // Initialize the dataflow information.
49 // Add a definition of a variable. STATEMENT assigns a value to
50 // VAR. VAL is the value if it is known, NULL otherwise.
52 add_def(Named_object
* var
, Expression
* val
, Statement
* statement
,
55 // Add a reference to a variable. VAR is the variable, and
56 // STATEMENT is the statement which refers to it.
58 add_ref(Named_object
* var
, Statement
* statement
);
60 // Return the definitions of VAR--the places where it is set.
62 find_defs(Named_object
* var
) const;
64 // Return the references to VAR--the places where it is used.
66 find_refs(Named_object
* var
) const;
69 // Order variables in the map.
73 operator()(const Named_object
*, const Named_object
*) const;
76 // Map from variables to a list of defs of the variable. We use a
77 // map rather than a hash table because the order in which we
78 // process variables may affect the resulting code.
79 typedef std::map
<Named_object
*, Defs
*, Compare_vars
> Defmap
;
81 // Map from variables to a list of refs to the vairable.
82 typedef std::map
<Named_object
*, Refs
*, Compare_vars
> Refmap
;
91 #endif // !defined(GO_DATAFLOW_H)