Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / TAO_IDL / be_include / be_visitor_context.h
blob4fe7d9013551b48b233fb74e30ca2373eec2097d
2 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file be_visitor_context.h
7 * This class serves to provide all the necessary context information to the
8 * visitor as it generates code. This may include the scope inside which the
9 * code is generated, the output file that is being used, and others. This
10 * context information will be passed to the abstract/concrete visitor
11 * factory which in turn will use it to construct the right visitor.
13 * @author Aniruddha Gokhale
15 //=============================================================================
17 #ifndef TAO_BE_VISITOR_CONTEXT_H
18 #define TAO_BE_VISITOR_CONTEXT_H
20 #include "ast_visitor_context.h"
22 #include "fe_utils.h"
24 #include "be_codegen.h"
26 class TAO_OutStream;
27 class be_decl;
28 class be_interface;
29 class be_typedef;
30 class be_attribute;
31 class be_scope;
33 // When interface is defined as macro redefine it as aceinterface
34 #if defined (interface)
35 # define aceinterface interface
36 # undef interface
37 #endif /* interface */
39 class be_visitor_context : public ast_visitor_context
41 public:
42 /// default constructor
43 be_visitor_context ();
45 /// default constructor
46 be_visitor_context (const be_visitor_context &ctx);
48 /// destructor
49 ~be_visitor_context ();
51 /// assignment operator
52 be_visitor_context &operator= (const be_visitor_context &ctx);
54 // =helpers
56 /// reset the context
57 void reset ();
59 /// set the output stream
60 void stream (TAO_OutStream *os);
62 /// get the stream
63 TAO_OutStream *stream ();
65 /// set the scope
66 void scope (be_scope *scope);
68 /// get the scope in which code will be generated
69 be_scope *scope ();
71 /// current node being visited
72 void node (be_decl *node);
74 /// node being visited
75 be_decl *node ();
77 /// code generation state
78 void state (TAO_CodeGen::CG_STATE);
80 /// return the code generation state
81 TAO_CodeGen::CG_STATE state ();
83 /// code generation state
84 void sub_state (TAO_CodeGen::CG_SUB_STATE);
86 /// return the code generation state
87 TAO_CodeGen::CG_SUB_STATE sub_state ();
89 /// set the alias node (if any)
90 void alias (be_typedef *node);
92 /// return the aliased node (if any)
93 be_typedef *alias ();
95 /// set the typedef node (if any)
96 void tdef (be_typedef *node);
98 /// return the typedef node (if any)
99 be_typedef *tdef ();
101 /// set the attribute node if any
102 void attribute (be_attribute *attr);
104 /// get the attribute node
105 be_attribute *attribute ();
107 /// is it the special ctor for exceptions?
108 void exception (bool);
110 /// is it the special ctor for exceptions?
111 bool exception ();
113 /// scope supoorts generation of comma after each element
114 void comma (bool);
116 /// are we supposed to generate a comma?
117 bool comma ();
120 * In some cases we need to generate the objects of one interface as
121 * members of a derived visitor (the TIE classes are a good
122 * example). This field is use to hold the interface where we are
123 * *generating* code, as opposed to the interfaces where the methods
124 * or structures are defined.
126 be_interface *interface () const;
127 void interface (be_interface *);
129 /// Accessor for the member.
130 ACE_CString &port_prefix ();
132 /// return the export macro currently in force
133 const char *export_macro () const;
135 /// if anyop export macro is empty, check stub.
136 const char *non_null_export_macro () const;
138 private:
139 /// code generation state
140 TAO_CodeGen::CG_STATE state_;
142 /// code generation state
143 TAO_CodeGen::CG_SUB_STATE sub_state_;
145 /// current output stream
146 TAO_OutStream *os_;
148 /// current scope in which code is generated
149 be_scope *scope_;
151 /// current node
152 be_decl *node_;
154 /// aliased node used as a scoped name to define IDL types.
155 be_typedef *alias_;
157 /// typedef node
158 be_typedef *tdef_;
160 /// attribute node stored here while generating its code
161 be_attribute *attr_;
163 /// is it the special ctor for exceptions?
164 bool exception_;
166 /// whether scope should generate a comma after every element
167 bool comma_;
169 /// See the method declaration above.
170 be_interface *interface_;
172 /// Used in enough visitors to put it here.
173 ACE_CString port_prefix_;
176 #if defined (interface)
177 # define interface aceinterface
178 #endif /* interface */
180 #endif /* BE_VISITOR_CONTEXT_H */