summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/IDL2/SemanticAction/Impl/Operation.hpp
blob: 686d851e8f38edc521f78fda2caf34231163fac1 (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/IDL2/SemanticAction/Impl/Operation.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef CCF_IDL2_SEMANTIC_ACTION_IMPL_OPERATION_HPP
#define CCF_IDL2_SEMANTIC_ACTION_IMPL_OPERATION_HPP

#include "CCF/IDL2/SemanticAction/Operation.hpp"

namespace CCF
{
  namespace IDL2
  {
    namespace SemanticAction
    {
      namespace Impl
      {
        //
        //
        //
        class Operation : public virtual SemanticAction::Operation
        {
        public:

          virtual
          ~Operation () throw () {}

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

          bool
          lookup_type (SyntaxTree::Name const& name,
                       SyntaxTree::ScopedName& result)
          {
            using namespace SyntaxTree;

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

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

              return true;
            }
            catch (DeclarationTable::NameNotFound const&)
            {
              cerr << "error: invalid operation declaration" << endl;
              cerr << "no type with name \'"
                   << name << "\' visible from scope \'"
                   << scope_->name () << "\'" << endl;
            }
            catch (DeclarationTable::PredicateNotMet const&)
            {
              cerr << "error: invalid operation declaration" << endl;
              cerr << "declaration with name \'" << name
                   << "\' visible from scope \'" << scope_->name ()
                   << "\' is not a type declaration" << endl;
              cerr << "using non-type as operation parameter type "
                   << " or return type is illegal"
                   << endl;
            }

            return false;
          }


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

            using namespace SyntaxTree;

            ScopedName type_name;

            if (lookup_type (Name (type_id->lexeme ()), type_name))
            {
              operation_ = OperationDeclPtr (
                new OperationDecl (SimpleName (name_id->lexeme ()),
                                   type_name,
                                   scope_));
            }
          }


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

            using namespace SyntaxTree;

            ScopedName type_name ("");

            if (lookup_type (Name (type_id->lexeme ()), type_name) &&
                operation_ != 0)
            {
              OperationParameter::Direction::Value d =
                OperationParameter::Direction::INOUT;

              if (direction == Direction::IN)
              {
                d = OperationParameter::Direction::IN;
              }
              else if (direction == Direction::OUT)
              {
                d = OperationParameter::Direction::OUT;
              }

              OperationParameterPtr p (
                new OperationParameter (d,
                                        type_name,
                                        SimpleName (name_id->lexeme ()),
                                        scope_->table ()));
              operation_->insert (p);
            }
          }

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

      }
    }
  }
}

#endif  // CCF_IDL2_SEMANTIC_ACTION_IMPL_OPERATION_HPP