📄 ast_interface.cpp
字号:
// Add this AST_StructureFwd node (a forward declaration of an IDL
// struct) to this scope.
AST_StructureFwd *
AST_Interface::fe_add_structure_fwd (AST_StructureFwd *t)
{
AST_Decl *d = 0;
// Already defined and cannot be redefined? Or already used?
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
{
AST_Decl::NodeType nt = d->node_type ();
// There used to be another check here ANDed with the one below:
// d->defined_in () == this. But lookup_for_add() calls only
// lookup_by_name_local(), which does not bump up the scope.
if (nt == AST_Decl::NT_struct_fwd)
{
// It's legal to forward declare something more than once,
// but we need only one entry in the scope for lookup.
AST_StructureFwd *fd = AST_StructureFwd::narrow_from_decl (d);
t->destroy ();
delete t;
t = 0;
return fd;
}
else if (nt == AST_Decl::NT_struct)
{
AST_Structure *s = AST_Structure::narrow_from_decl (d);
t->set_full_definition (s);
if (t->added () == 0)
{
t->set_added (1);
this->add_to_scope (t);
// Must check later that all struct and union forward declarations
// are defined in the same IDL file.
AST_record_fwd_decl (t);
}
return t;
}
else
{
if (!can_be_redefined (d))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
d);
return 0;
}
if (this->referenced (d, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
d);
return 0;
}
}
}
// Add it to scope
this->add_to_scope (t);
// Add it to set of locally referenced symbols
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
// Must check later that all struct and union forward declarations
// are defined in the same IDL file.
AST_record_fwd_decl (t);
return t;
}
// Add an AST_Enum node (an enum declaration) to this scope.
AST_Enum *
AST_Interface::fe_add_enum (AST_Enum *t)
{
AST_Decl *d = 0;
// Can't add to interface which was not yet defined.
if (!this->is_defined ())
{
idl_global->err ()->error2 (UTL_Error::EIDL_DECL_NOT_DEFINED,
this,
t);
return 0;
}
// Already defined and cannot be redefined? Or already used?
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
{
if (!can_be_redefined (d))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
d);
return 0;
}
if (this->referenced (d, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
d);
return 0;
}
if (t->has_ancestor (d))
{
idl_global->err ()->redefinition_in_scope (t,
d);
return 0;
}
}
// Add it to scope.
this->add_to_scope (t);
// Add it to set of locally referenced symbols.
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
return t;
}
// Add an AST_Union (a union declaration) to this scope.
AST_Union *
AST_Interface::fe_add_union (AST_Union *t)
{
AST_Decl *predef = 0;
AST_UnionFwd *fwd = 0;
if ((predef = this->lookup_for_add (t, I_FALSE)) != 0)
{
// Treat fwd declared interfaces specially
if (predef->node_type () == AST_Decl::NT_union_fwd)
{
fwd = AST_UnionFwd::narrow_from_decl (predef);
if (fwd == 0)
{
return 0;
}
// Forward declared and not defined yet.
if (!fwd->is_defined ())
{
if (fwd->defined_in () == this)
{
fwd->set_full_definition (t);
}
else
{
idl_global->err ()->error3 (UTL_Error::EIDL_SCOPE_CONFLICT,
fwd,
t,
this);
return 0;
}
}
// OK, not illegal redef of forward declaration. Now check whether.
// it has been referenced already.
else if (this->referenced (predef, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
predef);
return 0;
}
}
else if (!can_be_redefined (predef))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
predef);
return 0;
}
else if (referenced (predef, t->local_name ()) && !t->is_defined ())
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
predef);
return 0;
}
}
// Add it to scope.
this->add_to_scope (t);
// Add it to set of locally referenced symbols.
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
return t;
}
// Add this AST_UnionFwd node (a forward declaration of an IDL
// union) to this scope.
AST_UnionFwd *
AST_Interface::fe_add_union_fwd (AST_UnionFwd *t)
{
AST_Decl *d = 0;
// Already defined and cannot be redefined? Or already used?
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
{
AST_Decl::NodeType nt = d->node_type ();
// There used to be another check here ANDed with the one below:
// d->defined_in () == this. But lookup_for_add() calls only
// lookup_by_name_local(), which does not bump up the scope.
if (nt == AST_Decl::NT_union_fwd)
{
// It's legal to forward declare something more than once,
// but we need only one entry in the scope for lookup.
AST_UnionFwd *fd = AST_UnionFwd::narrow_from_decl (d);
t->destroy ();
delete t;
t = 0;
return fd;
}
else if (nt == AST_Decl::NT_union)
{
AST_Union *s = AST_Union::narrow_from_decl (d);
t->set_full_definition (s);
if (t->added () == 0)
{
t->set_added (1);
this->add_to_scope (t);
// Must check later that all struct and union forward declarations
// are defined in the same IDL file.
AST_record_fwd_decl (t);
}
return t;
}
else
{
if (!can_be_redefined (d))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
d);
return 0;
}
if (this->referenced (d, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
d);
return 0;
}
}
}
// Add it to scope
this->add_to_scope (t);
// Add it to set of locally referenced symbols
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
// Must check later that all struct and union forward declarations
// are defined in the same IDL file.
AST_record_fwd_decl (t);
return t;
}
// Add an AST_EnumVal node (an enumerator) to this scope.
// This is done to conform to the C++ scoping rules which declare
// enumerators in the enclosing scope (in addition to declaring them
// in the enum itself).
AST_EnumVal *
AST_Interface::fe_add_enum_val (AST_EnumVal *t)
{
AST_Decl *d = 0;
// Can't add to interface which was not yet defined.
if (!this->is_defined ())
{
idl_global->err ()->error2 (UTL_Error::EIDL_DECL_NOT_DEFINED,
this,
t);
return 0;
}
// Already defined and cannot be redefined? Or already used?
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
{
if (!can_be_redefined (d))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
d);
return 0;
}
if (this->referenced (d, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
d);
return 0;
}
if (t->has_ancestor (d))
{
idl_global->err ()->redefinition_in_scope (t,
d);
return 0;
}
}
// Add it to scope.
this->add_to_scope (t);
// Add it to set of locally referenced symbols.
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
return t;
}
// Add an AST_Typedef (a typedef) to the current scope.
AST_Typedef *
AST_Interface::fe_add_typedef (AST_Typedef *t)
{
AST_Decl *d = 0;
// Can't add to interface which was not yet defined.
if (!this->is_defined ())
{
idl_global->err ()->error2 (UTL_Error::EIDL_DECL_NOT_DEFINED,
this,
t);
return 0;
}
// Already defined and cannot be redefined? Or already used?
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
{
if (!can_be_redefined (d))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
d);
return 0;
}
if (this->referenced (d, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
d);
return 0;
}
if (t->has_ancestor (d))
{
idl_global->err ()->redefinition_in_scope (t,
d);
return 0;
}
}
// Add it to scope.
this->add_to_scope (t);
// Add it to set of locally referenced symbols.
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
AST_Type *bt = t->base_type ();
UTL_ScopedName *mru = bt->last_referenced_as ();
if (mru != 0)
{
this->add_to_referenced (
bt,
I_FALSE,
mru->first_component ()
);
}
return t;
}
// Add an AST_Native (a native declaration) to this scope.
AST_Native *
AST_Interface::fe_add_native (AST_Native *t)
{
AST_Decl *d = 0;
// Can't add to interface which was not yet defined.
if (!this->is_defined ())
{
idl_global->err ()->error2 (UTL_Error::EIDL_DECL_NOT_DEFINED,
this,
t);
return 0;
}
// Already defined and cannot be redefined? Or already used?
if ((d = this->lookup_for_add (t, I_FALSE)) != 0)
{
if (!can_be_redefined (d))
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
this,
d);
return 0;
}
if (this->referenced (d, t->local_name ()))
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
this,
d);
return 0;
}
if (t->has_ancestor (d))
{
idl_global->err ()->redefinition_in_scope (t,
d);
return 0;
}
}
// Add it to scope.
this->add_to_scope (t);
// Add it to set of locally referenced symbols.
this->add_to_referenced (t,
I_FALSE,
t->local_name ());
return t;
}
// Dump this AST_Interface node to the ostream o.
void
AST_Interface::dump (ACE_OSTREAM_TYPE &o)
{
if (this->is_abstract ())
{
this->dump_i (o, "abstract ");
}
else if (this->is_local ())
{
this->dump_i (o, "local ");
}
this->dump_i (o, "interface ");
this->local_name ()->dump (o);
this->dump_i (o, " ");
if (this->pd_n_inherits > 0)
{
this->dump_i (o, ": ");
for (long i = 0; i < this->pd_n_inherits; ++i)
{
this->pd_inherits[i]->local_name ()->dump (o);
if (i < this->pd_n_inherits - 1)
{
this->dump_i (o, ", ");
}
}
}
this->dump_i (o, " {\n");
UTL_Scope::dump (o);
idl_global->indent ()->skip_to (o);
this->dump_i (o, "}");
}
// This serves for interfaces, valuetypes, components and eventtypes.
void
AST_Interface::fwd_redefinition_helper (AST_Interface *&i,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -