* sv.po: Update.
[official-gcc.git] / gcc / go / gofrontend / dataflow.h
bloba75c8e661f5a19ba772bcca0f05bec688d7e483c
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.
7 #ifndef GO_DATAFLOW_H
8 #define GO_DATAFLOW_H
10 class Expression;
11 class Named_object;
12 class Statement;
14 // Dataflow information about the Go program.
16 class Dataflow
18 public:
19 // A variable definition.
20 struct Def
22 // The statement where the variable is defined.
23 Statement* statement;
24 // The value to which the variable is set. This may be NULL.
25 Expression* val;
26 // Whether this is an initialization of the variable.
27 bool is_init;
30 // A variable reference.
31 struct Ref
33 // The statement where the variable is referenced.
34 Statement* statement;
37 // A list of defs.
38 typedef std::vector<Def> Defs;
40 // A list of refs.
41 typedef std::vector<Ref> Refs;
43 Dataflow();
45 // Initialize the dataflow information.
46 void
47 initialize(Gogo*);
49 // Add a definition of a variable. STATEMENT assigns a value to
50 // VAR. VAL is the value if it is known, NULL otherwise.
51 void
52 add_def(Named_object* var, Expression* val, Statement* statement,
53 bool is_init);
55 // Add a reference to a variable. VAR is the variable, and
56 // STATEMENT is the statement which refers to it.
57 void
58 add_ref(Named_object* var, Statement* statement);
60 // Return the definitions of VAR--the places where it is set.
61 const Defs*
62 find_defs(Named_object* var) const;
64 // Return the references to VAR--the places where it is used.
65 const Refs*
66 find_refs(Named_object* var) const;
68 private:
69 // Order variables in the map.
70 struct Compare_vars
72 bool
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;
84 // Variable defs.
85 Defmap defs_;
86 // Variable refs;
87 Refmap refs_;
91 #endif // !defined(GO_DATAFLOW_H)