diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-11-09 15:20:11 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-11-09 15:20:11 +0100 |
commit | 2957adfc99464dc519a3f15ff313a986f6c780ed (patch) | |
tree | 11d8dc8829b1a9286e3efa68fca28d67cd27cb3d /codegen | |
parent | 35bfea81798da96a651dd491f7a09658e15ce802 (diff) | |
download | vala-2957adfc99464dc519a3f15ff313a986f6c780ed.tar.gz |
codegen: Use SemanticAnalyzer.get_data_type_for_symbol()
Diffstat (limited to 'codegen')
-rw-r--r-- | codegen/valaccodebasemodule.vala | 49 | ||||
-rw-r--r-- | codegen/valaccodememberaccessmodule.vala | 4 | ||||
-rw-r--r-- | codegen/valaccodemethodmodule.vala | 2 | ||||
-rw-r--r-- | codegen/valaccodestructmodule.vala | 2 | ||||
-rw-r--r-- | codegen/valagirwriter.vala | 4 | ||||
-rw-r--r-- | codegen/valagtypemodule.vala | 10 |
6 files changed, 20 insertions, 51 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index f3c044a44..615180dbe 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -1582,7 +1582,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (prop.binding == MemberBinding.INSTANCE) { var t = (TypeSymbol) prop.parent_symbol; - var this_type = get_data_type_for_symbol (t); + var this_type = SemanticAnalyzer.get_data_type_for_symbol (t); generate_type_declaration (this_type, decl_space); var cselfparam = new CCodeParameter ("self", get_ccode_name (this_type)); if (t is Struct && !((Struct) t).is_simple_type ()) { @@ -1664,7 +1664,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return; } - var this_type = get_data_type_for_symbol (t); + var this_type = SemanticAnalyzer.get_data_type_for_symbol (t); var cselfparam = new CCodeParameter ("self", get_ccode_name (this_type)); if (t is Struct && !((Struct) t).is_simple_type ()) { cselfparam.type_name += "*"; @@ -2032,7 +2032,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { data.add_field ("Block%dData *".printf (parent_block_id), "_data%d_".printf (parent_block_id)); } else { if (get_this_type () != null) { - data.add_field (get_ccode_name (get_data_type_for_symbol (current_type_symbol)), "self"); + data.add_field (get_ccode_name (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol)), "self"); } if (current_method != null) { @@ -2099,7 +2099,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { bool in_creation_method_with_chainup = (current_method is CreationMethod && current_class != null && current_class.base_class != null); if (get_this_type () != null && (!in_creation_method_with_chainup || current_method.body != b)) { - var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_data_type_for_symbol (current_type_symbol), b.source_reference)); + var ref_call = new CCodeFunctionCall (get_dup_func_expression (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol), b.source_reference)); ref_call.add_argument (get_this_cexpression ()); // never increase reference count for self in finalizers to avoid infinite recursion on following unref @@ -2196,7 +2196,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (get_this_type () != null) { // assign "self" for type parameters - ccode.add_declaration(get_ccode_name (get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self")); + ccode.add_declaration(get_ccode_name (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self")); ccode.add_assignment (new CCodeIdentifier ("self"), new CCodeMemberAccess.pointer (outer_block, "self")); } @@ -2296,7 +2296,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { this_type.value_owned = true; if (this_type.is_disposable () && !is_in_destructor ()) { // reference count for self is not increased in finalizers - var this_value = new GLibValue (get_data_type_for_symbol (current_type_symbol), new CCodeIdentifier ("self"), true); + var this_value = new GLibValue (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol), new CCodeIdentifier ("self"), true); ccode.add_expression (destroy_value (this_value)); } } @@ -4973,7 +4973,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { foreach (MemberInitializer init in expr.get_object_initializer ()) { if (init.symbol_reference is Field) { var f = (Field) init.symbol_reference; - var instance_target_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol); + var instance_target_type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) f.parent_symbol); var typed_inst = transform_value (new GLibValue (expr.type_reference, instance, true), instance_target_type, init); store_field (f, typed_inst, init.initializer.target_value, init.source_reference); @@ -4983,7 +4983,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } else if (init.symbol_reference is Property) { var p = (Property) init.symbol_reference; - var instance_target_type = get_data_type_for_symbol ((TypeSymbol) p.parent_symbol); + var instance_target_type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) p.parent_symbol); var typed_inst = transform_value (new GLibValue (expr.type_reference, instance), instance_target_type, init); var inst_ma = new MemberAccess.simple ("fake"); inst_ma.target_value = typed_inst; @@ -6191,37 +6191,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return generated_external_symbols.add (external_symbol); } - public static DataType get_data_type_for_symbol (TypeSymbol sym) { - DataType type = null; - - if (sym is Class) { - type = new ObjectType ((Class) sym); - } else if (sym is Interface) { - type = new ObjectType ((Interface) sym); - } else if (sym is Struct) { - var st = (Struct) sym; - if (st.is_boolean_type ()) { - type = new BooleanType (st); - } else if (st.is_integer_type ()) { - type = new IntegerType (st); - } else if (st.is_floating_type ()) { - type = new FloatingType (st); - } else { - type = new StructValueType (st); - } - } else if (sym is Enum) { - type = new EnumValueType ((Enum) sym); - } else if (sym is ErrorDomain) { - type = new ErrorType ((ErrorDomain) sym, null); - } else if (sym is ErrorCode) { - type = new ErrorType ((ErrorDomain) sym.parent_symbol, (ErrorCode) sym); - } else { - Report.error (null, "internal error: `%s' is not a supported type".printf (sym.get_full_name ())); - return new InvalidType (); - } - - return type; - } public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression, bool on_error = false) { unowned Struct? st = type.type_symbol as Struct; @@ -6396,7 +6365,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { push_context (new EmitContext ()); push_function (function); - var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true); + var dest_struct = new GLibValue (SemanticAnalyzer.get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true); foreach (Field f in st.get_fields ()) { if (f.binding == MemberBinding.INSTANCE) { var value = load_field (f, load_this_parameter ((TypeSymbol) st)); diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala index e520ede93..3d082b21e 100644 --- a/codegen/valaccodememberaccessmodule.vala +++ b/codegen/valaccodememberaccessmodule.vala @@ -594,7 +594,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { pub_inst = get_cvalue_ (instance); } - var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol); + var instance_target_type = SemanticAnalyzer.get_data_type_for_symbol (field.parent_symbol); unowned Class? cl = instance_target_type.type_symbol as Class; bool is_gtypeinstance = ((instance_target_type.type_symbol == cl) && (cl == null || !cl.is_compact)); @@ -812,7 +812,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { /* Convenience method returning access to "this" */ public override TargetValue load_this_parameter (TypeSymbol sym) { - var param = new Parameter ("this", get_data_type_for_symbol (sym)); + var param = new Parameter ("this", SemanticAnalyzer.get_data_type_for_symbol (sym)); return load_parameter (param); } diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index 7a4b30394..860783b89 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -511,7 +511,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { // as closures have block data parameter if (m.binding == MemberBinding.INSTANCE) { var cself = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self"); - ccode.add_declaration (get_ccode_name (get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self")); + ccode.add_declaration (get_ccode_name (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self")); ccode.add_assignment (new CCodeIdentifier ("self"), cself); } diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index 83c1a67a3..e432e6060 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -302,7 +302,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { push_function (function); - var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true); + var dest_struct = new GLibValue (SemanticAnalyzer.get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true); unowned Struct sym = st; while (sym.base_struct != null) { sym = sym.base_struct; diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index c30384d38..65fafeada 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -1294,7 +1294,7 @@ public class Vala.GIRWriter : CodeVisitor { DataType instance_type = null; if (instance) { - instance_type = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol); + instance_type = SemanticAnalyzer.get_data_type_for_symbol (m.parent_symbol); } write_params_and_return (params, m.get_type_parameters (), return_type, get_ccode_array_length (m), return_comment, false, instance_type); @@ -1340,7 +1340,7 @@ public class Vala.GIRWriter : CodeVisitor { write_doc (get_method_comment (m)); - var datatype = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol); + var datatype = SemanticAnalyzer.get_data_type_for_symbol (m.parent_symbol); List<TypeParameter>? type_params = null; if (m.parent_symbol is Class) { type_params = ((Class) m.parent_symbol).get_type_parameters (); diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 51e69c3d7..67c36a537 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -1396,7 +1396,7 @@ public class Vala.GTypeModule : GErrorModule { var function = new CCodeFunction (name, return_type); function.modifiers = CCodeModifiers.STATIC; - var this_type = get_data_type_for_symbol (cl); + var this_type = SemanticAnalyzer.get_data_type_for_symbol (cl); function.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type))); push_function (function); ccode.add_return (expression); @@ -1468,7 +1468,7 @@ public class Vala.GTypeModule : GErrorModule { if (iface.get_attribute ("GenericAccessors") != null) { foreach (TypeParameter p in iface.get_type_parameters ()) { GenericType p_type = new GenericType (p); - DataType p_data_type = p_type.get_actual_type (get_data_type_for_symbol (cl), null, cl); + DataType p_data_type = p_type.get_actual_type (SemanticAnalyzer.get_data_type_for_symbol (cl), null, cl); add_generic_accessor_function ("get_%s_type".printf (p.name.down ()), "GType", @@ -2118,7 +2118,7 @@ public class Vala.GTypeModule : GErrorModule { foreach (TypeParameter p in iface.get_type_parameters ()) { string method_name = "get_%s_type".printf (p.name.down ()); var vdeclarator = new CCodeFunctionDeclarator (method_name); - var this_type = get_data_type_for_symbol (iface); + var this_type = SemanticAnalyzer.get_data_type_for_symbol (iface); vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type))); var vdecl = new CCodeDeclaration ("GType"); @@ -2127,7 +2127,7 @@ public class Vala.GTypeModule : GErrorModule { method_name = "get_%s_dup_func".printf (p.name.down ()); vdeclarator = new CCodeFunctionDeclarator (method_name); - this_type = get_data_type_for_symbol (iface); + this_type = SemanticAnalyzer.get_data_type_for_symbol (iface); vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type))); vdecl = new CCodeDeclaration ("GBoxedCopyFunc"); @@ -2136,7 +2136,7 @@ public class Vala.GTypeModule : GErrorModule { method_name = "get_%s_destroy_func".printf (p.name.down ()); vdeclarator = new CCodeFunctionDeclarator (method_name); - this_type = get_data_type_for_symbol (iface); + this_type = SemanticAnalyzer.get_data_type_for_symbol (iface); vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type))); vdecl = new CCodeDeclaration ("GDestroyNotify"); |