lib/antlr4-native/context.rb in antlr4-native-1.1.0 vs lib/antlr4-native/context.rb in antlr4-native-2.0.0

- old
+ new

@@ -49,20 +49,28 @@ .join("\n") end def conversions @class_conversions ||= <<~END - template <> - Object to_ruby<#{parser_ns}::#{name}*>(#{parser_ns}::#{name}* const &x) { - if (!x) return Nil; - return Data_Object<#{parser_ns}::#{name}>(x, #{proxy_class_variable}, nullptr, nullptr); - } + namespace Rice::detail { + template <> + class To_Ruby<#{parser_ns}::#{name}*> { + public: + VALUE convert(#{parser_ns}::#{name}* const &x) { + if (!x) return Nil; + return Data_Object<#{parser_ns}::#{name}>(x, false, #{proxy_class_variable}); + } + }; - template <> - Object to_ruby<#{name}Proxy*>(#{name}Proxy* const &x) { - if (!x) return Nil; - return Data_Object<#{name}Proxy>(x, #{proxy_class_variable}, nullptr, nullptr); + template <> + class To_Ruby<#{name}Proxy*> { + public: + VALUE convert(#{name}Proxy* const &x) { + if (!x) return Nil; + return Data_Object<#{name}Proxy>(x, false, #{proxy_class_variable}); + } + }; } END end def proxy_class_methods @@ -86,11 +94,11 @@ for (size_t i = 0; i < count; i ++) { a.push(#{ctx_method.name}At(i)); } } - return a; + return std::move(a); } END else <<~END Object #{name}Proxy::#{ctx_method.cpp_name}(#{ctx_method.raw_args}) { @@ -103,11 +111,11 @@ if (ctx == nullptr) { return Qnil; } for (auto child : getChildren()) { - if (ctx == from_ruby<ContextProxy>(child).getOriginal()) { + if (ctx == detail::From_Ruby<ContextProxy>().convert(child.value()).getOriginal()) { return child; } } return Nil; @@ -125,21 +133,21 @@ <<~END Object #{name}Proxy::#{token_mtd.cpp_name}(#{token_mtd.raw_args}) { Array a; if (orig == nullptr) { - return a; + return std::move(a); } auto vec = ((#{parser_ns}::#{name}*)orig) -> #{token_mtd.name}(#{params}); for (auto it = vec.begin(); it != vec.end(); it ++) { TerminalNodeProxy proxy(*it); - a.push(proxy); + a.push(detail::To_Ruby<TerminalNodeProxy>().convert(proxy)); } - return a; + return std::move(a); } END else <<~END Object #{name}Proxy::#{token_mtd.cpp_name}(#{token_mtd.raw_args}) { @@ -152,21 +160,20 @@ if (token == nullptr) { return Qnil; } TerminalNodeProxy proxy(token); - return to_ruby(proxy); + return detail::To_Ruby<TerminalNodeProxy>().convert(proxy); } END end end end def class_wrapper(module_var) @class_wrapper ||= begin lines = [ - "#{proxy_class_variable} = #{module_var}", - ".define_class<#{name}Proxy, ContextProxy>(\"#{name}\")" + %(#{proxy_class_variable} = define_class_under<#{name}Proxy, ContextProxy>(#{module_var}, "#{name}")) ] each_context_method do |ctx_method| lines << ".define_method(\"#{underscore(ctx_method.cpp_name)}\", &#{name}Proxy::#{ctx_method.cpp_name})" end