summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/CIDL/SemanticAction/Impl/HomeExecutor.hpp
blob: 8364f526cbb2936b2eaf0afd9dcc4d98a2445b4c (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// file      : CCF/CIDL/SemanticAction/Impl/HomeExecutor.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $id$

#ifndef CCF_CIDL_SEMANTIC_ACTION_IMPL_HOME_EXECUTOR_HPP
#define CCF_CIDL_SEMANTIC_ACTION_IMPL_HOME_EXECUTOR_HPP

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

namespace CCF
{
  namespace CIDL
  {
    namespace SemanticAction
    {
      namespace Impl
      {
        //
        //
        //
        class HomeExecutor :
          public virtual SemanticAction::HomeExecutor,
          public virtual ScopeBase<SyntaxTree::HomeExecutorPtr>
        {
        public:
          virtual
          ~HomeExecutor () throw () {}

          HomeExecutor (bool trace, SyntaxTree::ScopePtr& scope)
              : ScopeBase<SyntaxTree::HomeExecutorPtr> (scope),
                trace_ (trace),
                name_ (""),
                implements_ (""),
                manages_ ("")

          {
          }

          virtual void
          begin (SimpleIdentifierPtr const& id)
          {
            if (trace_) cerr << "home executor " << id << endl;
            name_ = SyntaxTree::SimpleName (id->lexeme ());
          }

          virtual void
          open_scope ()
          {
            // Note: nothing is expected to go to home executor scope
            //       so watch for grammar changes.
          }

          virtual void
          implements (IdentifierPtr const& id)
          {
            if (trace_) cerr << "implements " << id << endl;

            using namespace SyntaxTree;

            Name name (id->lexeme ());

            struct ImplementsPredicate : public DeclarationTable::ResolvePredicate
            {
              struct IncompatibleType :
                public DeclarationTable::ResolutionFailure
              {
                IncompatibleType (std::string const& t) : type (t) {}
                std::string type;
              };

              virtual bool
              test (DeclarationPtr const& d)
                throw (IncompatibleType)
              {
                std::string type = d->declaration_class ();

                if (type != "home") throw IncompatibleType (type);

                return d->dynamic_type<TypeDecl> ()->defined ();
              }
            } p;

            try
            {
              ScopedName sn = scope_->table ().resolve (
                name,
                scope_->name (),
                scope_->peek_order (),
                p);

              implements_ = sn;
            }
            catch (ImplementsPredicate::IncompatibleType const& e)
            {
              cerr << "error: invalid implements specification" << endl;

              cerr << "specifying " << e.type << " \'" << name
                   << "\' in home executor implements clause is illegal"
                   << endl;
            }
            catch (DeclarationTable::NameNotFound const&)
            {
              cerr << "error: invalid implements specification" << endl;
              cerr << "no home with name \'"
                   << name << "\' visible from scope \'"
                   << scope_->name () << "\'" << endl;
            }
            catch (DeclarationTable::PredicateNotMet const&)
            {
              cerr << "error: invalid implements specification" << endl;
              cerr << "no defined home with name \'"
                   << name << "\' visible from scope \'"
                   << scope_->name () << "\'" << endl;
              cerr << "implementing forward-declared home is illegal"
                   << endl;
            }

          }

          virtual void
          manages (SimpleIdentifierPtr const& id)
          {
            if (trace_) cerr << "manages " << id << endl;
            manages_ = SyntaxTree::SimpleName (id->lexeme ());
          }

          virtual void
          close_scope ()
          {
            // Note: nothing is expected to go to home executor scope
            //       so watch for grammar changes.
          }

          virtual void
          end ()
          {
            if (trace_) cerr << "end" << endl;

            using namespace SyntaxTree;

            HomeExecutorPtr he (new SyntaxTree::HomeExecutor (
                                  name_,
                                  scope_,
                                  implements_,
                                  manages_));
            scope_->insert (he);
          }
        private:
          bool trace_;
          SyntaxTree::SimpleName name_;
          SyntaxTree::ScopedName implements_;
          SyntaxTree::SimpleName manages_;
        };
      }
    }
  }
}

#endif  // CCF_CIDL_SEMANTIC_ACTION_IMPL_HOME_EXECUTOR_HPP