summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/IDL3/SemanticAction/Impl/HomeFactory.hpp
blob: 403c3477283cbf770df489e3d2b4a56e858b5dfb (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
// file      : CCF/IDL3/SemanticAction/Impl/HomeFactory.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef CCF_IDL3_SEMANTIC_ACTION_IMPL_HOME_FACTORY_HPP
#define CCF_IDL3_SEMANTIC_ACTION_IMPL_HOME_FACTORY_HPP

#include "CCF/IDL3/SemanticAction/HomeFactory.hpp"

namespace CCF
{
  namespace IDL3
  {
    namespace SemanticAction
    {
      namespace Impl
      {
        //
        //
        //
        class HomeFactory : public virtual SemanticAction::HomeFactory
        {
        public:
          virtual
          ~HomeFactory () throw ()
          {
          }

          HomeFactory (bool trace, SyntaxTree::ScopePtr& current)
              : trace_ (trace),
                scope_ (current)
          {
          }

          virtual void
          begin (SimpleIdentifierPtr const& id)
          {
            if (trace_) cerr << "home factory " << id << endl;

            using namespace SyntaxTree;

            HomeDefPtr home (scope_->dynamic_type<HomeDef> ());

            if (home == 0)
            {
              //@@ internal compiler error
            }

            ComponentDefPtr component (home->manages ());

            home_factory_ = HomeFactoryDeclPtr (
              new HomeFactoryDecl (SimpleName (id->lexeme ()),
                                   component->name (),
                                   scope_));
          }

          virtual void
          parameter (IdentifierPtr const& type_id,
                     SimpleIdentifierPtr const& name_id)
          {
            if (trace_) cerr << "parameter " << type_id << " "
                             << name_id << endl;

            using namespace IDL3::SyntaxTree;

            Name type_name (type_id->lexeme ());

            struct Predicate : public DeclarationTable::ResolvePredicate
            {
              virtual bool
              test (DeclarationPtr const& d) const throw ()
              {
                return d->is_a<TypeDecl> ();
              }
            } p;

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

              HomeFactoryParameterPtr p (
                new HomeFactoryParameter (sn,
                                          SimpleName (name_id->lexeme ()),
                                          scope_->table ()));

              home_factory_->insert (p);
            }
            catch (DeclarationTable::NameNotFound const&)
            {
              cerr << "error: invalid home factory declaration" << endl;
              cerr << "no type with name \'"
                   << type_name << "\' visible from scope \'"
                   << scope_->name () << "\'" << endl;
            }
            catch (DeclarationTable::PredicateNotMet const&)
            {
              cerr << "error: invalid home factory declaration" << endl;
              cerr << "declaration with name \'" << type_name
                   << "\' visible from scope \'" << scope_->name ()
                   << "\' is not a type declaration" << endl;
              cerr << "using non-type as home factory parameter type is illegal"
                   << endl;
            }
          }

          virtual void
          end ()
          {
            if (trace_) cerr << "end" << endl;
            scope_->insert (home_factory_);
            home_factory_ = SyntaxTree::HomeFactoryDeclPtr ();
          }
        private:
          bool trace_;
          SyntaxTree::ScopePtr& scope_;
          SyntaxTree::HomeFactoryDeclPtr home_factory_;
        };
      }
    }
  }
}

#endif  // CCF_IDL3_SEMANTIC_ACTION_IMPL_HOME_FACTORY_HPP