}
public static string get_ccode_lower_case_name (CodeNode node, string? infix = null) {
- var sym = node as Symbol;
+ unowned Symbol? sym = node as Symbol;
if (sym != null) {
if (infix == null) {
infix = "";
return "%s%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), infix, get_ccode_lower_case_suffix (sym));
}
} else if (node is ErrorType) {
- var type = (ErrorType) node;
+ unowned ErrorType type = (ErrorType) node;
if (type.error_domain == null) {
if (infix == null) {
return "g_error";
return get_ccode_lower_case_name (type.error_code, infix);
}
} else if (node is DelegateType) {
- var type = (DelegateType) node;
+ unowned DelegateType type = (DelegateType) node;
return get_ccode_lower_case_name (type.delegate_symbol, infix);
} else if (node is PointerType) {
- var type = (PointerType) node;
+ unowned PointerType type = (PointerType) node;
return get_ccode_lower_case_name (type.base_type, infix);
} else if (node is GenericType) {
return "valageneric";
} else if (node is VoidType) {
return "valavoid";
} else {
- var type = (DataType) node;
+ unowned DataType type = (DataType) node;
return get_ccode_lower_case_name (type.data_type, infix);
}
}
}
public static string get_ccode_type_check_function (TypeSymbol sym) {
- var cl = sym as Class;
+ unowned Class? cl = sym as Class;
var a = sym.get_attribute_string ("CCode", "type_check_function");
if (cl != null && a != null) {
return a;
return a.get_double ("array_length_pos");
}
if (node is Parameter) {
- var param = (Parameter) node;
+ unowned Parameter param = (Parameter) node;
return get_ccode_pos (param) + 0.1;
} else {
return -3;
return a.get_double ("delegate_target_pos");
}
if (node is Parameter) {
- var param = (Parameter) node;
+ unowned Parameter param = (Parameter) node;
return get_ccode_pos (param) + 0.1;
} else {
return -3;
return a.get_double ("destroy_notify_pos");
}
if (node is Parameter) {
- var param = (Parameter) node;
+ unowned Parameter param = (Parameter) node;
return get_ccode_pos (param) + 0.1;
} else {
return -3;
public static string get_ccode_constructv_name (CreationMethod m) {
const string infix = "constructv";
- var parent = m.parent_symbol as Class;
+ unowned Class parent = (Class) m.parent_symbol;
if (m.name == ".new") {
return "%s%s".printf (get_ccode_lower_case_prefix (parent), infix);
*/
public class Vala.CCodeAttribute : AttributeCache {
private weak CodeNode node;
- private weak Symbol sym;
+ private weak Symbol? sym;
private Attribute ccode;
public string name {
if (ccode != null && ccode.has_argument ("free_function_address_of")) {
_free_function_address_of = ccode.get_bool ("free_function_address_of");
} else {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.base_class != null) {
_free_function_address_of = get_ccode_free_function_address_of (cl.base_class);
} else {
if (ccode != null && ccode.has_argument ("pos")) {
_pos = ccode.get_double ("pos");
} else {
- var param = (Parameter) node;
- var sym = param.parent_symbol;
- if (sym is Callable) {
- _pos = ((Callable) sym).get_parameters ().index_of (param) + 1.0;
+ unowned Parameter param = (Parameter) node;
+ unowned Callable? callable = param.parent_symbol as Callable;
+ if (callable != null) {
+ _pos = callable.get_parameters ().index_of (param) + 1.0;
} else {
_pos = 0.0;
}
_vfunc_name = ccode.get_string ("vfunc_name");
}
if (_vfunc_name == null) {
- Method m = node as Method;
+ unowned Method? m = node as Method;
if (m != null && m.signal_reference != null) {
_vfunc_name = get_ccode_lower_case_name (m.signal_reference);
} else {
public bool finish_instance {
get {
if (_finish_instance == null) {
- Method m = node as Method;
+ unowned Method? m = node as Method;
bool is_creation_method = m is CreationMethod;
if (ccode == null || m == null || m.is_abstract || m.is_virtual) {
_finish_instance = !is_creation_method;
}
private string get_default_name () {
- var sym = node as Symbol;
if (sym != null) {
if (sym is Constant && !(sym is EnumValue)) {
if (sym.parent_symbol is Block) {
}
return cname;
} else if (sym is CreationMethod) {
- var m = (CreationMethod) sym;
+ unowned CreationMethod m = (CreationMethod) sym;
string infix;
if (m.parent_symbol is Struct) {
infix = "init";
} else if (sym is DynamicMethod) {
return "_dynamic_%s%d".printf (sym.name, dynamic_method_id++);
} else if (sym is Method) {
- var m = (Method) sym;
+ unowned Method m = (Method) sym;
if (m.is_async_callback) {
return "%s_co".printf (get_ccode_real_name ((Method) m.parent_symbol));
}
return "%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name);
}
} else if (sym is PropertyAccessor) {
- var acc = (PropertyAccessor) sym;
+ unowned PropertyAccessor acc = (PropertyAccessor) sym;
var t = (TypeSymbol) acc.prop.parent_symbol;
if (acc.readable) {
private string? get_default_ref_function () {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_fundamental ()) {
return "%sref".printf (lower_case_prefix);
} else if (cl.base_class != null) {
private string? get_default_unref_function () {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_fundamental ()) {
return "%sunref".printf (lower_case_prefix);
} else if (cl.base_class != null) {
private string? get_default_free_function () {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.base_class != null) {
return get_ccode_free_function (cl.base_class);
}
} else if (sym is ErrorType) {
return "G_TYPE_ERROR";
} else if (sym is Struct) {
- var st = (Struct) sym;
+ unowned Struct st = (Struct) sym;
if (!get_ccode_has_type_id (st)) {
- var base_struct = st.base_struct;
+ unowned Struct? base_struct = st.base_struct;
if (base_struct != null) {
return get_ccode_type_id (base_struct);
}
return get_ccode_upper_case_name (st, "TYPE_");
}
} else if (sym is Enum) {
- var en = (Enum) sym;
+ unowned Enum en = (Enum) sym;
if (get_ccode_has_type_id (en)) {
return get_ccode_upper_case_name (en, "TYPE_");
} else {
private string get_default_marshaller_type_name () {
if (sym != null) {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.base_class != null) {
return get_ccode_marshaller_type_name (cl.base_class);
} else if (!cl.is_compact) {
return "BOXED";
}
} else if (sym is Enum) {
- var en = (Enum) sym;
+ unowned Enum en = (Enum) sym;
if (get_ccode_has_type_id (en)) {
if (en.is_flags) {
return "FLAGS";
}
return "POINTER";
} else if (sym is Struct) {
- var st = (Struct) sym;
- var base_st = st.base_struct;
+ unowned Struct st = (Struct) sym;
+ unowned Struct? base_st = st.base_struct;
while (base_st != null) {
if (get_ccode_has_type_id (base_st)) {
return get_ccode_marshaller_type_name (base_st);
return "POINTER";
}
} else if (sym is Parameter) {
- var param = (Parameter) sym;
+ unowned Parameter param = (Parameter) sym;
if (param.direction != ParameterDirection.IN) {
return "POINTER";
} else {
private string get_default_get_value_function () {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_fundamental ()) {
return get_ccode_lower_case_name (cl, "value_get_");
} else if (cl.base_class != null) {
return "g_value_get_boxed";
}
} else if (sym is Enum) {
- var en = (Enum) sym;
+ unowned Enum en = (Enum) sym;
if (get_ccode_has_type_id (en)) {
if (en.is_flags) {
return "g_value_get_flags";
}
return "g_value_get_pointer";
} else if (sym is Struct) {
- var st = (Struct) sym;
- var base_st = st.base_struct;
+ unowned Struct st = (Struct) sym;
+ unowned Struct? base_st = st.base_struct;
while (base_st != null) {
if (get_ccode_has_type_id (base_st)) {
return get_ccode_get_value_function (base_st);
private string get_default_set_value_function () {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_fundamental ()) {
return get_ccode_lower_case_name (cl, "value_set_");
} else if (cl.base_class != null) {
return "g_value_set_boxed";
}
} else if (sym is Enum) {
- var en = (Enum) sym;
+ unowned Enum en = (Enum) sym;
if (get_ccode_has_type_id (en)) {
if (en.is_flags) {
return "g_value_set_flags";
}
return "g_value_set_pointer";
} else if (sym is Struct) {
- var st = (Struct) sym;
- var base_st = st.base_struct;
+ unowned Struct st = (Struct) sym;
+ unowned Struct? base_st = st.base_struct;
while (base_st != null) {
if (get_ccode_has_type_id (base_st)) {
return get_ccode_set_value_function (base_st);
private string get_default_take_value_function () {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_fundamental ()) {
return get_ccode_lower_case_name (cl, "value_take_");
} else if (cl.base_class != null) {
return "g_value_take_boxed";
}
} else if (sym is Enum) {
- var en = (Enum) sym;
+ unowned Enum en = (Enum) sym;
if (get_ccode_has_type_id (en)) {
if (en.is_flags) {
return "g_value_take_flags";
}
return "g_value_set_pointer";
} else if (sym is Struct) {
- var st = (Struct) sym;
- var base_st = st.base_struct;
+ unowned Struct st = (Struct) sym;
+ unowned Struct? base_st = st.base_struct;
while (base_st != null) {
if (get_ccode_has_type_id (base_st)) {
return get_ccode_take_value_function (base_st);
private string get_default_param_spec_function () {
if (node is Symbol) {
if (sym is Class) {
- var cl = (Class) sym;
+ unowned Class cl = (Class) sym;
if (cl.is_fundamental ()) {
return get_ccode_lower_case_name (cl, "param_spec_");
} else if (cl.base_class != null) {
}
return "g_param_spec_pointer";
} else if (sym is Enum) {
- var e = sym as Enum;
+ unowned Enum e = (Enum) sym;
if (get_ccode_has_type_id (e)) {
if (e.is_flags) {
return "g_param_spec_flags";
if (sym is Enum) {
return "0";
} else if (sym is Struct) {
- var st = (Struct) sym;
- var base_st = st.base_struct;
-
+ unowned Struct st = (Struct) sym;
+ unowned Struct? base_st = st.base_struct;
if (base_st != null) {
return get_ccode_default_value (base_st);
}
private string get_default_real_name () {
if (sym is CreationMethod) {
- var m = (CreationMethod) sym;
- var parent = m.parent_symbol as Class;
+ unowned CreationMethod m = (CreationMethod) sym;
+ unowned Class? parent = m.parent_symbol as Class;
if (parent == null || parent.is_compact) {
return name;
return "%s%s_%s".printf (get_ccode_lower_case_prefix (parent), infix, m.name);
}
} else if (sym is Method) {
- var m = (Method) sym;
+ unowned Method m = (Method) sym;
if (m.base_method != null || m.base_interface_method != null) {
string m_name;
if (m.signal_reference != null) {
return name;
}
} else if (sym is PropertyAccessor) {
- var acc = (PropertyAccessor) sym;
- var prop = (Property) acc.prop;
+ unowned PropertyAccessor acc = (PropertyAccessor) sym;
+ unowned Property prop = (Property) acc.prop;
if (prop.base_property != null || prop.base_interface_property != null) {
if (acc.readable) {
return "%sreal_get_%s".printf (get_ccode_lower_case_prefix (prop.parent_symbol), prop.name);
private string get_default_const_name () {
if (node is DataType) {
- var type = (DataType) node;
+ unowned DataType type = (DataType) node;
string ptr;
TypeSymbol t;
// FIXME: workaround to make constant arrays possible
private bool get_default_array_length () {
if (node is Parameter) {
- var param = (Parameter) node;
+ unowned Parameter param = (Parameter) node;
if (param.base_parameter != null) {
return get_ccode_array_length (param.base_parameter);
}
} else if (node is Method) {
- var method = (Method) node;
+ unowned Method method = (Method) node;
if (method.base_method != null && method.base_method != method) {
return get_ccode_array_length (method.base_method);
} else if (method.base_interface_method != null && method.base_interface_method != method) {
private bool get_default_array_null_terminated () {
if (node is Parameter) {
- var param = (Parameter) node;
+ unowned Parameter param = (Parameter) node;
if (param.base_parameter != null) {
return get_ccode_array_null_terminated (param.base_parameter);
}
} else if (node is Method) {
- var method = (Method) node;
+ unowned Method method = (Method) node;
if (method.base_method != null && method.base_method != method) {
return get_ccode_array_null_terminated (method.base_method);
} else if (method.base_interface_method != null && method.base_interface_method != method) {