summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorBruno da Silva Belo <brunodasilvabelo@gmail.com>2020-01-02 22:27:25 +0000
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2020-01-02 22:06:24 -0300
commit5c99f08511f8628c14e176026c641bf1da3eaed2 (patch)
treeb27195c83a14be1d7f447069bce2df909ea0c6ac /src/bin
parent0aaad623a01a623db7e89cb8ed2e8b7636d05867 (diff)
c#: Checking null for parameters generated code.
Checking null for generated code ref T8399 Reviewed-by: Felipe Magno de Almeida <felipe@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D10970
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/eolian_mono/eolian/mono/events.hh17
-rw-r--r--src/bin/eolian_mono/eolian/mono/function_definition.hh1
-rw-r--r--src/bin/eolian_mono/eolian/mono/parameter.hh25
-rw-r--r--src/bin/eolian_mono/eolian_mono.cc3
4 files changed, 29 insertions, 17 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh
index a77f6d7..8bb1799 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -165,7 +165,8 @@ struct pack_event_info_and_call_visitor
165 if (regular.is_struct()) 165 if (regular.is_struct())
166 { 166 {
167 return as_generator( 167 return as_generator(
168 indent << "IntPtr info = Marshal.AllocHGlobal(Marshal.SizeOf(e.arg));\n" 168 indent << "Contract.Requires(e != null, nameof(e));\n"
169 << indent << "IntPtr info = Marshal.AllocHGlobal(Marshal.SizeOf(e.arg));\n"
169 << indent << "CallNativeEventCallback(" + library_name + ", \"_" + evt_c_name + "\", info, " << "(p) => Marshal.FreeHGlobal(p));\n" 170 << indent << "CallNativeEventCallback(" + library_name + ", \"_" + evt_c_name + "\", info, " << "(p) => Marshal.FreeHGlobal(p));\n"
170 ).generate(sink, attributes::unused, *context); 171 ).generate(sink, attributes::unused, *context);
171 } 172 }
@@ -192,7 +193,8 @@ struct pack_event_info_and_call_visitor
192 auto str_accept_func = [&](std::string const& conversion) 193 auto str_accept_func = [&](std::string const& conversion)
193 { 194 {
194 return as_generator( 195 return as_generator(
195 indent << "IntPtr info = Eina.StringConversion.ManagedStringToNativeUtf8Alloc(" << conversion << ");\n" 196 indent << "Contract.Requires(e != null, nameof(e));\n"
197 << indent << "IntPtr info = Eina.StringConversion.ManagedStringToNativeUtf8Alloc(" << conversion << ");\n"
196 << indent << "CallNativeEventCallback(" + library_name + ", \"_" + evt_c_name + "\", info, " << "(p) => Eina.MemoryNative.Free(p));\n" 198 << indent << "CallNativeEventCallback(" + library_name + ", \"_" + evt_c_name + "\", info, " << "(p) => Eina.MemoryNative.Free(p));\n"
197 ).generate(sink, attributes::unused, *context); 199 ).generate(sink, attributes::unused, *context);
198 }; 200 };
@@ -210,7 +212,8 @@ struct pack_event_info_and_call_visitor
210 auto value_accept_func = [&](std::string const& conversion) 212 auto value_accept_func = [&](std::string const& conversion)
211 { 213 {
212 return as_generator( 214 return as_generator(
213 indent << "IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(" << conversion << ");\n" 215 indent << "Contract.Requires(e != null, nameof(e));\n"
216 << indent << "IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(" << conversion << ");\n"
214 << indent << "CallNativeEventCallback(" + library_name + ", \"_" + evt_c_name + "\", info, " << "(p) => Marshal.FreeHGlobal(p));\n" 217 << indent << "CallNativeEventCallback(" + library_name + ", \"_" + evt_c_name + "\", info, " << "(p) => Marshal.FreeHGlobal(p));\n"
215 ).generate(sink, attributes::unused, *context); 218 ).generate(sink, attributes::unused, *context);
216 }; 219 };
@@ -223,7 +226,9 @@ struct pack_event_info_and_call_visitor
223 bool operator()(grammar::attributes::klass_name const&) const 226 bool operator()(grammar::attributes::klass_name const&) const
224 { 227 {
225 auto const& indent = current_indentation(*context); 228 auto const& indent = current_indentation(*context);
226 return as_generator(indent << "IntPtr info = e.arg.NativeHandle;\n" 229 return as_generator(
230 indent << "Contract.Requires(e != null, nameof(e));\n"
231 << indent << "IntPtr info = e.arg.NativeHandle;\n"
227 << "CallNativeEventCallback(" << library_name << ", \"_" << evt_c_name << "\", IntPtr.Zero, null);\n" 232 << "CallNativeEventCallback(" << library_name << ", \"_" << evt_c_name << "\", IntPtr.Zero, null);\n"
228 ).generate(sink, attributes::unused, *context); 233 ).generate(sink, attributes::unused, *context);
229 } 234 }
@@ -233,7 +238,9 @@ struct pack_event_info_and_call_visitor
233 if ((type.outer.base_type == "iterator") || (type.outer.base_type == "accessor")) 238 if ((type.outer.base_type == "iterator") || (type.outer.base_type == "accessor"))
234 return true; 239 return true;
235 240
236 return as_generator(indent << "IntPtr info = e.arg.Handle;\n" 241 return as_generator(
242 indent << "Contract.Requires(e != null, nameof(e));\n"
243 << indent << "IntPtr info = e.arg.Handle;\n"
237 << "CallNativeEventCallback(" << library_name << ", \"_" << evt_c_name << "\", IntPtr.Zero, null);\n" 244 << "CallNativeEventCallback(" << library_name << ", \"_" << evt_c_name << "\", IntPtr.Zero, null);\n"
238 ).generate(sink, attributes::unused, *context); 245 ).generate(sink, attributes::unused, *context);
239 } 246 }
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index 86eb2db..fa49412 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -305,6 +305,7 @@ struct property_extension_method_definition_generator
305 if (!as_generator(scope_tab << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.BindablePart<T> part, Efl.Csharp.ExtensionTag<" 305 if (!as_generator(scope_tab << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.BindablePart<T> part, Efl.Csharp.ExtensionTag<"
306 << name_helpers::klass_full_concrete_or_interface_name(cls) 306 << name_helpers::klass_full_concrete_or_interface_name(cls)
307 << ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n" 307 << ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n"
308 << scope_tab << scope_tab << "Contract.Requires(part != null, nameof(part));\n"
308 << scope_tab << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(part.PartName, \"" << property.name << "\", part.Binder);\n" 309 << scope_tab << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(part.PartName, \"" << property.name << "\", part.Binder);\n"
309 << scope_tab << "}\n\n" 310 << scope_tab << "}\n\n"
310 ).generate(sink, std::make_tuple(prop_type, prop_type), context)) 311 ).generate(sink, std::make_tuple(prop_type, prop_type), context))
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh b/src/bin/eolian_mono/eolian/mono/parameter.hh
index 4af5fe2..5e6246d 100644
--- a/src/bin/eolian_mono/eolian/mono/parameter.hh
+++ b/src/bin/eolian_mono/eolian/mono/parameter.hh
@@ -693,10 +693,10 @@ struct convert_in_variable_generator
693 } 693 }
694 else if (param.type.c_type == "Eina_Binbuf *" || param.type.c_type == "const Eina_Binbuf *") 694 else if (param.type.c_type == "Eina_Binbuf *" || param.type.c_type == "const Eina_Binbuf *")
695 { 695 {
696 auto var_name = in_variable_name(param.param_name);
697 if (!as_generator( 696 if (!as_generator(
698 "var " << string << " = " << escape_keyword(param.param_name) << ".Handle;\n" 697 "Contract.Requires(" << string << " != null, nameof(" << string << "));\n"
699 ).generate(sink, var_name, context)) 698 << scope_tab(2) << "var " << string << " = " << string << ".Handle;\n"
699 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), escape_keyword(param.param_name), in_variable_name(param.param_name), escape_keyword(param.param_name)), context))
700 return false; 700 return false;
701 if (param.type.has_own) 701 if (param.type.has_own)
702 { 702 {
@@ -710,10 +710,10 @@ struct convert_in_variable_generator
710 attributes::complex_type_def const* complex = efl::eina::get<attributes::complex_type_def>(&param.type.original_type); 710 attributes::complex_type_def const* complex = efl::eina::get<attributes::complex_type_def>(&param.type.original_type);
711 if (!complex || complex->subtypes.size() != 2) 711 if (!complex || complex->subtypes.size() != 2)
712 return false; 712 return false;
713 auto var_name = in_variable_name(param.param_name);
714 if (!as_generator( 713 if (!as_generator(
715 "var " << string << " = " << escape_keyword(param.param_name) << ".Handle;\n" 714 "Contract.Requires(" << string << " != null, nameof(" << string << "));\n"
716 ).generate(sink, var_name, context)) 715 << scope_tab(2) << "var " << string << " = " << string << ".Handle;\n"
716 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), escape_keyword(param.param_name), in_variable_name(param.param_name), escape_keyword(param.param_name)), context))
717 return false; 717 return false;
718 if (param.type.has_own && !as_generator( 718 if (param.type.has_own && !as_generator(
719 escape_keyword(param.param_name) << ".SetOwn(false);\n" 719 escape_keyword(param.param_name) << ".SetOwn(false);\n"
@@ -736,10 +736,12 @@ struct convert_in_variable_generator
736 attributes::complex_type_def const* complex = efl::eina::get<attributes::complex_type_def>(&param.type.original_type); 736 attributes::complex_type_def const* complex = efl::eina::get<attributes::complex_type_def>(&param.type.original_type);
737 if (!complex) 737 if (!complex)
738 return false; 738 return false;
739 auto var_name = in_variable_name(param.param_name);
740 if (!as_generator( 739 if (!as_generator(
741 "var " << string << " = " << escape_keyword(param.param_name) << ".Handle;\n" 740 "Contract.Requires(" << string << " != null, nameof(" << string << "));\n"
742 ).generate(sink, var_name, context)) 741 << "var " << string << " = " << string << ".Handle;\n"
742 ).generate(sink, std::make_tuple(escape_keyword(param.param_name), escape_keyword(param.param_name),
743 in_variable_name(param.param_name), escape_keyword(param.param_name))
744 , context))
743 return false; 745 return false;
744 if (param.type.has_own && !as_generator( 746 if (param.type.has_own && !as_generator(
745 escape_keyword(param.param_name) << ".Own = false;\n" 747 escape_keyword(param.param_name) << ".Own = false;\n"
@@ -777,8 +779,9 @@ struct convert_in_variable_generator
777 else if (param.type.c_type == "Eina_Value") 779 else if (param.type.c_type == "Eina_Value")
778 { 780 {
779 return as_generator( 781 return as_generator(
780 "var " << string << " = " << string << ".GetNative();\n" 782 "Contract.Requires(" << string << " != null, nameof(" << string << "));\n"
781 ).generate(sink, std::make_tuple(in_variable_name(param.param_name), param.param_name), context); 783 "var " << string << " = " << string << ".GetNative();\n"
784 ).generate(sink, std::make_tuple(param.param_name, param.param_name, in_variable_name(param.param_name), param.param_name), context);
782 } 785 }
783 return true; 786 return true;
784 } 787 }
diff --git a/src/bin/eolian_mono/eolian_mono.cc b/src/bin/eolian_mono/eolian_mono.cc
index b6d2b6f..bf3874a 100644
--- a/src/bin/eolian_mono/eolian_mono.cc
+++ b/src/bin/eolian_mono/eolian_mono.cc
@@ -172,7 +172,8 @@ run(options_type const& opts)
172 "using System.Linq;\n" 172 "using System.Linq;\n"
173 "using System.Threading;\n" 173 "using System.Threading;\n"
174 "using System.ComponentModel;\n" 174 "using System.ComponentModel;\n"
175 "using System.Diagnostics.CodeAnalysis;\n") 175 "using System.Diagnostics.CodeAnalysis;\n"
176 "using System.Diagnostics.Contracts;\n")
176 .generate(iterator, efl::eolian::grammar::attributes::unused, efl::eolian::grammar::context_null())) 177 .generate(iterator, efl::eolian::grammar::attributes::unused, efl::eolian::grammar::context_null()))
177 { 178 {
178 throw std::runtime_error("Failed to generate file preamble"); 179 throw std::runtime_error("Failed to generate file preamble");