summaryrefslogtreecommitdiff
path: root/CIAO/CIDLC/CxxNamePrinter.cpp
blob: 027889791ec241f038b87a39da7ed9176cdd25c8 (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
// file      : CIDLC/CxxNamePrinter.cpp
// author    : Boris Kolpackov <boris@codesynthesis.com>
// cvs-id    : $Id: Collectors.hpp 55138 2004-01-05 07:53:05Z parsons $

#include "CIDLC/CxxNamePrinter.hpp"

#include <ostream>
#include <algorithm>

namespace
{
  // Sorted C++ keywords.
  //
  char* keywords[] = {
    "and",
    "asm",
    "auto",
    "bitand",
    "bitor",
    "bool",
    "break",
    "case",
    "catch",
    "char",
    "class",
    "compl",
    "const",
    "const_cast",
    "continue",
    "default",
    "delete",
    "do",
    "double",
    "dynamic_cast",
    "else",
    "end_eq",
    "enum",
    "explicit",
    "export",
    "extern",
    "false",
    "float",
    "for",
    "friend",
    "goto",
    "if",
    "inline",
    "int",
    "long",
    "mutable",
    "namespace",
    "new",
    "not",
    "not_eq",
    "operator",
    "or",
    "or_eq",
    "private",
    "protected",
    "public",
    "register",
    "reinterpret_cast",
    "return",
    "short",
    "signed",
    "sizeof",
    "static",
    "static_cast",
    "struct",
    "switch",
    "template",
    "this",
    "throw",
    "true",
    "try",
    "typedef",
    "typeid",
    "typename",
    "union",
    "unsigned",
    "using",
    "virtual",
    "void",
    "volatile",
    "wchar_t",
    "while",
    "xor",
    "xor_eq"
  };
}

void CxxNamePrinter::
print (std::ostream& os, CCF::IDL2::SemanticGraph::SimpleName const& n)
{
  std::size_t const size (sizeof (keywords) / sizeof (char*));
  std::string const& str (n.unescaped_str ());

  if (std::binary_search (keywords, keywords + size, str))
    os << "_cxx_";

  os << str;
}