summaryrefslogtreecommitdiff
path: root/CIAO/CIDLC/Collectors.hpp
blob: e87667579b5749591598416dd48d7545d7136848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// file      : CIDLC/Collectors.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef COLLECTORS_HPP
#define COLLECTORS_HPP

#include <map>

#include "CCF/CIDL/SemanticGraph.hpp"
#include "CCF/CIDL/Traversal.hpp"

class Declarations
{
public:
  bool
  add (CCF::IDL3::SyntaxTree::HomeDefPtr const& h)
  {
    return homes_.insert (h).second;
  }

  bool
  add (CCF::IDL3::SyntaxTree::ComponentDefPtr const& c)
  {
    return components_.insert (c).second;
  }

  bool
  add (CCF::CIDL::SyntaxTree::CompositionPtr const& cs,
       CCF::IDL3::SyntaxTree::ComponentDefPtr const& cn)
  {
    return compositions_.insert (make_pair(cs, cn)).second;
  }

  bool
  add (CCF::IDL3::SyntaxTree::UnconstrainedInterfaceDeclPtr const& i)
  {
    return interfaces_.insert (i).second
      && interface_names_.insert (i->name ()).second;
  }

public:
  bool
  find (CCF::IDL3::SyntaxTree::HomeDefPtr const& h) const
  {
    return homes_.find (h) != homes_.end ();
  }

  bool
  find (CCF::IDL3::SyntaxTree::ComponentDefPtr const& c) const
  {
    return components_.find (c) != components_.end ();
  }

  bool
  find (CCF::CIDL::SyntaxTree::CompositionPtr const& c) const
  {
    return compositions_.find (c) != compositions_.end ();
  }

  bool
  find (CCF::IDL2::SyntaxTree::UnconstrainedInterfaceDefPtr const& i) const
  {
    return interface_names_.find (i->name ()) != interface_names_.end ();
  }

public:
  CCF::IDL3::SyntaxTree::ComponentDefPtr
  resolve (CCF::CIDL::SyntaxTree::CompositionPtr const& c) const
  {
    CompositionMap::const_iterator i = compositions_.find (c);
    if (i != compositions_.end ())
    {
      return i->second;
    }
    else
    {
      return CCF::IDL3::SyntaxTree::ComponentDefPtr (0);
    }
  }

public:
  bool
  contains_suborder (CCF::CIDL::SyntaxTree::Order const& o) const
  {
    for (CCF::IDL2::SyntaxTree::UnconstrainedInterfaceDeclSet::const_iterator i =
             interfaces_.begin ();
         i != interfaces_.end ();
         i++)
    {
      if (o.suborder ((*i)->order ())) return true;
    }

    for (CCF::IDL3::SyntaxTree::ComponentDefSet::const_iterator i = components_.begin ();
         i != components_.end ();
         i++)
    {
      if (o.suborder ((*i)->order ())) return true;
    }

    for (CCF::IDL3::SyntaxTree::HomeDefSet::const_iterator i = homes_.begin ();
         i != homes_.end ();
         i++)
    {
      if (o.suborder ((*i)->order ())) return true;
    }

    for (CompositionMap::const_iterator i = compositions_.begin ();
         i != compositions_.end ();
         i++)
    {
      if (o.suborder (i->first->order ())) return true;
    }

    return false;
  }

private:
  typedef
  std::map <CCF::CIDL::SyntaxTree::CompositionPtr,
            CCF::IDL3::SyntaxTree::ComponentDefPtr,
            CCF::CIDL::SyntaxTree::CompositionOrderComparator> CompositionMap;

  CCF::IDL3::SyntaxTree::HomeDefSet homes_;
  CCF::IDL3::SyntaxTree::ComponentDefSet components_;
  CompositionMap compositions_;
  CCF::IDL2::SyntaxTree::UnconstrainedInterfaceDeclSet interfaces_;
  CCF::IDL2::SyntaxTree::ScopedNameSet interface_names_;
};


//
//
//
class HomeCollector : public CCF::IDL3::Traversal::HomeDef
{
public:
  HomeCollector (Declarations& declarations)
    : declarations_ (declarations)
  {
  }

