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

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    constant_ch.cpp
//
// = DESCRIPTION
//    Visitor generating code for the Constant node in the client header.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

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


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

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

be_visitor_constant_ch::~be_visitor_constant_ch (void)
{
}

// Visit the Constant node and its scope.
int
be_visitor_constant_ch::visit_constant (be_constant *node)
{
  TAO_OutStream *os = this->ctx_->stream ();

  if (!node->cli_hdr_gen () && !node->imported ())
    {
      // If we are defined in the outermost scope, then the value is assigned
      // to us here itself, else it will be in the *.cpp file.

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

          *os << " const "
              << node->local_name () << " = "
              << node->constant_value ();
        }
      // Is our enclosing scope a module? We need this check because for
      // platforms that support namespaces, the constant must be declared
      // extern.
      else 
        {
          AST_Decl::NodeType nt = node->defined_in ()->scope_node_type ();

          if (node->is_nested () && nt == AST_Decl::NT_module)
            {
              *os << "TAO_NAMESPACE_STORAGE_CLASS ";
            }
          else
            {
              *os << "static ";
            }

          *os << "const ";

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

          *os << " " << node->local_name ();

          if (!node->is_nested ())
            {
              // We were defined at the outermost scope. So we put the value
              // in the header itself.
              *os << " = " << node->constant_value ();
            }
        }

      *os << ";" << be_nl << be_nl;

      node->cli_hdr_gen (I_TRUE);
    }

  return 0;
}