blob: d8d3d370aa2cd62d6ca84602aeebeca581242423 (
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
|
//=============================================================================
/**
* @file constant_ch.cpp
*
* Visitor generating code for the Constant node in the client header.
*
* @author Aniruddha Gokhale
*/
//=============================================================================
#include "constant.h"
be_visitor_constant_ch::be_visitor_constant_ch (be_visitor_context *ctx)
: be_visitor_decl (ctx)
{
}
be_visitor_constant_ch::~be_visitor_constant_ch ()
{
}
// Visit the Constant node and its scope.
int
be_visitor_constant_ch::visit_constant (be_constant *node)
{
if (node->cli_hdr_gen () || node->imported ())
{
return 0;
}
TAO_OutStream *os = this->ctx_->stream ();
TAO_INSERT_COMMENT (os);
// 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.
AST_Decl::NodeType nt = AST_Decl::NT_pre_defined;
AST_Decl *tdef = node->constant_value ()->get_tdef ();
AST_Decl::NodeType bnt = AST_Decl::NT_pre_defined;
AST_Expression::ExprType etype = node->et ();
AST_Decl::NodeType snt = node->defined_in ()->scope_node_type ();
if (tdef != nullptr)
{
nt = tdef->node_type ();
be_typedef *td = dynamic_cast<be_typedef*> (tdef);
bnt = td->base_node_type ();
}
*os << be_nl_2;
if (! node->is_nested ())
{
*os << "const ";
if (etype == AST_Expression::EV_enum)
{
*os << node->enum_full_name ();
}
else if (nt == AST_Decl::NT_typedef)
{
*os << tdef->name ();
}
else
{
*os << exprtype_to_cpp_corba_type (node->et ());
}
*os << " " << node->local_name ();
}
// We are nested inside an interface or a valuetype.
else
{
if (snt != AST_Decl::NT_module)
{
*os << "static ";
}
else if (!be_global->gen_inline_constants ())
{
*os << "extern " << be_global->stub_export_macro () << " ";
}
*os << "const ";
if (etype == AST_Expression::EV_enum)
{
*os << node->enum_full_name ();
}
else if (nt == AST_Decl::NT_typedef)
{
if (bnt == AST_Decl::NT_string || bnt == AST_Decl::NT_wstring)
{
*os << exprtype_to_cpp_corba_type (node->et ());
}
else
{
*os << tdef->name ();
}
}
else
{
*os << exprtype_to_cpp_corba_type (node->et ());
}
*os << " " << node->local_name ();
}
// If this is true, can't generate inline constants.
bool const forbidden_in_class = (snt != AST_Decl::NT_root
&& snt != AST_Decl::NT_module
&& (etype == AST_Expression::EV_string
|| etype == AST_Expression::EV_wstring
|| etype == AST_Expression::EV_float
|| etype == AST_Expression::EV_double
|| etype == AST_Expression::EV_longdouble));
if (!node->is_nested ()
|| (be_global->gen_inline_constants () && !forbidden_in_class))
{
*os << " = " << node->constant_value ();
}
*os << ";";
node->cli_hdr_gen (true);
return 0;
}
|