Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_enum.cpp
blob520c315ef7d05985c16b2617573bb69fbb5362ff
2 //=============================================================================
3 /**
4 * @file be_enum.cpp
6 * Extension of class AST_Enum that provides additional means for C++
7 * mapping.
9 * @author Copyright 1994-1995 by Sun Microsystems
10 * @author Inc. and Aniruddha Gokhale
12 //=============================================================================
14 #include "be_enum.h"
15 #include "be_visitor.h"
16 #include "be_helper.h"
18 #include "global_extern.h"
20 be_enum::be_enum (UTL_ScopedName *n,
21 bool local,
22 bool abstract)
23 : COMMON_Base (local,
24 abstract),
25 AST_Decl (AST_Decl::NT_enum,
26 n),
27 AST_Type (AST_Decl::NT_enum,
28 n),
29 AST_ConcreteType (AST_Decl::NT_enum,
30 n),
31 UTL_Scope (AST_Decl::NT_enum),
32 AST_Enum (n,
33 local,
34 abstract),
35 be_scope (AST_Decl::NT_enum),
36 be_decl (AST_Decl::NT_enum,
37 n),
38 be_type (AST_Decl::NT_enum,
41 if (!this->imported ())
43 idl_global->enum_seen_ = true;
44 idl_global->fixed_size_decl_seen_ = true;
48 void
49 be_enum::gen_ostream_operator (TAO_OutStream *os,
50 bool /* use_underscore */)
52 *os << be_nl
53 << "std::ostream& operator<< (std::ostream &strm, const "
54 << this->name () << " _tao_enumerator)" << be_nl
55 << "{" << be_idt_nl
56 << "switch (_tao_enumerator)" << be_idt_nl
57 << "{" << be_idt_nl;
59 // The enum's type name itself is not part of the scope of the
60 // enum values. If the enum is defined at global scope, this will
61 // produce an empty string when streamed to the output file.
62 UTL_ScopedName *s = ScopeAsDecl (this->defined_in ())->name ();
64 for (UTL_ScopeActiveIterator i (this, IK_decls); !i.is_done (); i.next ())
66 Identifier *id = i.item ()->local_name ();
68 *os << "case " << s << "::" << id
69 << ": return strm << \"" << s << "::" << id
70 << "\";" << be_nl;
73 *os << "default: return strm;" << be_uidt_nl
74 << "}" << be_uidt << be_uidt_nl
75 << "}" << be_nl;
78 void
79 be_enum::destroy (void)
81 // Call the destroy methods of our base classes.
82 // No need to call be_scope::destroy(). It has no
83 // allocated members, and AST_Enum::destroy() will
84 // call UTL_Scope::destroy().
85 this->be_type::destroy ();
86 this->be_scope::destroy ();
87 this->AST_Enum::destroy ();
90 int
91 be_enum::accept (be_visitor *visitor)
93 return visitor->visit_enum (this);
98 IMPL_NARROW_FROM_DECL (be_enum)
99 IMPL_NARROW_FROM_SCOPE (be_enum)