Fixes bug 635095.
List<EmitContext> emit_context_stack = new ArrayList<EmitContext> ();
+ public CCodeLineDirective? current_line = null;
+
+ List<CCodeLineDirective> line_directive_stack = new ArrayList<CCodeLineDirective> ();
+
public Symbol current_symbol { get { return emit_context.current_symbol; } }
public TryStatement current_try {
}
this.emit_context = emit_context;
+ if (ccode != null) {
+ ccode.current_line = current_line;
+ }
}
public void pop_context () {
if (emit_context_stack.size > 0) {
this.emit_context = emit_context_stack[emit_context_stack.size - 1];
emit_context_stack.remove_at (emit_context_stack.size - 1);
+ if (ccode != null) {
+ ccode.current_line = current_line;
+ }
} else {
this.emit_context = null;
}
}
+ public void push_line (SourceReference? source_reference) {
+ line_directive_stack.add (current_line);
+ if (source_reference != null) {
+ current_line = new CCodeLineDirective (source_reference.file.filename, source_reference.first_line);
+ if (ccode != null) {
+ ccode.current_line = current_line;
+ }
+ }
+ }
+
+ public void pop_line () {
+ current_line = line_directive_stack[line_directive_stack.size - 1];
+ line_directive_stack.remove_at (line_directive_stack.size - 1);
+ if (ccode != null) {
+ ccode.current_line = current_line;
+ }
+ }
+
public void push_function (CCodeFunction func) {
emit_context.ccode_stack.add (ccode);
emit_context.ccode = func;
+ ccode.current_line = current_line;
}
public void pop_function () {
emit_context.ccode = emit_context.ccode_stack[emit_context.ccode_stack.size - 1];
emit_context.ccode_stack.remove_at (emit_context.ccode_stack.size - 1);
+ if (ccode != null) {
+ ccode.current_line = current_line;
+ }
}
public bool add_symbol_declaration (CCodeFile decl_space, Symbol sym, string name) {
}
public override void visit_enum (Enum en) {
+ push_line (en.source_reference);
+
en.accept_children (this);
if (en.comment != null) {
if (!en.is_private_symbol ()) {
generate_enum_declaration (en, internal_header_file);
}
+
+ pop_line ();
}
public void visit_member (Symbol m) {
}
public override void visit_constant (Constant c) {
+ push_line (c.source_reference);
+
if (c.parent_symbol is Block) {
// local constant
var cinitializer = get_cvalue (c.value);
ccode.add_declaration (type_name, new CCodeVariableDeclarator ("%s%s".printf (c.get_cname (), arr), cinitializer), CCodeModifiers.STATIC);
+ } else {
+ generate_constant_declaration (c, cfile, true);
- return;
+ if (!c.is_internal_symbol ()) {
+ generate_constant_declaration (c, header_file);
+ }
+ if (!c.is_private_symbol ()) {
+ generate_constant_declaration (c, internal_header_file);
+ }
}
- generate_constant_declaration (c, cfile, true);
-
- if (!c.is_internal_symbol ()) {
- generate_constant_declaration (c, header_file);
- }
- if (!c.is_private_symbol ()) {
- generate_constant_declaration (c, internal_header_file);
- }
+ pop_line ();
}
public void generate_field_declaration (Field f, CCodeFile decl_space) {
}
public override void visit_field (Field f) {
+ push_line (f.source_reference);
visit_member (f);
check_type (f.variable_type);
pop_context ();
}
+
+ pop_line ();
}
public bool is_constant_ccode_expression (CCodeExpression cexpr) {
public override void visit_property_accessor (PropertyAccessor acc) {
push_context (new EmitContext (acc));
+ push_line (acc.source_reference);
var prop = (Property) acc.prop;
}
if (acc.source_type == SourceFileType.FAST) {
+ pop_line ();
return;
}
cfile.add_function (function);
}
+ pop_line ();
pop_context ();
}
}
foreach (Statement stmt in b.get_statements ()) {
+ push_line (stmt.source_reference);
stmt.emit (this);
+ pop_line ();
}
// free in reverse order
public override void visit_method (Method m) {
push_context (new EmitContext (m));
+ push_line (m.source_reference);
bool in_gobject_creation_method = false;
bool in_fundamental_creation_method = false;
pop_function ();
cfile.add_function (cmain);
}
+
+ pop_line ();
}
public virtual CCodeParameter generate_parameter (Parameter param, CCodeFile decl_space, Map<int,CCodeParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
}
public override void visit_creation_method (CreationMethod m) {
+ push_line (m.source_reference);
+
bool visible = !m.is_private_symbol ();
visit_method (m);
cfile.add_function (vfunc);
}
+
+ pop_line ();
}
}
public override void visit_struct (Struct st) {
push_context (new EmitContext (st));
+ push_line (st.source_reference);
var old_instance_finalize_context = instance_finalize_context;
instance_finalize_context = new EmitContext ();
instance_finalize_context = old_instance_finalize_context;
+ pop_line ();
pop_context ();
}
return;
}
+ push_line (cl.source_reference);
if (class_has_readable_properties (cl) || cl.get_type_parameters ().size > 0) {
add_get_property_function (cl);
}
if (class_has_writable_properties (cl) || cl.get_type_parameters ().size > 0) {
add_set_property_function (cl);
}
+ pop_line ();
}
public override void generate_class_init (Class cl) {
}
public override void visit_constructor (Constructor c) {
+ push_line (c.source_reference);
+
if (c.binding == MemberBinding.CLASS || c.binding == MemberBinding.STATIC) {
in_static_or_class_context = true;
} else {
in_static_or_class_context = false;
in_constructor = false;
+
+ pop_line ();
}
public override string get_dynamic_property_getter_cname (DynamicProperty prop) {
public override void visit_method_call (MethodCall expr) {
if (expr.call is MemberAccess) {
+ push_line (expr.source_reference);
+
var ma = expr.call as MemberAccess;
if (ma.inner != null && ma.inner.symbol_reference == gobject_type &&
(ma.member_name == "new" || ma.member_name == "newv")) {
}
}
}
+
+ pop_line ();
}
base.visit_method_call (expr);
public override void visit_class (Class cl) {
push_context (new EmitContext (cl));
+ push_line (cl.source_reference);
var old_param_spec_struct = param_spec_struct;
var old_prop_enum = prop_enum;
add_g_value_take_function (cl);
var ref_count = new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "ref_count"), new CCodeConstant ("1"));
- instance_init_context.ccode.add_expression (ref_count);
+ push_context (instance_init_context);
+ ccode.add_expression (ref_count);
+ pop_context ();
}
instance_init_context = old_instance_init_context;
instance_finalize_context = old_instance_finalize_context;
+ pop_line ();
pop_context ();
}
ccast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (cl.get_lower_case_cname (null))));
var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast, "finalize"));
ccall.add_argument (new CCodeIdentifier ("obj"));
- instance_finalize_context.ccode.add_expression (ccall);
+ push_context (instance_finalize_context);
+ ccode.add_expression (ccall);
+ pop_context ();
}
cfile.add_function_declaration (instance_finalize_context.ccode);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
ccall.add_argument (new CCodeIdentifier ("self"));
- instance_finalize_context.ccode.add_expression (ccall);
+ push_context (instance_finalize_context);
+ ccode.add_expression (ccall);
+ pop_context ();
}
cfile.add_function (instance_finalize_context.ccode);
public override void visit_interface (Interface iface) {
push_context (new EmitContext (iface));
+ push_line (iface.source_reference);
if (iface.get_cname().length < 3) {
iface.error = true;
cfile.add_type_member_declaration (type_fun.get_source_declaration ());
cfile.add_type_member_definition (type_fun.get_definition ());
+ pop_line ();
pop_context ();
}
base.visit_struct (st);
if (st.has_type_id) {
+ push_line (st.source_reference);
var type_fun = new StructRegisterFunction (st, context);
type_fun.init_from_type (false, false);
cfile.add_type_member_definition (type_fun.get_definition ());
+ pop_line ();
}
}
base.visit_enum (en);
if (en.has_type_id) {
+ push_line (en.source_reference);
var type_fun = new EnumRegisterFunction (en, context);
type_fun.init_from_type (false, false);
cfile.add_type_member_definition (type_fun.get_definition ());
+ pop_line ();
}
}
}
// to_string() on a gtype enum
+ push_line (expr.source_reference);
var temp_var = get_temp_variable (new CType ("GEnumValue*"), false, expr, false);
emit_temp_var (temp_var);
ccode.add_assignment (get_variable_cexpression (temp_var.name), get_value);
var is_null_value = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, get_variable_cexpression (temp_var.name), new CCodeIdentifier ("NULL"));
set_cvalue (expr, new CCodeConditionalExpression (is_null_value, new CCodeMemberAccess.pointer (get_variable_cexpression (temp_var.name), "value_name"), new CCodeIdentifier ("NULL")));
+ pop_line ();
}
public override void visit_property (Property prop) {