summaryrefslogtreecommitdiff
path: root/modules/CIAO/CCF/CCF/IDL2/SemanticAction/Impl/Const.cpp
blob: 9685d0874ee15ec6f87180bdf26e4b8adc4a1ccf (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/IDL2/SemanticAction/Impl/Const.cpp
// author    : Boris Kolpackov <boris@kolpackov.net>
// cvs-id    : $Id$

#include "CCF/IDL2/SemanticAction/Impl/Const.hpp"

#include "CCF/IDL2/SemanticGraph/Fundamental.hpp"
#include "CCF/IDL2/SemanticGraph/IntExpression.hpp"

#include <iostream>

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

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

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

        void Const::
        begin (IdentifierPtr const& type_id,
               SimpleIdentifierPtr const& name_id)
        {
          if (ctx.trace ())
            cerr << "const " << type_id << " " << name_id << endl;

          const_ = 0;

          SimpleName name (name_id->lexeme ());
          Name type_name (type_id->lexeme ());
          ScopedName from (ctx.scope ().scoped_name ());

          try
          {
            try
            {
              Type& t (resolve<Type> (from, type_name, Flags::complete));

              if (dynamic_cast<Octet*> (&t) ||
                  dynamic_cast<Short*> (&t) ||
                  dynamic_cast<UnsignedShort*> (&t) ||
                  dynamic_cast<Long*> (&t) ||
                  dynamic_cast<UnsignedLong*> (&t) ||
                  dynamic_cast<LongLong*> (&t) ||
                  dynamic_cast<UnsignedLongLong*> (&t))
              {
                // Integer constant.
                //
                const_ = &ctx.tu ().new_node<SemanticGraph::IntConst> (
                  ctx.file (), name_id->line ());

                ctx.tu ().new_edge<Belongs> (*const_, t);
                ctx.tu ().new_edge<Defines> (ctx.scope (), *const_, name);
              }

            }
            catch (Resolve const&)
            {
              cerr << ctx.file () << ":" << type_id->line () << ": error: "
                   << "invalid const declaration" << endl;
              throw;
            }

            //@@ I am not handling NotUnique here. For example if
            //   I provide module name as type then the compiler
            //   will ICE. Think about other places it may happen
            //   (attribute, value memebr, typeded, others?).
            //
          }
          catch (NotFound const&)
          {
            cerr << ctx.file () << ":" << type_id->line () << ": error: "
                 << "no type with name \'" << type_name
                 << "\' visible from scope \'" << from << "\'" << endl;
          }
          catch (WrongType const&)
          {
            cerr << ctx.file () << ":" << type_id->line () << ": error: "
                 << "declaration with name \'" << type_name
                 << "\' visible from scope \'" << from
                 << "\' is not a type declaration" << endl;

            cerr << ctx.file () << ":" << type_id->line () << ": error: "
                 << "using non-type as a const type is illegal" << endl;
          }
          catch (NotComplete const& e)
          {
            cerr << ctx.file () << ":" << type_id->line () << ": error: "
                 << "type \'" << e.name () << "\' is not complete" << endl;
          }
        }

        void Const::
        expr ()
        {
          //@@ Need to check if int_exp_stack is empty.
          //
          if (const_ && ctx.int_exp_size () > 0)
          {
            IntExpression& expr (ctx.int_exp_pop ());

            ctx.tu ().new_edge<Initializes> (expr, *const_);
          }
        }
      }
    }
  }
}