aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/eolian_js/eolian/class.hh
blob: bd04d5fedd667e1773210dc86afc9c9629c00dcb (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
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
#ifndef EOLIAN_KLASS_HH
#define EOLIAN_KLASS_HH

#include <Eina.hh>

#include <eolian/js/domain.hh>

#include <ostream>

inline std::string name(Eolian_Class const* klass)
{
  return ::eolian_class_name_get(klass);
}

inline std::string full_name(Eolian_Class const* klass)
{
  return ::eolian_class_full_name_get(klass);
}

inline std::string full_name_transformed(Eolian_Class const* klass)
{
  auto r = full_name(klass);
  std::replace(r.begin(), r.end(), '.', '_');
  return r;
}

inline std::size_t namespace_size(Eolian_Class const* klass)
{
   std::size_t size = 0;
   for(efl::eina::iterator<const char> first (::eolian_class_namespaces_get(klass))
         , last; first != last; ++first)
     ++size;
   return size;
}

inline std::string type_class_name(Eolian_Type const* tp)
{
   if (tp)
     {
        Eolian_Type_Type tpt = ::eolian_type_type_get(tp);
        if (tpt == EOLIAN_TYPE_POINTER || tpt == EOLIAN_TYPE_ALIAS || tpt == EOLIAN_TYPE_REGULAR)
          {
             return type_class_name(::eolian_type_base_type_get(tp));
          }
        else if(tpt == EOLIAN_TYPE_CLASS)
          {
             Eolian_Class const* klass = ::eolian_type_class_get(tp);
             if (klass)
               {
                  Eina_Stringshare* klass_name = ::eolian_class_full_name_get(klass);
                  if (!klass_name)
                    throw std::runtime_error("Could not get Eo class name");

                  return klass_name;
               } // TODO: else should throw std::runtime_error("Could not get Eo class");
          }
        else if(tpt == EOLIAN_TYPE_STRUCT)
          {
             auto struct_type_full_name = ::eolian_type_full_name_get(tp);
             if (!struct_type_full_name)
               throw std::runtime_error("Could not get struct name");
             return struct_type_full_name;
          }
     }
   return "";
}

inline void print_lower_case_namespace(Eolian_Class const* klass, std::ostream& os)
{
  std::vector<std::string> namespace_;
   for(efl::eina::iterator<const char> first (::eolian_class_namespaces_get(klass))
         , last; first != last; ++first)
     namespace_.push_back(&*first);
   for(auto first = namespace_.begin(), last = namespace_.end()
         ; first != last; ++first)
     {
       std::string lower(*first);
       std::transform(lower.begin(), lower.end(), lower.begin(), tolower);
       os << lower;
       if(std::next(first) != last) os << "::";
     }
}

inline void print_eo_class(Eolian_Class const* klass, std::ostream& os)
{
   assert(klass != 0);
   EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "print_eo_class";

   auto toupper = [] (unsigned char c) { return std::toupper(c); };
  
   EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "print_eo_class";
   std::vector<std::string> namespace_;
   for(efl::eina::iterator<const char> first (::eolian_class_namespaces_get(klass))
         , last; first != last; ++first)
     namespace_.push_back(&*first);
   EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "namespace";
   namespace_.push_back(name(klass));
   EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "class";
   switch(eolian_class_type_get(klass))
     {
     case EOLIAN_CLASS_REGULAR:
     case EOLIAN_CLASS_ABSTRACT:
       EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "";
       namespace_.push_back("CLASS");
       break;
     case EOLIAN_CLASS_INTERFACE:
       EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "";
       namespace_.push_back("INTERFACE");
       break;
     case EOLIAN_CLASS_MIXIN:
       EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "";
       namespace_.push_back("MIXIN");
       break;
     default:
       EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "default ?";
       std::abort();
     }
   EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "";
   for(auto first = namespace_.begin(), last = namespace_.end()
         ; first != last; ++first)
     {
       EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "";
       std::string upper(*first);
       std::transform(upper.begin(), upper.end(), upper.begin(), toupper);
       os << upper;
       if(std::next(first) != last) os << "_";
     }
   EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "";
}

inline bool is_evas(Eolian_Class const* klass)
{
  EINA_CXX_DOM_LOG_WARN(eolian::js::domain) << "is_evas";
  efl::eina::iterator<const char> first (::eolian_class_namespaces_get(klass));
  return first != efl::eina::iterator<const char>()
    && std::strcmp(&*first, "Evas") == 0;
}

#endif