summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/eo_validate.hh
blob: 9e5342d55d57b04dfac3ececa15da2d3ac110e4f (plain) (blame)
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

#ifndef EOLIAN_CXX_EO_CLASS_VALIDATE_HH
#define EOLIAN_CXX_EO_CLASS_VALIDATE_HH

#include <string>
#include <cassert>

#ifdef DEBUG
#include <iostream>
#endif

#include "eo_types.hh"

namespace efl { namespace eolian {

inline bool
_isvalid(const std::string& name)
{
   return name.size() > 0 and isalpha(name[0]);
}

inline void
_dbg(const std::string& msg)
{
#ifdef DEBUG
   std::cerr << "eo_validate() - " << msg << std::endl;
#endif
}

inline void
eo_class_validate(const eo_class& cls)
{
   _dbg("class name... " + cls.name);
   assert(_isvalid(cls.name));

   _dbg("class type... " + cls.type);
   assert(cls.type != eo_class::regular_ ||
          cls.type != eo_class::regular_noninst_ ||
          cls.type != eo_class::interface_ ||
          cls.type != eo_class::mixin_);

   {
      constructors_container_type::const_iterator it,
        first = cls.constructors.begin(),
        last = cls.constructors.end();
      for (it = first; it != last; ++it)
        {
           parameters_container_type::const_iterator
             param = (*it).params.begin(),
             last_param = (*it).params.end();
           _dbg("constructor... " + (*it).name);
           assert(_isvalid((*it).name));
           for (; param != last_param; ++param)
             {
                _dbg("constructor parameter... " + (*param).name);
                assert(_isvalid((*param).name));
                _dbg("constructor parameter type... " + (*param).type);
                assert(_isvalid((*param).type));
             }
        }
   }

   {
      functions_container_type::const_iterator it,
        first = cls.functions.begin(),
        last  = cls.functions.end();
      for (it = first; it != last; ++it)
        {
           _dbg("function... " + (*it).name);
           assert(_isvalid((*it).name));
           _dbg("function api... " + (*it).impl);
           assert(_isvalid((*it).impl));
           _dbg("function return... " + (*it).ret);
           assert(_isvalid((*it).ret));
           parameters_container_type::const_iterator
             param = (*it).params.begin(),
             last_param = (*it).params.end();
           for (; param != last_param; ++param)
             {
                _dbg("function parameter... " + (*param).name);
                assert(_isvalid((*param).name));
                _dbg("function parameter type... " + (*param).type);
                assert(_isvalid((*param).type));
             }
        }
   }
}

} } // namespace efl { namespace eolian {

#endif // EOLIAN_CXX_EO_CLASS_VALIDATE_HH