From 8210197b3aa2a0d2b25c90c63fa8f9ca1aedd71f Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Mon, 27 Oct 2014 01:22:20 -0200 Subject: [PATCH] eolian-js: Added generation of prototype function member calls --- src/bin/eolian_js/eolian/class.hh | 26 +++++++++++++++++++++--- src/bin/eolian_js/main.cc | 33 +++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/bin/eolian_js/eolian/class.hh b/src/bin/eolian_js/eolian/class.hh index e51e972ce6..e45ca54b49 100644 --- a/src/bin/eolian_js/eolian/class.hh +++ b/src/bin/eolian_js/eolian/class.hh @@ -17,7 +17,7 @@ inline std::size_t namespace_size(Eolian_Class const* klass) return size; } -inline void print_namespace(Eolian_Class const* klass, std::ostream& os) +inline void print_lower_case_namespace(Eolian_Class const* klass, std::ostream& os) { std::vector namespace_; for(efl::eina::iterator first (::eolian_class_namespaces_get(klass)) @@ -26,7 +26,9 @@ inline void print_namespace(Eolian_Class const* klass, std::ostream& os) for(auto first = namespace_.begin(), last = namespace_.end() ; first != last; ++first) { - os << *first; + std::string lower(*first); + std::transform(lower.begin(), lower.end(), lower.begin(), tolower); + os << lower; if(std::next(first) != last) os << "::"; } } @@ -40,7 +42,18 @@ inline void print_eo_class(Eolian_Class const* klass, std::ostream& os) , last; first != last; ++first) namespace_.push_back(&*first); namespace_.push_back(name(klass)); - namespace_.push_back("CLASS"); + switch(eolian_class_type_get(klass)) + { + case EOLIAN_CLASS_REGULAR: + case EOLIAN_CLASS_ABSTRACT: + namespace_.push_back("CLASS"); + break; + case EOLIAN_CLASS_INTERFACE: + namespace_.push_back("INTERFACE"); + break; + default: + std::abort(); + } for(auto first = namespace_.begin(), last = namespace_.end() ; first != last; ++first) { @@ -51,4 +64,11 @@ inline void print_eo_class(Eolian_Class const* klass, std::ostream& os) } } +inline bool is_evas(Eolian_Class const* klass) +{ + efl::eina::iterator first (::eolian_class_namespaces_get(klass)); + return first != efl::eina::iterator() + && std::strcmp(&*first, "Evas") == 0; +} + #endif diff --git a/src/bin/eolian_js/main.cc b/src/bin/eolian_js/main.cc index 8a310b8a52..0b7535a6d6 100644 --- a/src/bin/eolian_js/main.cc +++ b/src/bin/eolian_js/main.cc @@ -122,15 +122,27 @@ int main(int argc, char** argv) os << "#ifndef EFL_GENERATED_EOLIAN_CLASS_GUARD_" << upper_case_class_name << "_H\n"; os << "#define EFL_GENERATED_EOLIAN_CLASS_GUARD_" << upper_case_class_name << "_H\n\n"; + os << "#ifdef HAVE_CONFIG_H\n"; os << "#include \"config.h\"\n"; os << "#endif\n"; + os << "extern \"C\"\n"; + os << "{\n"; + os << "#include \n"; + os << "}\n"; os << "#include \n\n"; + os << "#include \n\n"; os << "#include \n\n"; + os << "extern \"C\" {\n"; + + if(is_evas(klass)) + os << "#include \n"; + os << "#include <" << eolian_class_file_get(klass) << ".h>\n\n"; + os << "}\n"; os << "namespace "; - print_namespace(klass, os); + print_lower_case_namespace(klass, os); os << " {\n"; os << "void register_xxx(v8::Handle global, v8::Isolate* isolate)\n"; @@ -145,18 +157,27 @@ int main(int argc, char** argv) os << " v8::Handle instance = constructor->InstanceTemplate();\n"; os << " instance->SetInternalFieldCount(1);\n"; os << " v8::Handle prototype = constructor->PrototypeTemplate();\n"; + + for(efl::eina::iterator first + ( ::eolian_class_functions_get(klass, EOLIAN_METHOD) ) + , last; first != last; ++first) + { + Eolian_Function const* function = &*first; + os << " prototype->Set( ::v8::String::NewFromUtf8(isolate, \"" + << eolian_function_name_get(function) << "\")\n" + << " , v8::FunctionTemplate::New(isolate, &efl::eo::js::call_function\n" + << " , v8::External::New(isolate, efl::eo::js::call_function_data(& ::" + << eolian_function_full_c_name_get(function) << "))));\n"; + } + os << "}\n"; for(std::size_t i = 0, j = namespace_size(klass); i != j; ++i) os << "}"; os << "\n"; - std::vector functions; + //std::vector functions; - for(efl::eina::iterator first - ( ::eolian_class_functions_get(klass, EOLIAN_METHOD) ) - , last; first != last; ++first) - functions.push_back(&*first); os << "\n#endif\n\n"; }