Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_constant / constant_ch.cpp
blobd8d3d370aa2cd62d6ca84602aeebeca581242423
2 //=============================================================================
3 /**
4 * @file constant_ch.cpp
6 * Visitor generating code for the Constant node in the client header.
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "constant.h"
14 be_visitor_constant_ch::be_visitor_constant_ch (be_visitor_context *ctx)
15 : be_visitor_decl (ctx)
19 be_visitor_constant_ch::~be_visitor_constant_ch ()
23 // Visit the Constant node and its scope.
24 int
25 be_visitor_constant_ch::visit_constant (be_constant *node)
27 if (node->cli_hdr_gen () || node->imported ())
29 return 0;
32 TAO_OutStream *os = this->ctx_->stream ();
34 TAO_INSERT_COMMENT (os);
36 // If we are defined in the outermost scope, then the value is assigned
37 // to us here itself, else it will be in the *.cpp file.
39 AST_Decl::NodeType nt = AST_Decl::NT_pre_defined;
40 AST_Decl *tdef = node->constant_value ()->get_tdef ();
41 AST_Decl::NodeType bnt = AST_Decl::NT_pre_defined;
42 AST_Expression::ExprType etype = node->et ();
43 AST_Decl::NodeType snt = node->defined_in ()->scope_node_type ();
45 if (tdef != nullptr)
47 nt = tdef->node_type ();
48 be_typedef *td = dynamic_cast<be_typedef*> (tdef);
49 bnt = td->base_node_type ();
52 *os << be_nl_2;
54 if (! node->is_nested ())
56 *os << "const ";
58 if (etype == AST_Expression::EV_enum)
60 *os << node->enum_full_name ();
62 else if (nt == AST_Decl::NT_typedef)
64 *os << tdef->name ();
66 else
68 *os << exprtype_to_cpp_corba_type (node->et ());
71 *os << " " << node->local_name ();
73 // We are nested inside an interface or a valuetype.
74 else
76 if (snt != AST_Decl::NT_module)
78 *os << "static ";
80 else if (!be_global->gen_inline_constants ())
82 *os << "extern " << be_global->stub_export_macro () << " ";
85 *os << "const ";
87 if (etype == AST_Expression::EV_enum)
89 *os << node->enum_full_name ();
91 else if (nt == AST_Decl::NT_typedef)
93 if (bnt == AST_Decl::NT_string || bnt == AST_Decl::NT_wstring)
95 *os << exprtype_to_cpp_corba_type (node->et ());
97 else
99 *os << tdef->name ();
102 else
104 *os << exprtype_to_cpp_corba_type (node->et ());
107 *os << " " << node->local_name ();
110 // If this is true, can't generate inline constants.
111 bool const forbidden_in_class = (snt != AST_Decl::NT_root
112 && snt != AST_Decl::NT_module
113 && (etype == AST_Expression::EV_string
114 || etype == AST_Expression::EV_wstring
115 || etype == AST_Expression::EV_float
116 || etype == AST_Expression::EV_double
117 || etype == AST_Expression::EV_longdouble));
119 if (!node->is_nested ()
120 || (be_global->gen_inline_constants () && !forbidden_in_class))
122 *os << " = " << node->constant_value ();
125 *os << ";";
127 node->cli_hdr_gen (true);
128 return 0;