Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_scope.cpp
blobe67a1afe354714e6e3762ee87ebdca200f16165a
2 //=============================================================================
3 /**
4 * @file be_visitor_scope.cpp
6 * Visitor for the base be_scope node. This serves to maintain the current
7 * state (context) of code generation for the derived visitor.
9 * @author Aniruddha Gokhale
11 //=============================================================================
14 #include "be_argument.h"
15 #include "be_scope.h"
16 #include "be_visitor_scope.h"
17 #include "be_visitor_context.h"
18 #include "ace/Log_Msg.h"
20 // ******************************************************
21 // Generic visitor for a scope.
22 // All elements that give rise to a scope inherit from
23 // this class.
24 // ******************************************************
26 be_visitor_scope::be_visitor_scope (be_visitor_context *ctx)
27 : be_visitor_decl (ctx),
28 elem_number_ (0)
32 be_visitor_scope::~be_visitor_scope ()
36 // Visit the scope and its elements.
37 int
38 be_visitor_scope::visit_scope (be_scope *node)
40 if (node == nullptr)
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "(%N:%l) be_visitor_scope::visit_scope - "
44 "nill node passed\n"),
45 -1);
48 // Proceed if the number of members in our scope is greater than 0.
49 this->elem_number_ = 0;
51 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
52 !si.is_done ();
53 si.next ())
55 AST_Decl *d = si.item ();
57 if (d == nullptr)
59 ACE_ERROR_RETURN ((LM_ERROR,
60 "(%N:%l) be_visitor_scope::visit_scope - "
61 "bad node in this scope\n"),
62 -1);
65 if (d->node_type () == AST_Decl::NT_annotation_decl)
67 continue;
70 be_decl *bd = dynamic_cast<be_decl*> (d);
72 // Set the scope node as "node" in which the code is being
73 // generated so that elements in the node's scope can use it
74 // for code generation.
75 this->ctx_->scope (node);
77 // Set the node to be visited.
78 this->ctx_->node (bd);
79 ++this->elem_number_;
81 // Do any pre processing using the next item info.
82 if (this->pre_process (bd) == -1)
84 ACE_ERROR_RETURN ((LM_ERROR,
85 "(%N:%l) be_visitor_scope::visit_scope - "
86 "pre processing failed\n"),
87 -1);
90 // Send the visitor.
91 if (bd == nullptr || bd->accept (this) == -1)
93 ACE_ERROR_RETURN ((LM_ERROR,
94 "(%N:%l) be_visitor_scope::visit_scope - "
95 "codegen for scope failed\n"),
96 -1);
99 // Do any post processing using this item info.
100 if (this->post_process (bd) == -1)
102 ACE_ERROR_RETURN ((LM_ERROR,
103 "(%N:%l) be_visitor_scope::visit_scope - "
104 "post processing failed\n"),
105 -1);
109 return 0;
113 be_visitor_scope::post_process (be_decl *)
115 return 0;
119 be_visitor_scope::pre_process (be_decl *)
121 return 0;
125 be_visitor_scope::elem_number ()
127 // Return the current element that we are working on.
128 return this->elem_number_;
131 // Find the element that succeeds "elem" in the list.
133 be_visitor_scope::next_elem (be_decl *elem,
134 be_decl *&successor)
136 be_decl *ctx_scope = this->ctx_->scope ()->decl ();
137 be_scope *node = nullptr;
139 if (ctx_scope != nullptr)
141 node = ctx_scope->scope ();
144 if (ctx_scope == nullptr || node == nullptr)
146 ACE_ERROR_RETURN ((LM_ERROR,
147 "(%N:%l) be_visitor_scope::next_elem - "
148 "bad scope\n"),
149 -1);
152 successor = nullptr;
154 // Initialize an iterator to iterate thru our scope.
155 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
156 !si.is_done ();
157 si.next ())
159 be_decl *bd = dynamic_cast<be_decl*> (si.item ());
161 if (bd == nullptr)
163 ACE_ERROR_RETURN ((LM_ERROR,
164 "(%N:%l) be_visitor_scope::next_elem - "
165 "bad node in this scope\n"),
166 -1);
169 if (bd != elem)
171 continue;
174 // Find who is next to me.
175 si.next ();
177 if (si.is_done ())
179 // Nobody left in the list.
180 return 0;
183 successor = dynamic_cast<be_decl*> (si.item ());
185 if (successor == nullptr)
187 ACE_ERROR_RETURN ((LM_ERROR,
188 "(%N:%l) be_visitor_scope::next_elem - "
189 "bad node in this scope\n"),
190 -1);
193 // Nothing else to do.
194 return 0;
197 return 0;
200 bool
201 be_visitor_scope::last_node (be_decl *bd)
203 be_decl *next = nullptr;
204 (void) this->next_elem (bd,
205 next);
207 return (next == nullptr);
210 bool
211 be_visitor_scope::last_inout_or_out_node (be_decl *)
213 // Return true if we are the last inout or out argument.
214 be_decl *next = nullptr;
215 (void) this->next_elem (this->ctx_->node (),
216 next);
218 while (next != nullptr)
220 be_argument *arg = dynamic_cast<be_argument*> (next);
222 if (arg->direction () == AST_Argument::dir_INOUT
223 || arg->direction () == AST_Argument::dir_OUT)
225 // Not the last.
226 return false;
229 be_decl *next_next = nullptr;
230 this->next_elem (next,
231 next_next);
233 next = next_next;
236 // I am the last one.
237 return true;