Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_annotation_appl.cpp
blob68786c72f522ffe1c27680d465a9f1ee4eeaae18
1 #include "ast_annotation_appl.h"
2 #include "ast_annotation_member.h"
4 AST_Annotation_Appl::Param::Param ()
5 : id (0),
6 expr (0),
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 = 0;
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_ (0)
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 = 0;
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 IMPL_NARROW_FROM_DECL (AST_Annotation_Appl)
107 IMPL_NARROW_FROM_SCOPE (AST_Annotation_Appl)
109 bool
110 AST_Annotation_Appl::apply_from (AST_Annotation_Decl *decl)
112 // Apply Each Member From the Annotation Declaration
113 for (UTL_ScopeActiveIterator si (
114 decl,
115 UTL_Scope::IK_decls);
116 !si.is_done ();
117 si.next ())
119 AST_Annotation_Member *member =
120 dynamic_cast<AST_Annotation_Member*> (si.item ());
121 if (member)
123 AST_Annotation_Member *new_member = fe_add_annotation_member (
124 new AST_Annotation_Member (member->name (), member));
127 * Check to see if we have a parameter that matches this. If not,
128 * make sure that the member has a default value.
130 Param *param = find_param (member->local_name ()->get_string ());
131 if (param)
133 new_member->value (new AST_Expression (param->expr, member->expr_type()));
134 if (new_member->invalid_value ())
136 idl_global->err ()->invalid_annotation_param_type (
137 this, member, param->expr);
138 return false;
140 param->used = true;
142 else if (!new_member->value ())
144 idl_global->err ()->annotation_param_missing_error (
145 this, member);
146 return false;
151 // Make sure all the parameters were used
152 if (params_)
154 for (Param::Iterator it (*params_);
155 !it.done (); it.advance ())
157 Param **param = 0;
158 it.next (param);
159 if ((*param) && !(*param)->used)
161 idl_global->err ()->invalid_annotation_param_error (
162 this, decl, (*param)->id);
163 return false;
168 annotation_decl_ = decl;
170 return true;
173 AST_Annotation_Appl::Params *
174 AST_Annotation_Appl::params ()
176 return params_;
179 AST_Annotation_Decl *
180 AST_Annotation_Appl::annotation_decl ()
182 return annotation_decl_;
185 AST_Annotation_Appl::Param *
186 AST_Annotation_Appl::find_param (const char *name)
188 if (params_)
190 // Check for single nameless parameter
191 if (params_->size () == 1)
193 Param *top = 0;
194 params_->top (top);
195 if (top && !top->id && top->expr)
197 // Don't reuse it if used
198 return top->used ? 0 : top;
201 for (Param::Iterator it (*params_);
202 !it.done (); it.advance ())
204 Param **param = 0;
205 it.next (param);
206 if ((*param) && (*param)->id && !ACE_OS::strcmp ((*param)->id->get_string (), name))
208 return (*param);
213 return 0;