Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / TAO_IDL / include / utl_scope_T.cpp
blob4a54a47479b94b007b8f48b8f090434b3146f9d8
1 #ifndef TAO_IDL_UTL_SCOPE_T_CPP
2 #define TAO_IDL_UTL_SCOPE_T_CPP
4 #include "utl_scope.h"
6 #include "nr_extern.h"
7 #include "global_extern.h"
9 #include "utl_err.h"
11 #include "ast_interface_fwd.h"
13 template<typename DECL>
14 DECL *
15 UTL_Scope::fe_add_full_intf_decl (DECL *t)
17 if (t->redef_clash ())
19 return 0;
22 AST_Decl *predef = 0;
24 // Already defined?
25 if ((predef = this->lookup_for_add (t)) != 0)
27 // Treat fwd declared interfaces specially
28 if (predef->node_type () == DECL::NT)
30 DECL *fwd = dynamic_cast<DECL *> (predef);
31 if (fwd == 0)
33 return 0;
36 // Forward declared and not defined yet.
37 if (!fwd->is_defined ())
39 if (fwd->defined_in () != this)
41 idl_global->err ()->error3 (UTL_Error::EIDL_SCOPE_CONFLICT,
42 fwd,
44 ScopeAsDecl (this));
46 return 0;
49 // OK, not illegal redef of forward declaration. Now check whether.
50 // it has been referenced already.
51 else if (this->referenced (predef, t->local_name ()))
53 idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
55 ScopeAsDecl (this),
56 predef);
58 return 0;
62 else if (!FE_Utils::can_be_redefined (predef, t))
64 idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
66 ScopeAsDecl (this),
67 predef);
69 return 0;
71 else if (referenced (predef, t->local_name ()) && !t->is_defined ())
73 idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
75 ScopeAsDecl (this),
76 predef);
78 return 0;
80 else if (t->has_ancestor (predef))
82 idl_global->err ()->redefinition_in_scope (t, predef);
84 return 0;
88 // Add it to scope
89 this->add_to_scope (t);
91 // We do this for interfaces, valuetypes and components in
92 // a different place than we do for structs and unions,
93 // since fwd declared structs and unions must be defined in
94 // the same translation unit.
95 AST_InterfaceFwd *fd = t->fwd_decl ();
96 if (0 != fd)
98 fd->set_as_defined ();
99 fd->disown_full_definition (); // This scope assumes ownership
102 // Add it to set of locally referenced symbols
103 this->add_to_referenced (t,
104 false,
105 t->local_name ());
106 return t;
109 template<typename FULL_DECL>
110 typename FULL_DECL::FWD_TYPE *
111 UTL_Scope::fe_add_fwd_intf_decl (typename FULL_DECL::FWD_TYPE *t)
113 AST_Decl *d = 0;
115 // Already defined and cannot be redefined? Or already used?
116 if ((d = this->lookup_for_add (t)) != 0)
118 AST_Decl::NodeType nt = d->node_type ();
120 // There used to be another check here ANDed with the one below:
121 // d->defined_in () == this. But lookup_for_add() calls only
122 // lookup_by_name_local(), which does not bump up the scope,
123 // and look_in_prev_mods() for modules. If look_in_prev_mods()
124 // finds something, the scopes will NOT be the same pointer
125 // value, but the result is what we want.
126 if (nt == FULL_DECL::NT)
128 FULL_DECL *itf = dynamic_cast<FULL_DECL *> (d);
129 if (itf == 0)
131 return 0;
134 // If the lookup found the full_definition member of another
135 // interface_fwd, don't reset this full_definition. Otherwise
136 // reset the member and set is_defined_ on i so it itf won't
137 // get destroyed twice.
138 if (itf->is_defined ())
140 t->set_full_definition (itf);
141 t->set_as_defined ();
145 if (!FE_Utils::can_be_redefined (d, t))
147 idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
149 ScopeAsDecl (this),
151 return 0;
154 // No need to call referenced() for forward declared interafces,
155 // they can be redeclared after referencing.
157 if (t->has_ancestor (d))
159 idl_global->err ()->redefinition_in_scope (t, d);
160 return 0;
164 // Add it to scope
165 this->add_to_scope (t);
167 // Add it to set of locally referenced symbols
168 this->add_to_referenced (t,
169 false,
170 t->local_name ());
172 return t;
175 #endif // TAO_IDL_UTL_SCOPE_T_CPP