Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_annotation_appl.cpp
blob7ea25ceffe4092ef71f2be2b807799356f3fa7ae
1 #include "ast_annotation_appl.h"
2 #include "ast_annotation_member.h"
4 AST_Annotation_Appl::Param::Param ()
5 : id (nullptr),
6 expr (nullptr),
7 used (false)
11 AST_Annotation_Appl::Param::~Param ()
13 if (id)
15 id->destroy ();
17 delete id;
18 if (expr)
20 expr->destroy ();
22 delete expr;
25 void
26 AST_Annotation_Appl::delete_params (AST_Annotation_Appl::Params* params)
28 if (params)
30 Params::ITERATOR iter (*params);
31 while (!iter.done ())
33 Param **i = nullptr;
34 iter.next (i);
35 delete *i;
36 iter.advance ();
38 delete params;
42 AST_Decl::NodeType const AST_Annotation_Appl::NT = AST_Decl::NT_annotation_appl;
44 AST_Annotation_Appl::AST_Annotation_Appl (
45 UTL_ScopedName *name, AST_Annotation_Appl::Params *params)
46 : AST_Decl (NT, name),
47 AST_Type (NT, name),
48 AST_ConcreteType (NT, name),
49 UTL_Scope (NT),
50 AST_Structure (name, false, false),
51 AST_Annotation_Decl (name),
52 original_name_ (name->get_string_copy ()),
53 params_ (params),
54 annotation_decl_ (nullptr)
58 AST_Annotation_Appl::~AST_Annotation_Appl ()
60 delete [] original_name_;
61 delete_params (params_);
62 AST_Structure::destroy ();
65 void AST_Annotation_Appl::dump (ACE_OSTREAM_TYPE &o)
67 dump_i (o, original_name_);
68 if (params_)
70 dump_i (o, "(");
71 Params::ITERATOR iter (*params_);
72 while (!iter.done ())
74 Param **i = nullptr;
75 iter.next (i);
76 if ((*i)->id)
78 (*i)->id->dump (o);
79 dump_i (o, " = ");
81 (*i)->expr->dump (o);
82 iter.advance ();
83 if (!iter.done ())
85 dump_i (o, ", ");
88 dump_i (o, ")");
92 int AST_Annotation_Appl::ast_accept (ast_visitor *)
94 return 0;
97 void AST_Annotation_Appl::destroy ()
101 const char *AST_Annotation_Appl::original_name () const
103 return original_name_;
106 bool
107 AST_Annotation_Appl::apply_from (AST_Annotation_Decl *decl)
109 // Apply Each Member From the Annotation Declaration
110 for (UTL_ScopeActiveIterator si (
111 decl,
112 UTL_Scope::IK_decls);
113 !si.is_done ();
114 si.next ())
116 AST_Annotation_Member *member =
117 dynamic_cast<AST_Annotation_Member*> (si.item ());
118 if (member)
120 AST_Annotation_Member *new_member = fe_add_annotation_member (
121 new AST_Annotation_Member (member->name (), member));
124 * Check to see if we have a parameter that matches this. If not,
125 * make sure that the member has a default value.
127 Param *param = find_param (member->local_name ()->get_string ());
128 if (param)
130 new_member->value (new AST_Expression (param->expr, member->expr_type()));
131 if (new_member->invalid_value ())
133 idl_global->err ()->invalid_annotation_param_type (
134 this, member, param->expr);
135 return false;
137 param->used = true;
139 else if (!new_member->value ())
141 idl_global->err ()->annotation_param_missing_error (
142 this, member);
143 return false;
148 // Make sure all the parameters were used
149 if (params_)
151 for (Param::Iterator it (*params_);
152 !it.done (); it.advance ())
154 Param **param = nullptr;
155 it.next (param);
156 if ((*param) && !(*param)->used)
158 idl_global->err ()->invalid_annotation_param_error (
159 this, decl, (*param)->id);
160 return false;
165 annotation_decl_ = decl;
167 return true;
170 AST_Annotation_Appl::Params *
171 AST_Annotation_Appl::params ()
173 return params_;
176 AST_Annotation_Decl *
177 AST_Annotation_Appl::annotation_decl ()
179 return annotation_decl_;
182 AST_Annotation_Appl::Param *
183 AST_Annotation_Appl::find_param (const char *name)
185 if (params_)
187 // Check for single nameless parameter
188 if (params_->size () == 1)
190 Param *top = nullptr;
191 params_->top (top);
192 if (top && !top->id && top->expr)
194 // Don't reuse it if used
195 return top->used ? nullptr : top;
198 for (Param::Iterator it (*params_);
199 !it.done (); it.advance ())
201 Param **param = nullptr;
202 it.next (param);
203 if ((*param) && (*param)->id && !ACE_OS::strcmp ((*param)->id->get_string (), name))
205 return (*param);
210 return nullptr;