Commit ca020bf0 authored by Jürg Billeter's avatar Jürg Billeter

Drop POSIX profile

parent 5ea6dc05
......@@ -56,14 +56,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return;
}
CCodeFunctionCall gnew;
if (context.profile == Profile.POSIX) {
cfile.add_include ("stdlib.h");
gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
} else {
gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (get_ccode_name (expr.element_type)));
}
var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (get_ccode_name (expr.element_type)));
bool first = true;
CCodeExpression cexpr = null;
......@@ -88,12 +82,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
gnew.add_argument (cexpr);
if (context.profile == Profile.POSIX) {
var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
csizeof.add_argument (new CCodeIdentifier (get_ccode_name (expr.element_type)));
gnew.add_argument (csizeof);
}
var temp_var = get_temp_variable (expr.value_type, true, expr);
var name_cnode = get_variable_cexpression (temp_var.name);
int i = 0;
......
......@@ -606,24 +606,16 @@ public class Vala.CCodeAttribute : AttributeCache {
} else if (node is ErrorType) {
return "GError*";
} else if (node is GenericType) {
if (CodeContext.get ().profile == Profile.GOBJECT) {
var type = (GenericType) node;
if (type.value_owned) {
return "gpointer";
} else {
return "gconstpointer";
}
var type = (GenericType) node;
if (type.value_owned) {
return "gpointer";
} else {
return "void *";
return "gconstpointer";
}
} else if (node is MethodType) {
return "gpointer";
} else if (node is NullType) {
if (CodeContext.get ().profile == Profile.GOBJECT) {
return "gpointer";
} else {
return "void *";
}
return "gpointer";
} else if (node is PointerType) {
var type = (PointerType) node;
if (type.base_type.data_type != null && type.base_type.data_type.is_reference_type ()) {
......
......@@ -440,56 +440,54 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
unichar_type = new IntegerType (unichar_struct);
}
if (context.profile == Profile.GOBJECT) {
var glib_ns = root_symbol.scope.lookup ("GLib");
gtype_type = (TypeSymbol) glib_ns.scope.lookup ("Type");
gobject_type = (TypeSymbol) glib_ns.scope.lookup ("Object");
gerror_type = new ErrorType (null, null);
glist_type = (Class) glib_ns.scope.lookup ("List");
gslist_type = (Class) glib_ns.scope.lookup ("SList");
gnode_type = (Class) glib_ns.scope.lookup ("Node");
gqueue_type = (Class) glib_ns.scope.lookup ("Queue");
gvaluearray_type = (Class) glib_ns.scope.lookup ("ValueArray");
gstringbuilder_type = (TypeSymbol) glib_ns.scope.lookup ("StringBuilder");
garray_type = (TypeSymbol) glib_ns.scope.lookup ("Array");
gbytearray_type = (TypeSymbol) glib_ns.scope.lookup ("ByteArray");
gptrarray_type = (TypeSymbol) glib_ns.scope.lookup ("PtrArray");
gthreadpool_type = (TypeSymbol) glib_ns.scope.lookup ("ThreadPool");
gdestroynotify_type = new DelegateType ((Delegate) glib_ns.scope.lookup ("DestroyNotify"));
gquark_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Quark"));
gvalue_type = (Struct) glib_ns.scope.lookup ("Value");
gvariant_type = (Class) glib_ns.scope.lookup ("Variant");
mutex_type = (Struct) glib_ns.scope.lookup ("StaticRecMutex");
if (context.require_glib_version (2, 32)) {
gmutex_type = (Struct) glib_ns.scope.lookup ("Mutex");
grecmutex_type = (Struct) glib_ns.scope.lookup ("RecMutex");
grwlock_type = (Struct) glib_ns.scope.lookup ("RWLock");
gcond_type = (Struct) glib_ns.scope.lookup ("Cond");
}
type_module_type = (TypeSymbol) glib_ns.scope.lookup ("TypeModule");
regex_type = new ObjectType ((Class) root_symbol.scope.lookup ("GLib").scope.lookup ("Regex"));
if (context.module_init_method != null) {
foreach (Parameter parameter in context.module_init_method.get_parameters ()) {
if (parameter.variable_type.data_type == type_module_type) {
in_plugin = true;
module_init_param_name = parameter.name;
break;
}
}
if (!in_plugin) {
Report.error (context.module_init_method.source_reference, "[ModuleInit] requires a parameter of type `GLib.TypeModule'");
var glib_ns = root_symbol.scope.lookup ("GLib");
gtype_type = (TypeSymbol) glib_ns.scope.lookup ("Type");
gobject_type = (TypeSymbol) glib_ns.scope.lookup ("Object");
gerror_type = new ErrorType (null, null);
glist_type = (Class) glib_ns.scope.lookup ("List");
gslist_type = (Class) glib_ns.scope.lookup ("SList");
gnode_type = (Class) glib_ns.scope.lookup ("Node");
gqueue_type = (Class) glib_ns.scope.lookup ("Queue");
gvaluearray_type = (Class) glib_ns.scope.lookup ("ValueArray");
gstringbuilder_type = (TypeSymbol) glib_ns.scope.lookup ("StringBuilder");
garray_type = (TypeSymbol) glib_ns.scope.lookup ("Array");
gbytearray_type = (TypeSymbol) glib_ns.scope.lookup ("ByteArray");
gptrarray_type = (TypeSymbol) glib_ns.scope.lookup ("PtrArray");
gthreadpool_type = (TypeSymbol) glib_ns.scope.lookup ("ThreadPool");
gdestroynotify_type = new DelegateType ((Delegate) glib_ns.scope.lookup ("DestroyNotify"));
gquark_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Quark"));
gvalue_type = (Struct) glib_ns.scope.lookup ("Value");
gvariant_type = (Class) glib_ns.scope.lookup ("Variant");
mutex_type = (Struct) glib_ns.scope.lookup ("StaticRecMutex");
if (context.require_glib_version (2, 32)) {
gmutex_type = (Struct) glib_ns.scope.lookup ("Mutex");
grecmutex_type = (Struct) glib_ns.scope.lookup ("RecMutex");
grwlock_type = (Struct) glib_ns.scope.lookup ("RWLock");
gcond_type = (Struct) glib_ns.scope.lookup ("Cond");
}
type_module_type = (TypeSymbol) glib_ns.scope.lookup ("TypeModule");
regex_type = new ObjectType ((Class) root_symbol.scope.lookup ("GLib").scope.lookup ("Regex"));
if (context.module_init_method != null) {
foreach (Parameter parameter in context.module_init_method.get_parameters ()) {
if (parameter.variable_type.data_type == type_module_type) {
in_plugin = true;
module_init_param_name = parameter.name;
break;
}
}
dbus_proxy_type = (TypeSymbol) glib_ns.scope.lookup ("DBusProxy");
if (!in_plugin) {
Report.error (context.module_init_method.source_reference, "[ModuleInit] requires a parameter of type `GLib.TypeModule'");
}
}
dbus_proxy_type = (TypeSymbol) glib_ns.scope.lookup ("DBusProxy");
header_file = new CCodeFile ();
header_file.is_header = true;
internal_header_file = new CCodeFile ();
......@@ -522,12 +520,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// generate C header file for public API
if (context.header_filename != null) {
bool ret;
if (context.profile == Profile.GOBJECT) {
ret = header_file.store (context.header_filename, null, context.version_header, false, "G_BEGIN_DECLS", "G_END_DECLS");
} else {
ret = header_file.store (context.header_filename, null, context.version_header, false);
}
bool ret = header_file.store (context.header_filename, null, context.version_header, false, "G_BEGIN_DECLS", "G_END_DECLS");
if (!ret) {
Report.error (null, "unable to open `%s' for writing".printf (context.header_filename));
}
......@@ -535,12 +528,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// generate C header file for internal API
if (context.internal_header_filename != null) {
bool ret;
if (context.profile == Profile.GOBJECT) {
ret = internal_header_file.store (context.internal_header_filename, null, context.version_header, false, "G_BEGIN_DECLS", "G_END_DECLS");
} else {
ret = internal_header_file.store (context.internal_header_filename, null, context.version_header, false);
}
bool ret = internal_header_file.store (context.internal_header_filename, null, context.version_header, false, "G_BEGIN_DECLS", "G_END_DECLS");
if (!ret) {
Report.error (null, "unable to open `%s' for writing".printf (context.internal_header_filename));
}
......@@ -722,12 +710,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
wrappers = new HashSet<string> (str_hash, str_equal);
generated_external_symbols = new HashSet<Symbol> ();
if (context.profile == Profile.GOBJECT) {
header_file.add_include ("glib.h");
internal_header_file.add_include ("glib.h");
cfile.add_include ("glib.h");
cfile.add_include ("glib-object.h");
}
header_file.add_include ("glib.h");
internal_header_file.add_include ("glib.h");
cfile.add_include ("glib.h");
cfile.add_include ("glib-object.h");
source_file.accept_children (this);
......@@ -3004,7 +2990,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
public CCodeExpression? get_destroy_func_expression (DataType type, bool is_chainup = false) {
if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type || type.data_type == gqueue_type)) {
if (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type || type.data_type == gqueue_type) {
// create wrapper function to free list elements if necessary
bool elements_require_free = false;
......@@ -3088,17 +3074,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_variable_cexpression (func_name);
}
} else if (type is ArrayType) {
if (context.profile == Profile.POSIX) {
return new CCodeIdentifier ("free");
} else {
return new CCodeIdentifier ("g_free");
}
return new CCodeIdentifier ("g_free");
} else if (type is PointerType) {
if (context.profile == Profile.POSIX) {
return new CCodeIdentifier ("free");
} else {
return new CCodeIdentifier ("g_free");
}
return new CCodeIdentifier ("g_free");
} else {
return new CCodeConstant ("NULL");
}
......@@ -3299,42 +3277,40 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
/* set freed references to NULL to prevent further use */
var ccomma = new CCodeCommaExpression ();
if (context.profile == Profile.GOBJECT) {
if (type.data_type != null && !is_reference_counting (type.data_type) &&
(type.data_type.is_subtype_of (gstringbuilder_type)
|| type.data_type.is_subtype_of (garray_type)
|| type.data_type.is_subtype_of (gbytearray_type)
|| type.data_type.is_subtype_of (gptrarray_type))) {
ccall.add_argument (new CCodeConstant ("TRUE"));
} else if (type.data_type == gthreadpool_type) {
ccall.add_argument (new CCodeConstant ("FALSE"));
ccall.add_argument (new CCodeConstant ("TRUE"));
} else if (type is ArrayType) {
var array_type = (ArrayType) type;
if (requires_destroy (array_type.element_type)) {
CCodeExpression csizeexpr = null;
if (((GLibValue) value).array_length_cvalues != null) {
csizeexpr = get_array_length_cvalue (value);
} else if (get_array_null_terminated (value)) {
requires_array_length = true;
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
len_call.add_argument (cvar);
csizeexpr = len_call;
} else {
csizeexpr = get_array_length_cexpr (value);
}
if (type.data_type != null && !is_reference_counting (type.data_type) &&
(type.data_type.is_subtype_of (gstringbuilder_type)
|| type.data_type.is_subtype_of (garray_type)
|| type.data_type.is_subtype_of (gbytearray_type)
|| type.data_type.is_subtype_of (gptrarray_type))) {
ccall.add_argument (new CCodeConstant ("TRUE"));
} else if (type.data_type == gthreadpool_type) {
ccall.add_argument (new CCodeConstant ("FALSE"));
ccall.add_argument (new CCodeConstant ("TRUE"));
} else if (type is ArrayType) {
var array_type = (ArrayType) type;
if (requires_destroy (array_type.element_type)) {
CCodeExpression csizeexpr = null;
if (((GLibValue) value).array_length_cvalues != null) {
csizeexpr = get_array_length_cvalue (value);
} else if (get_array_null_terminated (value)) {
requires_array_length = true;
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
len_call.add_argument (cvar);
csizeexpr = len_call;
} else {
csizeexpr = get_array_length_cexpr (value);
}
if (csizeexpr != null) {
var st = array_type.element_type.data_type as Struct;
if (st != null && !array_type.element_type.nullable) {
ccall.call = new CCodeIdentifier (append_struct_array_free (st));
ccall.add_argument (csizeexpr);
} else {
requires_array_free = true;
ccall.call = new CCodeIdentifier ("_vala_array_free");
ccall.add_argument (csizeexpr);
ccall.add_argument (new CCodeCastExpression (get_destroy_func_expression (array_type.element_type), "GDestroyNotify"));
}
if (csizeexpr != null) {
var st = array_type.element_type.data_type as Struct;
if (st != null && !array_type.element_type.nullable) {
ccall.call = new CCodeIdentifier (append_struct_array_free (st));
ccall.add_argument (csizeexpr);
} else {
requires_array_free = true;
ccall.call = new CCodeIdentifier ("_vala_array_free");
ccall.add_argument (csizeexpr);
ccall.add_argument (new CCodeCastExpression (get_destroy_func_expression (array_type.element_type), "GDestroyNotify"));
}
}
}
......@@ -3777,12 +3753,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
public override void visit_boolean_literal (BooleanLiteral expr) {
if (context.profile == Profile.GOBJECT) {
set_cvalue (expr, new CCodeConstant (expr.value ? "TRUE" : "FALSE"));
} else {
cfile.add_include ("stdbool.h");
set_cvalue (expr, new CCodeConstant (expr.value ? "true" : "false"));
}
set_cvalue (expr, new CCodeConstant (expr.value ? "TRUE" : "FALSE"));
}
public override void visit_character_literal (CharacterLiteral expr) {
......@@ -3895,9 +3866,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
public override void visit_null_literal (NullLiteral expr) {
if (context.profile != Profile.GOBJECT) {
cfile.add_include ("stddef.h");
}
set_cvalue (expr, new CCodeConstant ("NULL"));
var array_type = expr.target_type as ArrayType;
......@@ -4157,9 +4125,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
dup0_func = dupid.name;
} else if (add_wrapper (dup0_func)) {
string pointer_cname = "gpointer";
if (context.profile == Profile.POSIX) {
pointer_cname = "void*";
}
var dup0_fun = new CCodeFunction (dup0_func, pointer_cname);
dup0_fun.add_parameter (new CCodeParameter ("self", pointer_cname));
dup0_fun.modifiers = CCodeModifiers.STATIC;
......@@ -5010,7 +4975,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var cl = expr.type_reference.data_type as Class;
var iface = expr.type_reference.data_type as Interface;
if (context.profile == Profile.GOBJECT && (iface != null || (cl != null && !cl.is_compact))) {
if (iface != null || (cl != null && !cl.is_compact)) {
// checked cast for strict subtypes of GTypeInstance
if (expr.is_silent_cast) {
var cexpr = get_cvalue (expr.inner);
......@@ -5251,38 +5216,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
set_cvalue (expr, new CCodeConstant ("%s %s".printf (left, right)));
return;
} else {
if (context.profile == Profile.POSIX) {
// convert to strcat(strcpy(malloc(1+strlen(a)+strlen(b)),a),b)
var strcat = new CCodeFunctionCall (new CCodeIdentifier ("strcat"));
var strcpy = new CCodeFunctionCall (new CCodeIdentifier ("strcpy"));
var malloc = new CCodeFunctionCall (new CCodeIdentifier ("malloc"));
var strlen_a = new CCodeFunctionCall (new CCodeIdentifier ("strlen"));
strlen_a.add_argument(cleft);
var strlen_b = new CCodeFunctionCall (new CCodeIdentifier ("strlen"));
strlen_b.add_argument(cright);
var newlength = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier("1"),
new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, strlen_a, strlen_b));
malloc.add_argument(newlength);
strcpy.add_argument(malloc);
strcpy.add_argument(cleft);
strcat.add_argument(strcpy);
strcat.add_argument(cright);
set_cvalue (expr, strcat);
} else {
// convert to g_strconcat (a, b, NULL)
var temp_value = create_temp_value (expr.value_type, false, expr);
// convert to g_strconcat (a, b, NULL)
var temp_value = create_temp_value (expr.value_type, false, expr);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_strconcat"));
ccall.add_argument (cleft);
ccall.add_argument (cright);
ccall.add_argument (new CCodeConstant("NULL"));
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_strconcat"));
ccall.add_argument (cleft);
ccall.add_argument (cright);
ccall.add_argument (new CCodeConstant("NULL"));
ccode.add_assignment (get_cvalue_ (temp_value), ccall);
expr.target_value = temp_value;
}
ccode.add_assignment (get_cvalue_ (temp_value), ccall);
expr.target_value = temp_value;
return;
}
} else if (expr.operator == BinaryOperator.EQUALITY
......@@ -5507,13 +5450,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
bool unboxing = (type is ValueType && type.nullable
&& target_type is ValueType && !target_type.nullable);
bool gvalue_boxing = (context.profile == Profile.GOBJECT
&& target_type != null
bool gvalue_boxing = (target_type != null
&& target_type.data_type == gvalue_type
&& !(type is NullType)
&& get_ccode_type_id (type) != "G_TYPE_VALUE");
bool gvariant_boxing = (context.profile == Profile.GOBJECT
&& target_type != null
bool gvariant_boxing = (target_type != null
&& target_type.data_type == gvariant_type
&& !(type is NullType)
&& type.data_type != gvariant_type);
......
......@@ -55,12 +55,10 @@ public class Vala.CCodeCompiler {
if (!context.compile_only) {
pc += " --libs";
}
if (context.profile == Profile.GOBJECT) {
use_pkgconfig = true;
pc += " gobject-2.0";
if (context.thread) {
pc += " gthread-2.0";
}
use_pkgconfig = true;
pc += " gobject-2.0";
if (context.thread) {
pc += " gthread-2.0";
}
foreach (string pkg in context.get_packages ()) {
if (package_exists (pkg)) {
......
......@@ -206,12 +206,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
}
public override void visit_loop (Loop stmt) {
if (context.profile == Profile.GOBJECT) {
ccode.open_while (new CCodeConstant ("TRUE"));
} else {
cfile.add_include ("stdbool.h");
ccode.open_while (new CCodeConstant ("true"));
}
ccode.open_while (new CCodeConstant ("TRUE"));
stmt.body.emit (this);
......
......@@ -48,8 +48,6 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
// Enum.VALUE.to_string()
var en = (Enum) ma.inner.value_type.data_type;
ccall.call = new CCodeIdentifier (generate_enum_tostring_function (en));
} else if (context.profile == Profile.POSIX && ma.inner != null && ma.inner.value_type != null && ma.inner.value_type.data_type == string_type.data_type && ma.member_name == "printf") {
ccall.call = new CCodeIdentifier (generate_string_printf_function ());
}
} else if (itype is SignalType) {
var sig_type = (SignalType) itype;
......@@ -123,12 +121,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
}
if (m is CreationMethod && m.parent_symbol is Class) {
if (context.profile == Profile.GOBJECT) {
if (!((Class) m.parent_symbol).is_compact) {
ccall.add_argument (get_variable_cexpression ("object_type"));
}
} else {
ccall.add_argument (get_this_cexpression ());
if (!((Class) m.parent_symbol).is_compact) {
ccall.add_argument (get_variable_cexpression ("object_type"));
}
if (!current_class.is_compact) {
......@@ -281,7 +275,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
param.accept (this);
}
generate_dynamic_method_wrapper ((DynamicMethod) m);
} else if (m is CreationMethod && context.profile == Profile.GOBJECT && m.parent_symbol is Class) {
} else if (m is CreationMethod && m.parent_symbol is Class) {
ccode.add_assignment (get_this_cexpression (), new CCodeCastExpression (ccall, CCodeBaseModule.get_ccode_name (current_class) + "*"));
if (current_method.body.captured) {
......@@ -837,80 +831,5 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
return to_string_func;
}
private string generate_string_printf_function () {
if (!add_wrapper ("string_printf")) {
// wrapper already defined
return "string_printf";
}
// declaration
var function = new CCodeFunction ("string_printf", "char*");
function.add_parameter (new CCodeParameter ("format", "const char*"));
function.add_parameter (new CCodeParameter.with_ellipsis ());
function.modifiers = CCodeModifiers.STATIC;
// definition
push_context (new EmitContext ());
push_function (function);
ccode.add_declaration ("int", new CCodeVariableDeclarator ("length"));
ccode.add_declaration ("va_list", new CCodeVariableDeclarator ("ap"));
ccode.add_declaration ("char*", new CCodeVariableDeclarator ("result"));
var va_start = new CCodeFunctionCall (new CCodeIdentifier ("va_start"));
va_start.add_argument (new CCodeIdentifier ("ap"));
va_start.add_argument (new CCodeIdentifier ("format"));
ccode.add_expression (va_start);
var vsnprintf = new CCodeFunctionCall (new CCodeIdentifier ("vsnprintf"));
vsnprintf.add_argument (new CCodeConstant ("NULL"));
vsnprintf.add_argument (new CCodeConstant ("0"));
vsnprintf.add_argument (new CCodeIdentifier ("format"));
vsnprintf.add_argument (new CCodeIdentifier ("ap"));
ccode.add_assignment (new CCodeIdentifier ("length"), new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, vsnprintf, new CCodeConstant ("1")));
var va_end = new CCodeFunctionCall (new CCodeIdentifier ("va_end"));
va_end.add_argument (new CCodeIdentifier ("ap"));
ccode.add_expression (va_end);
var malloc = new CCodeFunctionCall (new CCodeIdentifier ("malloc"));
malloc.add_argument (new CCodeIdentifier ("length"));
ccode.add_assignment (new CCodeIdentifier ("result"), malloc);
va_start = new CCodeFunctionCall (new CCodeIdentifier ("va_start"));
va_start.add_argument (new CCodeIdentifier ("ap"));
va_start.add_argument (new CCodeIdentifier ("format"));
ccode.add_expression (va_start);
vsnprintf = new CCodeFunctionCall (new CCodeIdentifier ("vsnprintf"));
vsnprintf.add_argument (new CCodeIdentifier ("result"));
vsnprintf.add_argument (new CCodeIdentifier ("length"));
vsnprintf.add_argument (new CCodeIdentifier ("format"));
vsnprintf.add_argument (new CCodeIdentifier ("ap"));
ccode.add_expression (vsnprintf);
va_end = new CCodeFunctionCall (new CCodeIdentifier ("va_end"));
va_end.add_argument (new CCodeIdentifier ("ap"));
ccode.add_expression (va_end);
ccode.add_return (new CCodeIdentifier ("result"));
// append to file
cfile.add_include ("stdarg.h");
cfile.add_function_declaration (function);
cfile.add_function (function);
pop_context ();
return "string_printf";
}
}
......@@ -827,24 +827,22 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
cmain.add_parameter (new CCodeParameter ("argv", "char **"));
push_function (cmain);
if (context.profile == Profile.GOBJECT) {
if (context.mem_profiler) {
var mem_profiler_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_mem_set_vtable"));
mem_profiler_init_call.line = cmain.line;
mem_profiler_init_call.add_argument (new CCodeConstant ("glib_mem_profiler_table"));
ccode.add_expression (mem_profiler_init_call);
}
if (context.thread) {
var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init"));
thread_init_call.line = cmain.line;
thread_init_call.add_argument (new CCodeConstant ("NULL"));
ccode.add_expression (thread_init_call);
}
if (context.mem_profiler) {
var mem_profiler_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_mem_set_vtable"));
mem_profiler_init_call.line = cmain.line;
mem_profiler_init_call.add_argument (new CCodeConstant ("glib_mem_profiler_table"));
ccode.add_expression (mem_profiler_init_call);
}
ccode.add_expression (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
if (context.thread) {
var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init"));
thread_init_call.line = cmain.line;
thread_init_call.add_argument (new CCodeConstant ("NULL"));
ccode.add_expression (thread_init_call);
}
ccode.add_expression (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
var main_call = new CCodeFunctionCall (new CCodeIdentifier (function.name));
if (m.get_parameters ().size == 1) {
main_call.add_argument (new CCodeIdentifier ("argv"));
......
......@@ -53,16 +53,14 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
return;
}
if (context.profile == Profile.GOBJECT) {
if (get_ccode_has_type_id (st)) {
decl_space.add_type_declaration (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (get_ccode_lower_case_name (st, null));
decl_space.add_type_declaration (new CCodeMacroReplacement (get_ccode_type_id (st), macro));
var type_fun = new StructRegisterFunction (st, context);
type_fun.init_from_type (false, true);
decl_space.add_type_member_declaration (type_fun.get_declaration ());
}
if (get_ccode_has_type_id (st)) {
decl_space.add_type_declaration (new CCodeNewline ());
var macro = "(%s_get_type ())".printf (get_ccode_lower_case_name (st, null));
decl_space.add_type_declaration (new CCodeMacroReplacement (get_ccode_type_id (st), macro));
var type_fun = new StructRegisterFunction (st, context);
type_fun.init_from_type (false, true);
decl_space.add_type_member_declaration (type_fun.get_declaration ());
}
var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (st)));
......@@ -204,17 +202,10 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
ccode.add_declaration (get_ccode_name (st) + "*", new CCodeVariableDeclarator ("dup"));
if (context.profile == Profile.GOBJECT) {
var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
creation_call.add_argument (new CCodeConstant (get_ccode_name (st)));
creation_call.add_argument (new CCodeConstant ("1"));
ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
} else if (context.profile == Profile.POSIX) {
var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
creation_call.add_argument (new CCodeConstant ("1"));
creation_call.add_argument (new CCodeIdentifier ("sizeof (%s*)".printf (get_ccode_name (st))));
ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
}
var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
creation_call.add_argument (new CCodeConstant (get_ccode_name (st)));
creation_call.add_argument (new CCodeConstant ("1"));
ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
if (st.is_disposable ()) {
var copy_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_copy_function (st)));
......@@ -257,15 +248,9 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
ccode.add_expression (destroy_call);
}
if (context.profile == Profile.GOBJECT) {
var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
free_call.add_argument (new CCodeIdentifier ("self"));
ccode.add_expression (free_call);
} else if (context.profile == Profile.POSIX) {
var free_call = new CCodeFunctionCall (new CCodeIdentifier ("free"));
free_call.add_argument (new CCodeIdentifier ("self"));
ccode.add_expression (free_call);
}
var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
free_call.add_argument (new CCodeIdentifier ("self"));
ccode.add_expression (free_call);
pop_function ();
......
......@@ -207,10 +207,7 @@ class Vala.Compiler {
context.thread = thread;
context.mem_profiler = mem_profiler;
context.save_temps = save_temps;
if (profile == "posix") {
context.profile = Profile.POSIX;
context.add_define ("POSIX");
} else if (profile == "gobject-2.0" || profile == "gobject" || profile == null) {
if (profile == "gobject-2.0" || profile == "gobject" || profile == null) {
// default profile
context.profile = Profile.GOBJECT;
context.add_define ("GOBJECT");
......@@ -234,33 +231,26 @@ class Vala.Compiler {
context.add_define ("VALA_0_%d".printf (i));
}