summaryrefslogtreecommitdiff
path: root/TAO_IDL/be_include/be_visitor_context.h
blob: 1b0240d38dfd19d2c25de2bb1161d8b45fae4f45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

/* -*- C++ -*- */
//=============================================================================
/**
 *  @file    be_visitor_context.h
 *
 *  $Id$
 *
 *  This class serves to provide all the necessary context information to the
 *  visitor as it generates code. This may include the scope inside which the
 *  code is generated, the output file that is being used, and others. This
 *  context information will be passed to the abstract/concrete visitor
 *  factory which in turn will use it to construct the right visitor.
 *
 *
 *  @author Aniruddha Gokhale
 */
//=============================================================================

#ifndef TAO_BE_VISITOR_CONTEXT_H
#define TAO_BE_VISITOR_CONTEXT_H

#include "ast_visitor_context.h"

#include "fe_utils.h"

#include "be_codegen.h"

class TAO_OutStream;
class be_decl;
class be_interface;
class be_typedef;
class be_attribute;
class be_scope;

// When interface is defined as macro redefine it as aceinterface
#if defined (interface)
# define aceinterface interface
# undef interface
#endif /* interface */

class be_visitor_context : public ast_visitor_context
{
public:
  /// default constructor
  be_visitor_context (void);

  /// default constructor
  be_visitor_context (const be_visitor_context &ctx);

  /// destructor
  ~be_visitor_context (void);

  /// assignment operator
  be_visitor_context &operator= (const be_visitor_context &ctx);

  // =helpers

  /// reset the context
  void reset (void);

  /// set the output stream
  void stream (TAO_OutStream *os);

  /// get the stream
  TAO_OutStream *stream (void);

  /// set the scope
  void scope (be_scope *scope);

  /// get the scope in which code will be generated
  be_scope *scope (void);

  /// current node being visited
  void node (be_decl *node);

  /// node being visited
  be_decl *node (void);

  /// code generation state
  void state (TAO_CodeGen::CG_STATE);

  /// return the code generation state
  TAO_CodeGen::CG_STATE state (void);

  /// code generation state
  void sub_state (TAO_CodeGen::CG_SUB_STATE);

  /// return the code generation state
  TAO_CodeGen::CG_SUB_STATE sub_state (void);

  /// set the alias node (if any)
  void alias (be_typedef *node);

  /// return the aliased node (if any)
  be_typedef *alias (void);

  /// set the typedef node (if any)
  void tdef (be_typedef *node);

  /// return the typedef node (if any)
  be_typedef *tdef (void);

  /// set the attribute node if any
  void attribute (be_attribute *attr);

  /// get the attribute node
  be_attribute *attribute (void);

  /// is it the special ctor for exceptions?
  void exception (bool);

  /// is it the special ctor for exceptions?
  bool exception (void);

  /// scope supoorts generation of comma after each element
  void comma (bool);

  /// are we supposed to generate a comma?
  bool comma (void);

  /**
   * In some cases we need to generate the objects of one interface as
   * members of a derived visitor (the TIE classes are a good
   * example). This field is use to hold the interface where we are
   * *generating* code, as opposed to the interfaces where the methods
   * or structures are defined.
   */
  be_interface *interface (void) const;
  void interface (be_interface *);

  /// Accessor for the member.
  ACE_CString &port_prefix (void);

  /// return the export macro currently in force
  const char *export_macro (void) const;

  /// if anyop export macro is empty, check stub.
  const char *non_null_export_macro (void) const;

private:
  /// code generation state
  TAO_CodeGen::CG_STATE state_;

  /// code generation state
  TAO_CodeGen::CG_SUB_STATE sub_state_;

  /// current output stream
  TAO_OutStream *os_;

  /// current scope in which code is generated
  be_scope *scope_;

  /// current node
  be_decl *node_;

  /// aliased node used as a scoped name to define IDL types.
  be_typedef *alias_;

  /// typedef node
  be_typedef *tdef_;

  /// attribute node stored here while generating its code
  be_attribute *attr_;

  /// is it the special ctor for exceptions?
  bool exception_;

  /// whether scope should generate a comma after every element
  bool comma_;

  /// See the method declaration above.
  be_interface *interface_;

  /// Used in enough visitors to put it here.
  ACE_CString port_prefix_;
};

#if defined (interface)
# define interface aceinterface
#endif /* interface */

#endif /* BE_VISITOR_CONTEXT_H */