summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/klass_def.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/eolian_cxx/grammar/klass_def.hpp')
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index 5fb0dbb..9969e89 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -16,6 +16,8 @@
16#include <vector> 16#include <vector>
17#include <memory> 17#include <memory>
18#include <set> 18#include <set>
19#include <iosfwd>
20#include <string>
19 21
20namespace efl { namespace eolian { namespace grammar { 22namespace efl { namespace eolian { namespace grammar {
21 23
@@ -73,6 +75,26 @@ enum class typedecl_type
73 function_ptr, 75 function_ptr,
74}; 76};
75 77
78inline std::ostream& operator<<(std::ostream& s, typedecl_type dec)
79{
80 switch(dec)
81 {
82 case typedecl_type::unknown:
83 return s << "unknown";
84 case typedecl_type::struct_:
85 return s << "struct_";
86 case typedecl_type::struct_opaque:
87 return s << "struct_opaque";
88 case typedecl_type::enum_:
89 return s << "enum_";
90 case typedecl_type::alias:
91 return s << "alias";
92 case typedecl_type::function_ptr:
93 return s << "function_ptr";
94 };
95 return s;
96}
97
76inline typedecl_type typedecl_type_get(Eolian_Typedecl const* decl) 98inline typedecl_type typedecl_type_get(Eolian_Typedecl const* decl)
77{ 99{
78 if (!decl) 100 if (!decl)
@@ -91,6 +113,14 @@ inline typedecl_type typedecl_type_get(Eolian_Typedecl const* decl)
91 } 113 }
92} 114}
93 115
116enum class variable_type
117{
118 unknown,
119 constant,
120 global
121};
122
123
94struct type_def; 124struct type_def;
95bool operator==(type_def const& rhs, type_def const& lhs); 125bool operator==(type_def const& rhs, type_def const& lhs);
96bool operator!=(type_def const& rhs, type_def const& lhs); 126bool operator!=(type_def const& rhs, type_def const& lhs);
@@ -100,6 +130,22 @@ enum class class_type
100 regular, abstract_, mixin, interface_ 130 regular, abstract_, mixin, interface_
101}; 131};
102 132
133inline std::ostream& operator<<(std::ostream& s, class_type t)
134{
135 switch(t)
136 {
137 case class_type::regular:
138 return s << "regular";
139 case class_type::abstract_:
140 return s << "abstract_";
141 case class_type::mixin:
142 return s << "mixin";
143 case class_type::interface_:
144 return s << "interface_";
145 };
146 return s;
147}
148
103struct klass_name 149struct klass_name
104{ 150{
105 std::vector<std::string> namespaces; 151 std::vector<std::string> namespaces;
@@ -108,6 +154,14 @@ struct klass_name
108 class_type type; 154 class_type type;
109 std::string klass_get_name; 155 std::string klass_get_name;
110 156
157 friend inline std::ostream& operator<<(std::ostream& s, klass_name const& name)
158 {
159 s << "[ namespaces: {";
160 std::copy(name.namespaces.begin(), name.namespaces.end(), std::ostream_iterator<std::string>(s, ","));
161 return s << "}, eolian_name: " << name.eolian_name << " base_qualifier: " << name.base_qualifier
162 << " type: " << name.type << " klass_get_name: " << name.klass_get_name << "]";
163 }
164
111 klass_name() { 165 klass_name() {
112 } 166 }
113 167
@@ -264,6 +318,14 @@ struct regular_type_def
264 bool is_alias() const { return is_type(typedecl_type::alias); } 318 bool is_alias() const { return is_type(typedecl_type::alias); }
265 bool is_function_ptr() const { return is_type(typedecl_type::function_ptr); } 319 bool is_function_ptr() const { return is_type(typedecl_type::function_ptr); }
266 320
321 friend inline std::ostream& operator<<(std::ostream& s, regular_type_def const& def)
322 {
323 s << "[ base_type: " << def.base_type << " base_qualifier: " << def.base_qualifier
324 << " namespaces: ";
325 std::copy(def.namespaces.begin(), def.namespaces.end(), std::ostream_iterator<std::string>(s, ", "));
326 return s << " type_type: " << def.type_type << " is_undefined " << def.is_undefined << "]";
327 }
328
267 std::string base_type; 329 std::string base_type;
268 qualifier_def base_qualifier; 330 qualifier_def base_qualifier;
269 std::vector<std::string> namespaces; 331 std::vector<std::string> namespaces;
@@ -284,6 +346,13 @@ struct complex_type_def
284{ 346{
285 regular_type_def outer; 347 regular_type_def outer;
286 std::vector<type_def> subtypes; 348 std::vector<type_def> subtypes;
349
350 friend inline std::ostream& operator<<(std::ostream& s, complex_type_def const& def)
351 {
352 s << "[ outer " << def.outer << " subtypes: {";
353 std::copy(def.subtypes.begin(), def.subtypes.end(), std::ostream_iterator<type_def>(s, ", "));
354 return s << "}]";
355 }
287}; 356};
288 357
289inline bool operator==(complex_type_def const& lhs, complex_type_def const& rhs) 358inline bool operator==(complex_type_def const& lhs, complex_type_def const& rhs)
@@ -318,6 +387,12 @@ struct type_def
318 { 387 {
319 return lhs.c_type < rhs.c_type; 388 return lhs.c_type < rhs.c_type;
320 } 389 }
390 friend inline std::ostream& operator<<(std::ostream& s, type_def const& rhs)
391 {
392 return s << "[ original: " << rhs.original_type << " c_type "
393 << rhs.c_type << " has_own " << rhs.has_own << " is_ptr "
394 << rhs.is_ptr << "]";
395 }
321}; 396};
322 397
323struct get_qualifier_visitor 398struct get_qualifier_visitor
@@ -857,6 +932,62 @@ struct property_def
857 } 932 }
858}; 933};
859 934
935struct variable_def
936{
937 std::string name;
938 std::string full_name;
939 type_def base_type;
940 documentation_def documentation;
941 variable_type type;
942 std::vector<std::string> namespaces;
943 Eolian_Value expression_value;
944 bool is_extern : 1;
945
946 friend inline bool operator==(variable_def const& lhs, variable_def const& rhs)
947 {
948 return lhs.name == rhs.name
949 && lhs.full_name == rhs.full_name
950 && lhs.base_type == rhs.base_type
951 && lhs.documentation == rhs.documentation
952 && lhs.type == rhs.type
953 && lhs.namespaces == rhs.namespaces
954 && lhs.expression_value.type == rhs.expression_value.type
955 && lhs.expression_value.value.ll == rhs.expression_value.value.ll
956 && lhs.is_extern == rhs.is_extern;
957 }
958
959 friend inline bool operator!=(variable_def const& lhs, variable_def const& rhs)
960 {
961 return !(lhs == rhs);
962 }
963
964 variable_def() = default;
965 variable_def(Eolian_Variable const* variable, Eolian_Unit const* unit)
966 : name(::eolian_variable_short_name_get(variable))
967 , full_name(::eolian_variable_name_get(variable))
968 , base_type(::eolian_variable_base_type_get(variable), unit, ::EOLIAN_C_TYPE_DEFAULT)
969 , documentation(::eolian_variable_documentation_get(variable))
970 , type(static_cast<variable_type>(::eolian_variable_type_get(variable)))
971 , expression_value()
972 , is_extern(::eolian_variable_is_extern(variable))
973 {
974 for(efl::eina::iterator<const char> namespace_iterator( ::eolian_variable_namespaces_get(variable))
975 , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator)
976 {
977 this->namespaces.push_back((&*namespace_iterator));
978 }
979
980 if (this->type == variable_type::constant)
981 {
982 auto expr = ::eolian_variable_value_get(variable);
983 if (!expr)
984 throw std::runtime_error("Could not get constant variable value expression");
985
986 this->expression_value = ::eolian_expression_eval_type(expr, ::eolian_variable_base_type_get(variable));
987 }
988 }
989};
990
860 991
861// template <int N> 992// template <int N>
862// struct tuple_element<N, function_def const> : tuple_element<N, function_def> {}; 993// struct tuple_element<N, function_def const> : tuple_element<N, function_def> {};