Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_template_export.cpp
blobb43b998f21832d3c931f900d319f4dc262ed386b
1 //=============================================================================
2 /**
3 * @file be_visitor_template_export.cpp
5 * This visitor generates template instantiations with export macro
7 * @author Jeff Parsons <j.parsons@vanderbilt.edu>
8 */
9 //=============================================================================
11 #include "be_visitor_template_export.h"
12 #include "be_visitor_context.h"
13 #include "be_root.h"
14 #include "be_module.h"
15 #include "be_typedef.h"
16 #include "be_sequence.h"
17 #include "be_extern.h"
18 #include "be_helper.h"
19 #include "be_predefined_type.h"
20 #include "ace/Log_Msg.h"
22 be_visitor_template_export::be_visitor_template_export (
23 be_visitor_context *ctx)
24 : be_visitor_scope (ctx)
28 be_visitor_template_export::~be_visitor_template_export (void)
32 int
33 be_visitor_template_export::visit_root (be_root *node)
35 TAO_OutStream *os = this->ctx_->stream ();
37 TAO_INSERT_COMMENT (os);
39 *os << "#if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT";
41 if (this->visit_scope (node) == -1)
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "be_visitor_template_export::"
45 "visit_root - visit scope failed\n"),
46 -1);
49 *os << be_nl << "#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */";
51 return 0;
54 int
55 be_visitor_template_export::visit_module (be_module *node)
57 if (this->visit_scope (node) == -1)
59 ACE_ERROR_RETURN ((LM_ERROR,
60 "be_visitor_template_export::"
61 "visit_module - visit scope failed\n"),
62 -1);
65 return 0;
68 int
69 be_visitor_template_export::visit_sequence (be_sequence *node)
71 TAO_OutStream *os = this->ctx_->stream ();
73 be_type *bt = dynamic_cast<be_type*> (node->base_type ());
75 // TAO provides extensions for octet sequences, first find out if
76 // the base type is an octet (or an alias for octet).
77 be_predefined_type *predef = 0;
79 if (bt->base_node_type () == AST_Type::NT_pre_defined)
81 be_typedef* alias =
82 dynamic_cast<be_typedef*> (bt);
84 if (alias == 0)
86 predef = dynamic_cast<be_predefined_type*> (bt);
88 else
90 predef =
91 dynamic_cast<be_predefined_type*> (
92 alias->primitive_base_type ()
97 // When it is a sequence add a special guard
98 if (predef != 0 && predef->pt () == AST_PredefinedType::PT_octet
99 && node->unbounded ())
101 *os << "\n#if (TAO_NO_COPY_OCTET_SEQUENCES == 0)";
104 *os << be_idt << be_nl
105 << "template class " << be_global->stub_export_macro ()
106 << " ";
108 if (node->gen_base_class_name (os,
110 this->ctx_->scope ()->decl ()) == -1)
112 ACE_ERROR_RETURN ((LM_ERROR,
113 "(%N:%l) be_visitor_template_export::"
114 "visit_sequence - "
115 "Base class name generation failed\n"),
116 -1);
119 *os << ";" << be_uidt;
121 if (predef != 0 && predef->pt () == AST_PredefinedType::PT_octet
122 && node->unbounded ())
124 *os << "\n#endif /* TAO_NO_COPY_OCTET_SEQUENCE == 0 */";
127 return 0;
131 be_visitor_template_export::visit_typedef (be_typedef *node)
133 this->ctx_->alias (node);
134 be_type *bt = node->primitive_base_type ();
136 if (bt->accept (this) == -1)
138 ACE_ERROR_RETURN ((LM_ERROR,
139 "be_visitor_template_export::"
140 "visit_typedef - "
141 "visit base type failed\n"),
142 -1);
145 this->ctx_->alias (0);
146 return 0;