summaryrefslogtreecommitdiff
path: root/CIAO/CCF/CCF/IDL2/SemanticAction/Impl/TypeId.cpp
blob: 816d83f6d12f6178c6b3c9c35027dc2a3c47d5ef (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
// file      : CCF/IDL2/SemanticAction/Impl/TypeId.cpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#include "CCF/IDL2/SemanticAction/Impl/TypeId.hpp"

#include "CCF/IDL2/SemanticGraph/TypeId.hpp"

// These inclusions are needed to ensure that typeprefix is applied to a
// suitable declaration.

#include "CCF/IDL2/SemanticGraph/Module.hpp"
#include "CCF/IDL2/SemanticGraph/Interface.hpp"
#include "CCF/IDL2/SemanticGraph/ValueType.hpp"

#include <iostream>

using std::cerr;
using std::endl;

namespace CCF
{
  namespace IDL2
  {
    namespace SemanticAction
    {
      namespace Impl
      {
        using namespace SemanticGraph;

        // TypeId
        //
        //
        TypeId::
        TypeId (Context& c)
            : ctx (c)
        {
        }

        void TypeId::
        begin (IdentifierPtr const& d, StringLiteralPtr const& id)
        {
          if (ctx.trace ())
            cerr << "typeid " << d << " " << id << endl;

          Name name (d->lexeme ());
          SemanticGraph::StringLiteral tid (id->value ());

          try
          {
            ScopedName from (ctx.scope ().scoped_name ());
            Nameables nodes (resolve (ctx.tu (), from, name));

            ScopedName full ((**(nodes.begin ())).scoped_name ());

            SemanticGraph::TypeId& ti (
              ctx.tu ().new_node<SemanticGraph::TypeId> (
                ctx.file (), d->line (), full, tid));

            ctx.tu ().new_edge<Defines> (ctx.scope (), ti, "typeid");
          }
          catch (NotFound const&)
          {
            cerr << ctx.file () << ":" << d->line () << ": error: "
                 << "invalid typeid declaration" << endl;

            cerr << ctx.file () << ":" << d->line () << ": error: "
                 << "no declaration with name \'"
                 << name << "\' visible from scope \'"
                 << ctx.scope ().scoped_name () << "\'" << endl;
          }
        }

        void TypeId::
        end ()
        {
          if (ctx.trace ()) cerr << "end" << endl;
        }


        // TypePrefix
        //
        //
        TypePrefix::
        TypePrefix (Context& c)
            : ctx (c)
        {
        }

        void TypePrefix::
        begin (IdentifierPtr const& d, StringLiteralPtr const& prefix)
        {
          if (ctx.trace ()) cerr << "typeprefix " << d << " " << prefix
                                 << endl;

          Name name (d->lexeme ());
          SemanticGraph::StringLiteral tprefix (prefix->value ());

          try
          {
            ScopedName from (ctx.scope ().scoped_name ());
            Nameables nodes (resolve (ctx.tu (), from, name));

            Nameable& node (**(nodes.begin ()));

            dynamic_cast<SemanticGraph::Scope&> (node);

            ScopedName full (node.scoped_name ());

            SemanticGraph::TypePrefix& tp (
              ctx.tu ().new_node<SemanticGraph::TypePrefix> (
                ctx.file (), d->line (), full, tprefix));

            ctx.tu ().new_edge<Defines> (ctx.scope (), tp, "typeprefix");
          }
          catch (NotFound const&)
          {
            cerr << ctx.file () << ":" << d->line () << ": error: "
                 << "invalid typeprefix declaration" << endl;

            cerr << ctx.file () << ":" << d->line () << ": error: "
                 << "no declaration with name \'"
                 << name << "\' visible from scope \'"
                 << ctx.scope ().scoped_name () << "\'" << endl;
          }
          catch (std::bad_cast const&)
          {
            cerr << ctx.file () << ":" << d->line () << ": error: "
                 << "invalid typeprefix declaration" << endl;

            cerr << ctx.file () << ":" << d->line () << ": error: "
                 << "no suitable declaration with name \'"
                 << name << "\' visible from scope \'"
                 << ctx.scope ().scoped_name () << "\'" << endl;
          }
        }

        void TypePrefix::
        end ()
        {
          if (ctx.trace ()) cerr << "end" << endl;
        }
      }
    }
  }
}