ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReachingDefinition.h
Go to the documentation of this file.
1 #ifndef REACHING_DEFINITION_H
2 #define REACHING_DEFINITION_H
3 
4 #include <assert.h>
5 #include <string>
6 #include "DataFlowAnalysis.h"
7 #include "BitVectorRepr.h"
8 #include "AnalysisInterface.h"
9 #include "StmtInfoCollect.h"
10 #include "AstInterface.h"
11 
12 typedef BitVectorRepr ReachingDefinitions;
13 
15  : private BitVectorReprBase<std::string, std::pair<AstNodePtr, AstNodePtr> >
16 {
17  Ast2StringMap scopemap;
18  public:
19  typedef BitVectorReprBase<std::string, std::pair<AstNodePtr, AstNodePtr> >::iterator iterator;
20  void collect_refs ( AstInterface& fa, const AstNodePtr& h,
21  FunctionSideEffectInterface* a=0,
22  AstInterface::AstNodeList* in = 0);
23  void add_ref( const std::string& name, const AstNodePtr& scope, const std::pair<AstNodePtr,AstNodePtr>& def);
24  void add_unknown_def ( const std::pair<AstNodePtr,AstNodePtr>& def)
25  { add_data( "unknown", def); }
26  void finalize() { BitVectorReprBase<std::string, std::pair<AstNodePtr, AstNodePtr> >::finalize(); }
27  iterator begin() const
28  { return BitVectorReprBase<std::string, std::pair<AstNodePtr, AstNodePtr> >::begin();}
29  iterator end() const
30  { return BitVectorReprBase<std::string, std::pair<AstNodePtr, AstNodePtr> >::end();}
31  std::pair<AstNodePtr, AstNodePtr> get_ref ( iterator p) const
32  { return BitVectorReprBase<std::string, std::pair<AstNodePtr, AstNodePtr> >::get_data(p); }
33 
34 
36 };
37 
39 : private BitVectorReprGenerator<std::string, std::pair<AstNodePtr,AstNodePtr> >
40 {
41  Ast2StringMap scopemap;
42  public:
44  : BitVectorReprGenerator<std::string, std::pair<AstNodePtr,AstNodePtr> >(b), scopemap(b.scopemap) {}
46  const std::pair<AstNodePtr,AstNodePtr>& def) const
47  { add_member( gen, "unknown", def); }
48  void add_def( ReachingDefinitions& repr, const std::string& varname, const AstNodePtr& scope,
49  const std::pair<AstNodePtr,AstNodePtr>& def) const;
50 
51 
53  { return get_data_set( "unknown" ); }
55  { return BitVectorReprGenerator<std::string, std::pair<AstNodePtr,AstNodePtr> >::get_empty_set(); }
56  ReachingDefinitions get_def_set( const std::string& varname, const AstNodePtr& scope) const;
57 
59  CollectObject< std::pair<AstNodePtr,AstNodePtr> >& collect) const
60  { BitVectorReprGenerator<std::string, std::pair<AstNodePtr,AstNodePtr> >::collect_member(repr, collect); }
61 
63  { return static_cast<const ReachingDefinitionBase&>
64  (BitVectorReprGenerator<std::string, std::pair<AstNodePtr,AstNodePtr> >::get_base()); }
65 
66 };
67 
69 : public DataFlowNode<ReachingDefinitions>
70 {
72  protected:
73  void finalize(AstInterface& fa, const ReachingDefinitionGenerator& g,
74  FunctionSideEffectInterface* a = 0, const ReachingDefinitions* in=0);
75  public:
77  { return in; }
78  virtual void set_entry_data(const ReachingDefinitions& _in)
79  { in = _in; }
81  { return out; }
82  virtual void apply_transfer_function()
83  {
84  out = in;
85  out &= notkill;
86  out |= gen;
87  }
88  void Dump() const;
89 
90  ReachingDefNode( MultiGraphCreate* c)
95 };
96 
98 : public DataFlowAnalysis <ReachingDefNode, ReachingDefinitions>
99 {
101  FunctionSideEffectInterface* a;
102  AstInterface::AstNodeList pars;
103 
105  { return g->get_empty_set(); }
106  virtual ReachingDefinitions
108  {
109  ReachingDefinitions result = d1;
110  result |= d2;
111  return result;
112  }
113  virtual void FinalizeCFG( AstInterface& fa);
114  public:
117  {
118  if (g != 0)
119  delete g;
120  }
121  void operator() ( AstInterface& fa, const AstNodePtr& h,
122  FunctionSideEffectInterface* anal = 0);
123  void collect_ast( const ReachingDefinitions& repr,
124  CollectObject< std::pair<AstNodePtr, AstNodePtr> >& collect);
125 
127  { return g; }
128 };
129 
130 
131 #endif