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

#include "CCF/CIDL/SemanticAction/Impl/HomeExecutor.hpp"

#include <iostream>

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

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

        HomeExecutor::
        HomeExecutor (Context& c)
            : Base (c)
        {
        }

        void HomeExecutor::
        begin (SimpleIdentifierPtr const& id)
        {
          if (ctx.trace ()) cerr << "home executor " << id << endl;

          id_ = id;
          he_ = &ctx.tu ().new_node<SemanticGraph::HomeExecutor> (
            ctx.file (), id->line ());
        }

        void HomeExecutor::
        implements (IdentifierPtr const& id)
        {
          if (ctx.trace ()) cerr << "implements " << id << endl;

          Name name (id->lexeme ());
          ScopedName from (ctx.scope ().scoped_name ());

          c_ = 0;

          try
          {
            try
            {
              SemanticGraph::Home& h (
                resolve<SemanticGraph::Home> (from, name, Flags::defined));

              c_ = &dynamic_cast<SemanticGraph::Component&> (
                h.manages ().managee ());

              ctx.tu ().new_edge<Implements> (*he_, h);
            }
            catch (Resolve const&)
            {
              cerr << ctx.file () << ":" << id->line () << ": error: "
                   << "invalid implements specification" << endl;
              throw;
            }
          }
          catch (NotFound const&)
          {
            cerr << ctx.file () << ":" << id->line () << ": error: "
                 << "no home with name \'" << name
                 << "\' visible from scope \'" << from << "\'" << endl;
          }
          catch (WrongType const&)
          {
            cerr << ctx.file () << ":" << id->line () << ": error: "
                 << "incompatible type in implements specification" << endl;
          }
          catch (NotDefined const& e)
          {
            cerr << ctx.file () << ":" << id->line () << ": error: "
                 << "attempt to implement forward-declared home "
                 << e.name () << endl;

            cerr << ctx.file () << ":" << id->line () << ": error: "
                 << "implementation of forward-declared home is illegal"
                 << endl;
          }
        }

        void HomeExecutor::
        manages (SimpleIdentifierPtr const& id)
        {
          if (ctx.trace ()) cerr << "manages " << id << endl;

          if (c_ != 0)
          {
            SemanticGraph::ComponentExecutor& ce (
              ctx.tu ().new_node<SemanticGraph::ComponentExecutor> (
                ctx.file (), id->line ()));

            ctx.tu ().new_edge<Implements> (ce, *c_);

            ctx.tu ().new_edge<Defines> (ctx.scope (), ce, id->lexeme ());
            ctx.tu ().new_edge<Defines> (ctx.scope (), *he_, id_->lexeme ());

            ctx.tu ().new_edge<Manages> (*he_, ce);
          }
        }

        void HomeExecutor::
        end ()
        {
          id_ = 0;
          if (ctx.trace ()) cerr << "end" << endl;
        }
      }
    }
  }
}