  virtual void
  traverse (CCF::CIDL::SyntaxTree::HomeDefPtr const& h)
  {
    CCF::CIDL::SyntaxTree::ScopedName n (h->name ());

    CCF::CIDL::SyntaxTree::ScopedName main (n.scope (), "CCM_" + n.simple ());
    CCF::CIDL::SyntaxTree::ScopedName expl (n.scope (), "CCM_" + n.simple () + "Explicit");
    CCF::CIDL::SyntaxTree::ScopedName impl (n.scope (), "CCM_" + n.simple () + "Implicit");

    // Check if mapping has already been provided.
    if (h->table ().exist (main) ||
        h->table ().exist (expl) ||
        h->table ().exist (impl)) return;

    if (declarations_.add (h))
    {
      // Note that I don't go after components that inherited home manages
      // because it will be handled by component inheritance tree.
      //
      if (h->inherits ()) traverse (h->inherits ().resolve ());
    }
  }

private:
  Declarations& declarations_;
};

//
//
//
class ComponentCollector : public CCF::IDL3::Traversal::ComponentDef
{
public:
  ComponentCollector (Declarations& declarations)
    : declarations_ (declarations)
  {
  }

  virtual void
  pre (CCF::IDL3::SyntaxTree::ComponentDefPtr const& c)
  {
    CCF::CIDL::SyntaxTree::ScopedName n (c->name ());

    CCF::CIDL::SyntaxTree::ScopedName monolith (n.scope (), "CCM_" + n.simple ());
    CCF::CIDL::SyntaxTree::ScopedName context (n.scope (), "CCM_" + n.simple () + "_Context");

    // Check if mapping has already been provided.
    if (c->table ().exist (context) ||
        c->table ().exist (monolith)) return;

    if(declarations_.add (c))
    {
      if (c->inherits ())
      {
        traverse (c->inherits ().resolve ());
      }
    }
  }

private:
  Declarations& declarations_;
};

//
//
//
class ProvidedInterfaceCollector : public CCF::IDL3::Traversal::ProvidesDecl
{
public:
  ProvidedInterfaceCollector (Declarations& declarations)
    : declarations_ (declarations)
  {
  }

  virtual void
  traverse (CCF::IDL3::SyntaxTree::ProvidesDeclPtr const& i)
  {
    //@@ CCM issue: interface should be defined at this point
    CCF::IDL2::SyntaxTree::UnconstrainedInterfaceDeclPtr def
        (i->type ()
         ->dynamic_type<CCF::CIDL::SyntaxTree::UnconstrainedInterfaceDecl> ());

    if (def != 0)
    {
      // Add to the list if it's not already there.
      declarations_.add (def);
    }
  }

private:
  Declarations& declarations_;
};


//
//
//
class HomeExecutorCollector : public CCF::CIDL::Traversal::HomeExecutor
{
public:
  HomeExecutorCollector (Declarations& declarations,
                         CCF::CIDL::Traversal::Dispatcher* home_collector,
                         CCF::CIDL::Traversal::Dispatcher* component_collector)
    : declarations_ (declarations),
      home_collector_ (home_collector),
      component_collector_ (component_collector)
  {
  }

  virtual void
  traverse (CCF::CIDL::SyntaxTree::HomeExecutorPtr const& he)
  {
    CCF::CIDL::SyntaxTree::HomeDefPtr home (he->implements ());
    home_collector_->dispatch (home);

    CCF::CIDL::SyntaxTree::ComponentDefPtr component (home->manages ());
    component_collector_->dispatch (component);

    CCF::CIDL::SyntaxTree::CompositionPtr
        composition (he->scope ()->dynamic_type<CCF::CIDL::SyntaxTree::Composition> ());
    declarations_.add (composition, component);
  }

private:
  Declarations& declarations_;

  CCF::CIDL::Traversal::Dispatcher* home_collector_;
  CCF::CIDL::Traversal::Dispatcher* component_collector_;
};

#endif // COLLECTORS_HPP

/*
 * Local Variables:
 * mode: C++
 * c-basic-offset: 2
 * End:
 */