summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_util.cpp
blob: 9943bdc4c80bf122923b80e946dfa9f6e3b867db (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
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    be_util.cpp
//
// = DESCRIPTION
//    Static helper methods used by multiple visitors.
//
// = AUTHOR
//    Gary Maxey, Jeff Parsons
//
// ============================================================================

#include "be_util.h"
#include "be_helper.h"
#include "be_module.h"
#include "be_identifier_helper.h"

#include "utl_identifier.h"

#include "ace/OS_NS_string.h"

void
be_util::gen_nested_namespace_begin (TAO_OutStream *os, be_module *node)
{
  char *item_name = 0;

  for (UTL_IdListActiveIterator i (node->name ()); !i.is_done (); i.next ())
    {
      item_name = i.item ()->get_string ();

      if (ACE_OS::strcmp (item_name, "") != 0)
        {
          // Leave the outermost root scope.
          *os << be_nl << "namespace " << item_name << be_nl
              << "{" << be_idt_nl;
        }
    }
}

void
be_util::gen_nested_namespace_end (TAO_OutStream *os, be_module *node)
{
  for (UTL_IdListActiveIterator i (node->name ()); !i.is_done (); i.next ())
    {
      if (ACE_OS::strcmp (i.item ()->get_string (), "") != 0)
        {
          // Leave the outermost root scope.
          *os << be_uidt_nl << "}";
        }
    }

  *os << be_nl << be_nl;
}

void
be_util::gen_nesting_open (TAO_OutStream &os, AST_Decl *node)
{
  os << be_nl;

  for (UTL_IdListActiveIterator i (node->name ()); ! i.is_done () ;)
    {
      UTL_ScopedName tmp (i.item (), 0);
      AST_Decl *scope =
        node->defined_in ()->lookup_by_name (&tmp, true);

      if (scope == 0)
        {
          i.next ();
          continue;
        }

      ACE_CString module_name =
        IdentifierHelper::try_escape (scope->original_local_name ());

      if (module_name == "")
        {
          i.next ();
          continue;
        }

      i.next ();

      if (i.is_done ())
        {
          break;
        }

      os << be_nl
         << "module " << module_name.c_str () << be_nl
         << "{" << be_idt;
    }
}

void
be_util::gen_nesting_close (TAO_OutStream &os, AST_Decl *node)
{
  for (UTL_IdListActiveIterator i (node->name ()); ! i.is_done () ;)
    {
      ACE_CString module_name (i.item ()->get_string ());

      if (module_name == "")
        {
          i.next ();
          continue;
        }

      i.next ();

      if (i.is_done ())
        {
          break;
        }

      os << be_uidt_nl
         << "};";
    }
}