summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_state_array.cpp
blob: 118d3e0f4ee343e41ea98955cc371186a3894d6c (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
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    be_state_array.cpp
//
// = DESCRIPTION
//    state based code generation for arrays.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include	"idl.h"
#include	"idl_extern.h"
#include	"be.h"

// return type for array
be_state_array::be_state_array (void)
{
}

// generate code for array type
int
be_state_array::gen_code (be_type *bt, be_decl *d, be_type *type)
{
  TAO_OutStream *os = 0; // output stream
  TAO_NL  nl;        // end line
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();

  // Macro to avoid "warning: unused parameter" type warning.
  ACE_UNUSED_ARG (nl);

  // get the appropriate stream
  switch (cg->state ())
    {
    case TAO_CodeGen::TAO_ARRAY_DEFN_CH:
    case TAO_CodeGen::TAO_ARRAY_OTHER_CH:
      os = cg->client_header ();
      break;
    case TAO_CodeGen::TAO_ARRAY_DEFN_CI:
      os = cg->client_inline ();
      break;
    }

  if (!type) // not a recursive call
    type = bt;
  else // recursively called thru a typedef. "type" will have the most primitive
       // base class of the typedef
    ACE_ASSERT (bt->node_type () == AST_Decl::NT_typedef);

  // generate code based on type. For every case, first downcast to the
  // appropriate type. If the downcast fails, return error, else proceed. In
  // some cases, the type itself may need code generation, e.g., anonymous
  // struct types.
  switch (type->node_type ())
    {
    case AST_Decl::NT_interface: // type is an obj reference
      {
        *os << bt->name () << "_var ";
      }
      break;
    case AST_Decl::NT_pre_defined: // type is predefined type
      {
        *os << bt->name ();
      }
      break;
    case AST_Decl::NT_string: // type is a string
      {
        *os << "CORBA::String_var ";
      }
      break;
    case AST_Decl::NT_array:
      // type is an array. This is possible only if we
      // are here thru the typedef node
      {
        *os << bt->name () << "_slice *";
      }
      break;
      // these are all anonymous types
    case AST_Decl::NT_enum:     // type is an enum
    case AST_Decl::NT_sequence: // type is a sequence
    case AST_Decl::NT_struct:   // type is a struct
    case AST_Decl::NT_union:    // type is a union
      {
        // based on what state we are in, we may have to generate the definition
        // of the type first
        if (cg->state () == TAO_CodeGen::TAO_ARRAY_DEFN_CH)
          if (bt->gen_client_header () == -1)  // generate the defn
            return -1;

        *os << bt->name ();
      }
      break;
    case AST_Decl::NT_except: // type is an exception
      {
        // XXXASG TODO: is this allowed ???
      }
      break;
    case AST_Decl::NT_typedef: // type is a typedef
      {
        be_type *temp;
        be_typedef *t = be_typedef::narrow_from_decl (bt);

        if (!t)
          return -1;

        temp = t->primitive_base_type ();
        // make a recursive call
        return this->gen_code (t, d, temp);
      } // end of switch
      //break; unreachable statement!
    }
  return 0;
}