summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_constant/constant_cs.cpp
blob: db20c61b3c8bb167bd7c3e1f87797d991e475284 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    constant_cs.cpp
//
// = DESCRIPTION
//    Visitor for code generation of Constant code in the client stubs file.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

ACE_RCSID (be_visitor_constant, 
           constant_cs, 
           "$Id$")


// ********************************************************************
// Visitor implementation for the Constant type
// This one for the client stubs file
// ********************************************************************

be_visitor_constant_cs::be_visitor_constant_cs (be_visitor_context *ctx)
  : be_visitor_decl (ctx)
{
}

be_visitor_constant_cs::~be_visitor_constant_cs (void)
{
}

// visit the Constant_cs node and its scope
int
be_visitor_constant_cs::visit_constant (be_constant *node)
{
  TAO_OutStream *os = this->ctx_->stream ();

  if (!node->cli_stub_gen () 
      && !node->imported ()
      && !be_global->gen_inline_constants ())
    {
      if (node->is_nested ())
        {
          if (node->defined_in ()->scope_node_type () == AST_Decl::NT_module)
            {
              *os << "TAO_NAMESPACE_TYPE (const "
                  << node->exprtype_to_string () << ")" << be_nl;
              be_module *module = 
                be_module::narrow_from_scope (node->defined_in ());

              if (!module || this->gen_nested_namespace_begin (module) == -1)
                {
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "be_visitor_constant_cs::"
                                     "visit_constant - "
                                     "Error parsing nested name\n"),
                                    -1);
                }

              *os << "TAO_NAMESPACE_DEFINE (const ";

              if (node->et () == AST_Expression::EV_enum)
                {
                  *os << node->enum_full_name ();
                }
              else
                {
                  *os << node->exprtype_to_string ();
                }

              *os << ", " << node->local_name () << ", "
                  << node->constant_value () << ")" << be_nl;

              if (this->gen_nested_namespace_end (module) == -1)
                {
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "be_visitor_constant_cs::"
                                     "visit_constant - "
                                     "Error parsing nested name\n"),
                                    -1);
                }
            }
          else
            {
              // For those constants not defined in the outer most scope,
              // they get assigned to their values in the impl file.
              os->indent ();

              *os << "const ";
              
              if (node->et () == AST_Expression::EV_enum)
                {
                  *os << node->enum_full_name ();
                }
              else
                {
                  *os << node->exprtype_to_string ();
                }
               
              *os << " "
                  << node->name () << " = " << node->constant_value ()
                  << ";\n\n";
            }
        }

      node->cli_stub_gen (I_TRUE);
    }

  return 0;
}

// The following needs to be done until the MSVC++ compiler fixes its
// broken handling of namespaces (hopefully forthcoming in version 7).
int
be_visitor_constant_cs::gen_nested_namespace_begin (be_module *node)
{
  TAO_OutStream *os = this->ctx_->stream ();
  char *item_name = 0;

  for (UTL_IdListActiveIterator i (node->name ()); !i.is_done (); i.next ())
    {
      item_name = i.item ()->get_string ();

      if (ACE_OS::strcmp (item_name, "") != 0)
        {
          // leave the outermost root scope.
          *os << "TAO_NAMESPACE_BEGIN (" << item_name
              << ")" << be_nl;
        }
    }

  return 0;
}

// The following needs to be done until the MSVC++ compiler fixes its
// broken handling of namespaces (hopefully forthcoming in version 7).
int
be_visitor_constant_cs::gen_nested_namespace_end (be_module *node)
{
  TAO_OutStream *os = this->ctx_->stream ();

  for (UTL_IdListActiveIterator i (node->name ()); !i.is_done (); i.next ())
    {
      if (ACE_OS::strcmp (i.item ()->get_string (), "") != 0)
        {
          // leave the outermost root scope.
          *os << "TAO_NAMESPACE_END" << be_nl;
        }
    }

  return 0;
}