From: Rico Tzschichholz Date: Wed, 27 Mar 2019 23:02:59 +0000 (+0100) Subject: girparser: Create correct output in get_default_lower_case_suffix() X-Git-Tag: 0.36.19~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8b0ee6ecdefebf37a870d9ecd2248772bcd62f1;p=thirdparty%2Fvala.git girparser: Create correct output in get_default_lower_case_suffix() It must match the output of CCodeAttribute.get_default_lower_case_suffix() Add metadata support to set lower_case_csuffix See https://gitlab.gnome.org/GNOME/vala/issues/778 --- diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index bd42b6aa1..b990004ac 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -778,6 +778,7 @@ public class Vala.CCodeAttribute : AttributeCache { if (sym is ObjectTypeSymbol) { var csuffix = Symbol.camel_case_to_lower_case (sym.name); + // FIXME Code duplication with GirParser.Node.get_default_lower_case_suffix() // remove underscores in some cases to avoid conflicts of type macros if (csuffix.has_prefix ("type_")) { csuffix = "type" + csuffix.substring ("type_".length); diff --git a/tests/Makefile.am b/tests/Makefile.am index b3270b8a2..bc600c141 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -392,6 +392,7 @@ TESTS = \ gir/delegate-array-length-type.test \ gir/method-array-length-type.test \ gir/parameter-array-length-type.test \ + gir/symbol-type-csuffix.test \ annotations/deprecated.vala \ annotations/description.vala \ annotations/noaccessormethod.test \ diff --git a/tests/gir/symbol-type-csuffix.test b/tests/gir/symbol-type-csuffix.test new file mode 100644 index 000000000..8039d4a8c --- /dev/null +++ b/tests/gir/symbol-type-csuffix.test @@ -0,0 +1,26 @@ +GIR + +Input: + + + + + + + + + + + + + + +Output: + +[CCode (cheader_filename = "test.h", type_id = "test_foo_get_type ()")] +public class TypeFoo : GLib.Object { + [CCode (cname = "test_type_foo_new", has_construct_function = false)] + public TypeFoo (); + [CCode (cname = "test_type_foo_bar")] + public void bar (); +} diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 40d0efb04..e020d495e 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -87,7 +87,8 @@ public class Vala.GirParser : CodeVisitor { DELEGATE_TARGET_CNAME, FINISH_VFUNC_NAME, NO_ACCESSOR_METHOD, - DELEGATE_TARGET; + DELEGATE_TARGET, + LOWER_CASE_CSUFFIX; public static ArgumentType? from_string (string name) { var enum_class = (EnumClass) typeof(ArgumentType).class_ref (); @@ -697,6 +698,9 @@ public class Vala.GirParser : CodeVisitor { public string get_lower_case_csuffix () { var suffix = symbol.get_attribute_string ("CCode", "lower_case_csuffix"); + if (metadata.has_argument (ArgumentType.LOWER_CASE_CSUFFIX)) { + suffix = metadata.get_string (ArgumentType.LOWER_CASE_CSUFFIX); + } // we can't rely on gir suffix if metadata changed the name if (suffix == null && girdata != null && girdata["c:symbol-prefix"] != null && !metadata.has_argument (ArgumentType.NAME)) { @@ -709,7 +713,19 @@ public class Vala.GirParser : CodeVisitor { } public string get_default_lower_case_csuffix () { - return Symbol.camel_case_to_lower_case (name); + var csuffix = Symbol.camel_case_to_lower_case (name); + + // FIXME Code duplication with CCodeAttribute.get_default_lower_case_suffix() + // remove underscores in some cases to avoid conflicts of type macros + if (csuffix.has_prefix ("type_")) { + csuffix = "type" + csuffix.substring ("type_".length); + } else if (csuffix.has_prefix ("is_")) { + csuffix = "is" + csuffix.substring ("is_".length); + } + if (csuffix.has_suffix ("_class")) { + csuffix = csuffix.substring (0, csuffix.length - "_class".length) + "class"; + } + return csuffix; } public string get_cprefix () {