2 //=============================================================================
4 * @file constant_ch.cpp
6 * Visitor generating code for the Constant node in the client header.
8 * @author Aniruddha Gokhale
10 //=============================================================================
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.
25 be_visitor_constant_ch::visit_constant (be_constant
*node
)
27 if (node
->cli_hdr_gen () || node
->imported ())
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 ();
47 nt
= tdef
->node_type ();
48 be_typedef
*td
= dynamic_cast<be_typedef
*> (tdef
);
49 bnt
= td
->base_node_type ();
54 if (! node
->is_nested ())
58 if (etype
== AST_Expression::EV_enum
)
60 *os
<< node
->enum_full_name ();
62 else if (nt
== AST_Decl::NT_typedef
)
68 *os
<< exprtype_to_cpp_corba_type (node
->et ());
71 *os
<< " " << node
->local_name ();
73 // We are nested inside an interface or a valuetype.
76 if (snt
!= AST_Decl::NT_module
)
80 else if (!be_global
->gen_inline_constants ())
82 *os
<< "extern " << be_global
->stub_export_macro () << " ";
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 ());
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 ();
127 node
->cli_hdr_gen (true);