summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_connector/connector_dds_ex_base.cpp
blob: d51ec479dd24cccc5b73066fb30fc3a6b69615c3 (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

//=============================================================================
/**
 *  @file    connector_dds_ex_base.cpp
 *
 *  Base class for visitors generating code for DDS Connectors in
 *  the exec impl.
 *
 *  @author Jeff Parsons
 */
//=============================================================================

#include "connector.h"

#include "ast_structure.h"
#include "ast_typedef.h"
#include "ast_template_module.h"
#include "ast_template_module_ref.h"
#include "ast_native.h"

#include "utl_strlist.h"
#include "utl_string.h"

#include "fe_extern.h"

be_visitor_connector_dds_ex_base::be_visitor_connector_dds_ex_base (
      be_visitor_context *ctx)
  : be_visitor_component_scope (ctx),
    t_inst_ (0),
    t_ref_ (0),
    t_params_ (0),
    base_tname_ (0)
{
}

be_visitor_connector_dds_ex_base::~be_visitor_connector_dds_ex_base (
  void)
{
}

bool
be_visitor_connector_dds_ex_base::begin (be_connector *node)
{
  node_ = node;

  this->process_template_args (node);

  AST_Connector *base = node;

  while (this->t_args_.is_empty () && base != 0)
    {
      this->process_template_args (base);
      base = base->base_connector ();
    }

  if (this->t_args_.is_empty ())
    {
      return false;
    }

  /// Use 'CIAO_' + component's flat name.
  os_ << be_nl_2
      << "namespace CIAO_" << node->flat_name ()
      << "_Impl" << be_nl
      << "{" << be_idt;

  this->base_tname_ = node->local_name ();

  return true;
}

bool
be_visitor_connector_dds_ex_base::is_dds_type (
  be_connector *node, AST_Decl *d)
{
  bool result = false;
  AST_Connector* base = node->base_connector ();

  if (base)
    {
      while (base->base_connector () != 0)
        {
          base = base->base_connector ();
        }

      const char* lname = base->local_name ()->get_string ();

      if (ACE_OS::strcmp (lname, "DDS_Base") == 0)
        {
          AST_Structure *s = dynamic_cast<AST_Structure*> (d);

          if (s == 0)
            {
              AST_Typedef *td = dynamic_cast<AST_Typedef*> (d);

              if (td != 0)
                {
                  s = dynamic_cast<AST_Structure*> (td->primitive_base_type ());
                }
            }

          if (s)
            {
              result = true;
            }
        }
    }

  return result;
}

void
be_visitor_connector_dds_ex_base::process_template_args (
  AST_Connector *node)
{
  AST_Module *m =
    dynamic_cast<AST_Module*> (node->defined_in ());

  /// If this is non-zero, we use this to limit our template
  /// args list to those used in the alias. If it is zero, we
  /// just use the complete template arg list in the
  /// instantiation.
  this->t_ref_ = m->from_ref ();
  this->t_inst_ = m->from_inst ();

  /// We assume the connector comes from the instantiation
  /// of a template module, and the regular module it's
  /// defined in (at some level) will have a reference to it.
  while (this->t_inst_ == 0 && m != 0)
    {
      this->t_inst_ = m->from_inst ();
      m = dynamic_cast<AST_Module*> (m->defined_in ());
    }

  if (this->t_inst_ == 0)
    {
      /// Probably means we're trying the base connector
      /// of DDS_State or DDS_Event, in which case we
      /// return so the caller can try again with the
      /// derived connector, which will succeed in
      /// finding the template module instantiation and
      /// its associated template arguments.
      return;
    }

  /// We need to fetch and store these so we can match them
  /// to the corresponding args and determine whether a
  /// corresponding boolean template arg (indicating FIXED
  /// size type) should be inserted into the
  /// connector base class template arg list.
  this->t_params_ = this->t_inst_->ref ()->template_params ();

  this->match_template_args ();

  /// We depend on the DDS datatype being the first template
  /// argument for now, this may change.
  AST_Decl **datatype = 0;
  int const status = this->t_args_.get (datatype, 0UL);

  if (status != 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("be_visitor_connector_dds_ex_base::")
                  ACE_TEXT ("process_template_args - ")
                  ACE_TEXT ("template arg not found\n ")));

      return;
    }

  this->dds_traits_name_ = (*datatype)->flat_name ();
  this->dds_traits_name_ += "_DDS_Traits";
}

void
be_visitor_connector_dds_ex_base::match_template_args (void)
{
  /// If the connector was declared in an aliased templated
  /// module, we want to populate our template args list with
  /// only the args referenced in the alias (see FOR loop
  /// below). Otherwise, we just copy the containing template
  /// module instantiation's arg list.
  if (this->t_ref_ == 0)
    {
      this->t_args_ = *this->t_inst_->template_args ();
      return;
    }

  for (UTL_StrlistActiveIterator i (this->t_ref_->param_refs ());
       ! i.is_done ();
       i.next ())
    {
      const char *ref_name = i.item ()->get_string ();
      size_t slot = 0;

      for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR ci (
             *this->t_inst_->ref ()->template_params ());
           ! ci.done ();
           ci.advance (), ++slot)
        {
          FE_Utils::T_Param_Info *t_param = 0;
          ci.next (t_param);

          if (t_param->name_ == ref_name)
            {
              AST_Decl **d = 0;
              this->t_inst_->template_args ()->get (d, slot);
              this->t_args_.enqueue_tail (*d);
              break;
            }
        }
    }
}