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

namespace CCF
{
  namespace IDL2
  {
    namespace SemanticAction
    {
      namespace Impl
      {
        template <typename T>
        T& Base::
        resolve (SemanticGraph::ScopedName const& from,
                 SemanticGraph::Name const& name,
                 Flags::Value flags)
          throw (NotFound, NotUnique, WrongType, NotDefined, NotComplete)
        {
          using namespace SemanticGraph;

          try
          {
            Nameables nodes (Impl::resolve (ctx.tu (), from, name));


            if (nodes.size () != 1) throw NotUnique ();

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

            try
            {
              T& t (dynamic_cast<T&> (node));

              if (flags & Flags::defined)
              {
                if (!t.defined ()) throw NotDefined (node.scoped_name ());
              }

              if (flags & Flags::complete)
              {
                SemanticGraph::Type& type (
                  dynamic_cast<SemanticGraph::Type&> (t));

                if (!type.complete ())
                {
                  throw NotComplete (node.scoped_name ());
                }
              }

              return t;
            }
            catch (std::bad_cast const&)
            {
              throw WrongType (node.scoped_name ());
            }
          }
          catch (Impl::NotFound const&)
          {
            throw NotFound ();
          }
        }

        template<typename I>
        void Base::
        check_inheritance (I begin, I end, SemanticGraph::Nameable& t)
          throw (AlreadyInherited)
        {
          for (;begin != end; ++begin)
          {
            if ((**begin).inheritee () == t)
            {
              throw AlreadyInherited (t.scoped_name ());
            }
          }
        }

        template<typename I>
        void Base::
        check_support (I begin, I end, SemanticGraph::Nameable& t)
          throw (AlreadySupported)
        {
          for (;begin != end; ++begin)
          {
            if ((**begin).supportee () == t)
            {
              throw AlreadySupported (t.scoped_name ());
            }
          }
        }
      }
    }
  }
}