From c7229010b2a88d3cf5e1f1f07e815635489bc788 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Tue, 4 Sep 2007 20:17:31 +0000 Subject: [PATCH] emit line directives in debug mode 2007-09-04 Juerg Billeter * vala/valacodenode.vala, ccode/valaccodebreakstatement.vala, ccode/valaccodecasestatement.vala, ccode/valaccodecontinuestatement.vala, ccode/valaccodedeclaration.vala, ccode/valaccodedostatement.vala, ccode/valaccodeexpressionstatement.vala, ccode/valaccodeforstatement.vala, ccode/valaccodefunction.vala, ccode/valaccodeifstatement.vala, ccode/valaccodereturnstatement.vala, ccode/valaccodeswitchstatement.vala, ccode/valaccodevariabledeclarator.vala, ccode/valaccodewhilestatement.vala, ccode/valaccodewriter.vala, gobject/valacodegenerator.vala, gobject/valacodegeneratormethod.vala, gobject/valacodegeneratorsourcefile.vala: emit line directives in debug mode svn path=/trunk/; revision=580 --- ChangeLog | 14 +++++++ ccode/valaccodebreakstatement.vala | 4 +- ccode/valaccodecasestatement.vala | 4 +- ccode/valaccodecontinuestatement.vala | 4 +- ccode/valaccodedeclaration.vala | 2 +- ccode/valaccodedostatement.vala | 4 +- ccode/valaccodeexpressionstatement.vala | 4 +- ccode/valaccodeforstatement.vala | 2 +- ccode/valaccodefunction.vala | 3 +- ccode/valaccodeifstatement.vala | 4 +- ccode/valaccodereturnstatement.vala | 4 +- ccode/valaccodeswitchstatement.vala | 2 +- ccode/valaccodevariabledeclarator.vala | 2 +- ccode/valaccodewhilestatement.vala | 4 +- ccode/valaccodewriter.vala | 21 ++++++---- gobject/valacodegenerator.vala | 67 ++++++++++++++++++++------------ gobject/valacodegeneratormethod.vala | 34 ++++++++++++---- gobject/valacodegeneratorsourcefile.vala | 1 + vala/valacodenode.vala | 2 +- 19 files changed, 120 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2059314..8302778 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-09-04 Jürg Billeter + + * vala/valacodenode.vala, ccode/valaccodebreakstatement.vala, + ccode/valaccodecasestatement.vala, ccode/valaccodecontinuestatement.vala, + ccode/valaccodedeclaration.vala, ccode/valaccodedostatement.vala, + ccode/valaccodeexpressionstatement.vala, ccode/valaccodeforstatement.vala, + ccode/valaccodefunction.vala, ccode/valaccodeifstatement.vala, + ccode/valaccodereturnstatement.vala, ccode/valaccodeswitchstatement.vala, + ccode/valaccodevariabledeclarator.vala, + ccode/valaccodewhilestatement.vala, ccode/valaccodewriter.vala, + gobject/valacodegenerator.vala, gobject/valacodegeneratormethod.vala, + gobject/valacodegeneratorsourcefile.vala: emit line directives in debug + mode + 2007-09-03 Mathias Hasselmann * vapi/glib-2.0.vala: add string.to_double diff --git a/ccode/valaccodebreakstatement.vala b/ccode/valaccodebreakstatement.vala index 3a2f033..5685d58 100644 --- a/ccode/valaccodebreakstatement.vala +++ b/ccode/valaccodebreakstatement.vala @@ -1,6 +1,6 @@ /* valaccodebreakstatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,7 @@ using GLib; */ public class Vala.CCodeBreakStatement : CCodeStatement { public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("break;"); writer.write_newline (); } diff --git a/ccode/valaccodecasestatement.vala b/ccode/valaccodecasestatement.vala index a75efa9..111336d 100644 --- a/ccode/valaccodecasestatement.vala +++ b/ccode/valaccodecasestatement.vala @@ -1,6 +1,6 @@ /* valaccodecasestatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -47,7 +47,7 @@ public class Vala.CCodeCaseStatement : CCodeStatement { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("case "); expression.write (writer); writer.write_string (":"); diff --git a/ccode/valaccodecontinuestatement.vala b/ccode/valaccodecontinuestatement.vala index 02c65d9..482f424 100644 --- a/ccode/valaccodecontinuestatement.vala +++ b/ccode/valaccodecontinuestatement.vala @@ -1,6 +1,6 @@ /* valaccodecontinuestatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,7 @@ using GLib; */ public class Vala.CCodeContinueStatement : CCodeStatement { public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("continue;"); writer.write_newline (); } diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala index 5a70cc3..9416db0 100644 --- a/ccode/valaccodedeclaration.vala +++ b/ccode/valaccodedeclaration.vala @@ -54,7 +54,7 @@ public class Vala.CCodeDeclaration : CCodeStatement { public override void write (CCodeWriter! writer) { if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.EXTERN)) != 0) { // combined declaration and initialization for static and extern variables - writer.write_indent (); + writer.write_indent (line); if ((modifiers & CCodeModifiers.STATIC) != 0) { writer.write_string ("static "); } diff --git a/ccode/valaccodedostatement.vala b/ccode/valaccodedostatement.vala index 4dd2dc1..8e0fd07 100644 --- a/ccode/valaccodedostatement.vala +++ b/ccode/valaccodedostatement.vala @@ -1,6 +1,6 @@ /* valaccodedostatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -42,7 +42,7 @@ public class Vala.CCodeDoStatement : CCodeStatement { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("do"); /* while shouldn't be on a separate line */ diff --git a/ccode/valaccodeexpressionstatement.vala b/ccode/valaccodeexpressionstatement.vala index e247a94..b0c208d 100644 --- a/ccode/valaccodeexpressionstatement.vala +++ b/ccode/valaccodeexpressionstatement.vala @@ -1,6 +1,6 @@ /* valaccodeexpressionstatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -36,7 +36,7 @@ public class Vala.CCodeExpressionStatement : CCodeStatement { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); if (expression != null) { expression.write (writer); } diff --git a/ccode/valaccodeforstatement.vala b/ccode/valaccodeforstatement.vala index 3760092..2d5b3a6 100644 --- a/ccode/valaccodeforstatement.vala +++ b/ccode/valaccodeforstatement.vala @@ -64,7 +64,7 @@ public class Vala.CCodeForStatement : CCodeStatement { public override void write (CCodeWriter! writer) { bool first; - writer.write_indent (); + writer.write_indent (line); writer.write_string ("for ("); first = true; diff --git a/ccode/valaccodefunction.vala b/ccode/valaccodefunction.vala index 855d6d0..1ead254 100644 --- a/ccode/valaccodefunction.vala +++ b/ccode/valaccodefunction.vala @@ -82,7 +82,7 @@ public class Vala.CCodeFunction : CCodeNode { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { writer.write_string ("static "); } @@ -108,7 +108,6 @@ public class Vala.CCodeFunction : CCodeNode { if (block == null) { writer.write_string (";"); } else { - writer.write_newline (); block.write (writer); writer.write_newline (); } diff --git a/ccode/valaccodeifstatement.vala b/ccode/valaccodeifstatement.vala index 426c590..93a9de5 100644 --- a/ccode/valaccodeifstatement.vala +++ b/ccode/valaccodeifstatement.vala @@ -1,6 +1,6 @@ /* valaccodeifstatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -55,7 +55,7 @@ public class Vala.CCodeIfStatement : CCodeStatement { public override void write (CCodeWriter! writer) { if (!else_if) { - writer.write_indent (); + writer.write_indent (line); } else { writer.write_string (" "); } diff --git a/ccode/valaccodereturnstatement.vala b/ccode/valaccodereturnstatement.vala index 192953d..de3e2a9 100644 --- a/ccode/valaccodereturnstatement.vala +++ b/ccode/valaccodereturnstatement.vala @@ -1,6 +1,6 @@ /* valaccodereturnstatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -36,7 +36,7 @@ public class Vala.CCodeReturnStatement : CCodeStatement { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("return"); if (return_expression != null) { diff --git a/ccode/valaccodeswitchstatement.vala b/ccode/valaccodeswitchstatement.vala index 596b972..2e63c1a 100644 --- a/ccode/valaccodeswitchstatement.vala +++ b/ccode/valaccodeswitchstatement.vala @@ -57,7 +57,7 @@ public class Vala.CCodeSwitchStatement : CCodeStatement { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("switch ("); expression.write (writer); writer.write_string (")"); diff --git a/ccode/valaccodevariabledeclarator.vala b/ccode/valaccodevariabledeclarator.vala index 790b776..c0772b9 100644 --- a/ccode/valaccodevariabledeclarator.vala +++ b/ccode/valaccodevariabledeclarator.vala @@ -60,7 +60,7 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator { public override void write_initialization (CCodeWriter! writer) { if (initializer != null) { - writer.write_indent (); + writer.write_indent (line); writer.write_string (name); writer.write_string (" = "); diff --git a/ccode/valaccodewhilestatement.vala b/ccode/valaccodewhilestatement.vala index 658b771..3be28b9 100644 --- a/ccode/valaccodewhilestatement.vala +++ b/ccode/valaccodewhilestatement.vala @@ -1,6 +1,6 @@ /* valaccodewhilestatement.vala * - * Copyright (C) 2006 Jürg Billeter + * Copyright (C) 2006-2007 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -42,7 +42,7 @@ public class Vala.CCodeWhileStatement : CCodeStatement { } public override void write (CCodeWriter! writer) { - writer.write_indent (); + writer.write_indent (line); writer.write_string ("while ("); condition.write (writer); diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala index 3393983..60939a8 100644 --- a/ccode/valaccodewriter.vala +++ b/ccode/valaccodewriter.vala @@ -46,14 +46,17 @@ public class Vala.CCodeWriter : Object { } /** + * Specifies whether to emit line directives. + */ + public bool line_directives { get; set; } + + /** * Specifies whether the output stream is at the beginning of a line. */ public bool bol { - get { - return _bol; - } + get { return _bol; } } - + private string _filename; private string temp_filename; private bool file_exists; @@ -104,14 +107,16 @@ public class Vala.CCodeWriter : Object { /** * Writes tabs according to the current indent level. */ - public void write_indent () { - int i; - + public void write_indent (CCodeLineDirective line = null) { + if (line_directives && line != null) { + line.write (this); + } + if (!bol) { stream.putc ('\n'); } - for (i = 0; i < indent; i++) { + for (int i = 0; i < indent; i++) { stream.putc ('\t'); } diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index e035c77..f2632bb 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -871,7 +871,7 @@ public class Vala.CodeGenerator : CodeVisitor { var ccomma = new CCodeCommaExpression (); - var temp_decl = get_temp_variable_declarator (decl.type_reference); + var temp_decl = get_temp_variable_declarator (decl.type_reference, true, decl); temp_vars.insert (0, temp_decl); ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), rhs)); @@ -907,14 +907,18 @@ public class Vala.CodeGenerator : CodeVisitor { list.ccodenode = clist; } } - - private VariableDeclarator get_temp_variable_declarator (TypeReference! type, bool takes_ownership = true) { + + private VariableDeclarator get_temp_variable_declarator (TypeReference! type, bool takes_ownership = true, CodeNode node_reference = null) { var decl = new VariableDeclarator ("_tmp%d".printf (next_temp_var_id)); decl.type_reference = type.copy (); decl.type_reference.is_ref = false; decl.type_reference.is_out = false; decl.type_reference.takes_ownership = takes_ownership; - + + if (node_reference != null) { + decl.source_reference = node_reference.source_reference; + } + next_temp_var_id++; return decl; @@ -1093,7 +1097,7 @@ public class Vala.CodeGenerator : CodeVisitor { return; } - var full_expr_decl = get_temp_variable_declarator (expr.static_type); + var full_expr_decl = get_temp_variable_declarator (expr.static_type, true, expr); expr.temp_vars.add (full_expr_decl); var expr_list = new CCodeCommaExpression (); @@ -1117,6 +1121,8 @@ public class Vala.CodeGenerator : CodeVisitor { var cdecl = new CCodeDeclaration (decl.type_reference.get_cname (true, !decl.type_reference.takes_ownership)); var vardecl = new CCodeVariableDeclarator (decl.name); + // sets #line + decl.ccodenode = vardecl; cdecl.add_declarator (vardecl); if (decl.type_reference.data_type != null && decl.type_reference.data_type.is_reference_type ()) { @@ -1275,7 +1281,7 @@ public class Vala.CodeGenerator : CodeVisitor { public override void visit_switch_statement (SwitchStatement! stmt) { // we need a temporary variable to save the property value - var temp_decl = get_temp_variable_declarator (stmt.expression.static_type); + var temp_decl = get_temp_variable_declarator (stmt.expression.static_type, true, stmt); stmt.expression.temp_vars.insert (0, temp_decl); var ctemp = new CCodeIdentifier (temp_decl.name); @@ -1389,7 +1395,8 @@ public class Vala.CodeGenerator : CodeVisitor { public override void visit_end_foreach_statement (ForeachStatement! stmt) { var cblock = new CCodeBlock (); - CCodeForStatement cfor; + // sets #line + stmt.ccodenode = cblock; var cfrag = new CCodeFragment (); append_temp_decl (cfrag, stmt.collection.temp_vars); @@ -1397,7 +1404,9 @@ public class Vala.CodeGenerator : CodeVisitor { var collection_backup = stmt.collection_variable_declarator; var ccoldecl = new CCodeDeclaration (collection_backup.type_reference.get_cname ()); - ccoldecl.add_declarator (new CCodeVariableDeclarator.with_initializer (collection_backup.name, (CCodeExpression) stmt.collection.ccodenode)); + var ccolvardecl = new CCodeVariableDeclarator.with_initializer (collection_backup.name, (CCodeExpression) stmt.collection.ccodenode); + ccolvardecl.line = cblock.line; + ccoldecl.add_declarator (ccolvardecl); cblock.add_statement (ccoldecl); if (stmt.tree_can_fail && stmt.collection.can_fail) { @@ -1407,8 +1416,6 @@ public class Vala.CodeGenerator : CodeVisitor { cblock.add_statement (cfrag); } - stmt.ccodenode = cblock; - if (stmt.collection.static_type.data_type is Array) { var arr = (Array) stmt.collection.static_type.data_type; @@ -1517,7 +1524,9 @@ public class Vala.CodeGenerator : CodeVisitor { var it_name = "%s_it".printf (stmt.variable_name); var citdecl = new CCodeDeclaration (stmt.collection.static_type.get_cname ()); - citdecl.add_declarator (new CCodeVariableDeclarator (it_name)); + var citvardecl = new CCodeVariableDeclarator (it_name); + citvardecl.line = cblock.line; + citdecl.add_declarator (citvardecl); cblock.add_statement (citdecl); var cbody = new CCodeBlock (); @@ -1539,7 +1548,9 @@ public class Vala.CodeGenerator : CodeVisitor { } var cdecl = new CCodeDeclaration (stmt.type_reference.get_cname ()); - cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (stmt.variable_name, element_expr)); + var cvardecl = new CCodeVariableDeclarator.with_initializer (stmt.variable_name, element_expr); + cvardecl.line = cblock.line; + cdecl.add_declarator (cvardecl); cbody.add_statement (cdecl); cbody.add_statement (stmt.body.ccodenode); @@ -1559,7 +1570,9 @@ public class Vala.CodeGenerator : CodeVisitor { var it_method = (Method) iterable_type.scope.lookup ("iterator"); var it_ccall = new CCodeFunctionCall (new CCodeIdentifier (it_method.get_cname ())); it_ccall.add_argument (new InstanceCast (new CCodeIdentifier (collection_backup.name), iterable_type)); - citdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (it_name, it_ccall)); + var citvardecl = new CCodeVariableDeclarator.with_initializer (it_name, it_ccall); + citvardecl.line = cblock.line; + citdecl.add_declarator (citvardecl); cblock.add_statement (citdecl); var cbody = new CCodeBlock (); @@ -1588,7 +1601,9 @@ public class Vala.CodeGenerator : CodeVisitor { } var cdecl = new CCodeDeclaration (stmt.type_reference.get_cname ()); - cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (stmt.variable_name, element_expr)); + var cvardecl = new CCodeVariableDeclarator.with_initializer (stmt.variable_name, element_expr); + cvardecl.line = cblock.line; + cdecl.add_declarator (cvardecl); cbody.add_statement (cdecl); cbody.add_statement (stmt.body.ccodenode); @@ -1597,7 +1612,9 @@ public class Vala.CodeGenerator : CodeVisitor { var next_ccall = new CCodeFunctionCall (new CCodeIdentifier (next_method.get_cname ())); next_ccall.add_argument (new CCodeIdentifier (it_name)); - cblock.add_statement (new CCodeWhileStatement (next_ccall, cbody)); + var cwhile = new CCodeWhileStatement (next_ccall, cbody); + cwhile.line = cblock.line; + cblock.add_statement (cwhile); } if (memory_management) { @@ -1605,7 +1622,9 @@ public class Vala.CodeGenerator : CodeVisitor { if (decl.type_reference.takes_ownership) { var ma = new MemberAccess.simple (decl.name); ma.symbol_reference = decl; - cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma))); + var cunref = new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma)); + cunref.line = cblock.line; + cblock.add_statement (cunref); } } } @@ -1688,7 +1707,7 @@ public class Vala.CodeGenerator : CodeVisitor { return; } - var return_expr_decl = get_temp_variable_declarator (expr.static_type); + var return_expr_decl = get_temp_variable_declarator (expr.static_type, true, expr); var ccomma = new CCodeCommaExpression (); ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (return_expr_decl.name), (CCodeExpression) expr.ccodenode)); @@ -1747,7 +1766,7 @@ public class Vala.CodeGenerator : CodeVisitor { // return array length if appropriate if (current_method != null && !current_method.no_array_length && current_return_type.data_type is Array) { - var return_expr_decl = get_temp_variable_declarator (stmt.return_expression.static_type); + var return_expr_decl = get_temp_variable_declarator (stmt.return_expression.static_type, true, stmt); var ccomma = new CCodeCommaExpression (); ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (return_expr_decl.name), (CCodeExpression) stmt.return_expression.ccodenode)); @@ -1939,7 +1958,7 @@ public class Vala.CodeGenerator : CodeVisitor { } var ce = new CCodeCommaExpression (); - var temp_var = get_temp_variable_declarator (expr.static_type); + var temp_var = get_temp_variable_declarator (expr.static_type, true, expr); var name_cnode = new CCodeIdentifier (temp_var.name); int i = 0; @@ -2173,7 +2192,7 @@ public class Vala.CodeGenerator : CodeVisitor { var ccomma = new CCodeCommaExpression (); // assign current value to temp variable - var temp_decl = get_temp_variable_declarator (prop.type_reference); + var temp_decl = get_temp_variable_declarator (prop.type_reference, true, expr); temp_vars.insert (0, temp_decl); ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), (CCodeExpression) expr.inner.ccodenode)); @@ -2236,7 +2255,7 @@ public class Vala.CodeGenerator : CodeVisitor { return ccall; } else { - var decl = get_temp_variable_declarator (expr.static_type, false); + var decl = get_temp_variable_declarator (expr.static_type, false, expr); temp_vars.insert (0, decl); var ctemp = new CCodeIdentifier (decl.name); @@ -2307,7 +2326,7 @@ public class Vala.CodeGenerator : CodeVisitor { } if (expr.ref_leaked) { - var decl = get_temp_variable_declarator (expr.static_type); + var decl = get_temp_variable_declarator (expr.static_type, true, expr); temp_vars.insert (0, decl); temp_ref_vars.insert (0, decl); expr.ccodenode = new CCodeParenthesizedExpression (new CCodeAssignment (new CCodeIdentifier (get_variable_cname (decl.name)), (CCodeExpression) expr.ccodenode)); @@ -2471,7 +2490,7 @@ public class Vala.CodeGenerator : CodeVisitor { // GObject cast if (expr.is_silent_cast) { var ccomma = new CCodeCommaExpression (); - var temp_decl = get_temp_variable_declarator (expr.inner.static_type); + var temp_decl = get_temp_variable_declarator (expr.inner.static_type, true, expr); temp_vars.add (temp_decl); @@ -2511,7 +2530,7 @@ public class Vala.CodeGenerator : CodeVisitor { public override void visit_reference_transfer_expression (ReferenceTransferExpression! expr) { /* (tmp = var, var = null, tmp) */ var ccomma = new CCodeCommaExpression (); - var temp_decl = get_temp_variable_declarator (expr.static_type); + var temp_decl = get_temp_variable_declarator (expr.static_type, true, expr); temp_vars.insert (0, temp_decl); var cvar = new CCodeIdentifier (temp_decl.name); diff --git a/gobject/valacodegeneratormethod.vala b/gobject/valacodegeneratormethod.vala index 509ce68..df4fd15 100644 --- a/gobject/valacodegeneratormethod.vala +++ b/gobject/valacodegeneratormethod.vala @@ -94,6 +94,7 @@ public class Vala.CodeGenerator { } function = new CCodeFunction (m.get_real_cname (), m.return_type.get_cname ()); + m.ccodenode = function; CCodeFunctionDeclarator vdeclarator = null; CCodeFormalParameter instance_param = null; @@ -208,6 +209,7 @@ public class Vala.CodeGenerator { * have a body, e.g. Vala.Parser.parse_file () */ if (m.body != null) { function.block = (CCodeBlock) m.body.ccodenode; + function.block.line = function.line; var cinit = new CCodeFragment (); function.block.prepend_statement (cinit); @@ -232,7 +234,9 @@ public class Vala.CodeGenerator { cinit.append (cdecl); } else if (m.instance) { - cinit.append (create_method_type_check_statement (m, cl, true, "self")); + var ccheckstmt = create_method_type_check_statement (m, cl, true, "self"); + ccheckstmt.line = function.line; + cinit.append (ccheckstmt); } } foreach (FormalParameter param in m.get_parameters ()) { @@ -240,6 +244,7 @@ public class Vala.CodeGenerator { if (t != null && t.is_reference_type () && !param.type_reference.is_out) { var type_check = create_method_type_check_statement (m, t, param.type_reference.non_null, param.name); if (type_check != null) { + type_check.line = function.line; cinit.append (type_check); } } @@ -320,6 +325,7 @@ public class Vala.CodeGenerator { if (m.is_abstract || m.is_virtual) { var vfunc = new CCodeFunction (m.get_cname (), m.return_type.get_cname ()); + vfunc.line = function.line; var this_type = new TypeReference (); this_type.data_type = (DataType) m.parent_symbol; @@ -382,12 +388,15 @@ public class Vala.CodeGenerator { vcall.add_argument (new CCodeIdentifier (cparam.name)); } + CCodeStatement cstmt; if (m.return_type.data_type == null && m.return_type.type_parameter == null) { - vblock.add_statement (new CCodeExpressionStatement (vcall)); + cstmt = new CCodeExpressionStatement (vcall); } else { /* pass method return value */ - vblock.add_statement (new CCodeReturnStatement (vcall)); + cstmt = new CCodeReturnStatement (vcall); } + cstmt.line = vfunc.line; + vblock.add_statement (cstmt); if (visible) { header_type_member_declaration.append (vfunc.copy ()); @@ -426,28 +435,39 @@ public class Vala.CodeGenerator { if (is_possible_entry_point (m, ref return_value, ref args_parameter)) { // m is possible entry point, add appropriate startup code var cmain = new CCodeFunction ("main", "int"); + cmain.line = function.line; cmain.add_parameter (new CCodeFormalParameter ("argc", "int")); cmain.add_parameter (new CCodeFormalParameter ("argv", "char **")); var main_block = new CCodeBlock (); 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")); main_block.add_statement (new CCodeExpressionStatement (thread_init_call)); } - main_block.add_statement (new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")))); + var type_init_call = new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init"))); + type_init_call.line = cmain.line; + main_block.add_statement (type_init_call); + var main_call = new CCodeFunctionCall (new CCodeIdentifier (function.name)); if (args_parameter) { main_call.add_argument (new CCodeIdentifier ("argc")); main_call.add_argument (new CCodeIdentifier ("argv")); } if (return_value) { - main_block.add_statement (new CCodeReturnStatement (main_call)); + var main_stmt = new CCodeReturnStatement (main_call); + main_stmt.line = cmain.line; + main_block.add_statement (main_stmt); } else { // method returns void, always use 0 as exit code - main_block.add_statement (new CCodeExpressionStatement (main_call)); - main_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("0"))); + var main_stmt = new CCodeExpressionStatement (main_call); + main_stmt.line = cmain.line; + main_block.add_statement (main_stmt); + var ret_stmt = new CCodeReturnStatement (new CCodeConstant ("0")); + ret_stmt.line = cmain.line; + main_block.add_statement (ret_stmt); } cmain.block = main_block; source_type_member_definition.append (cmain); diff --git a/gobject/valacodegeneratorsourcefile.vala b/gobject/valacodegeneratorsourcefile.vala index afeeff4..9543f18 100644 --- a/gobject/valacodegeneratorsourcefile.vala +++ b/gobject/valacodegeneratorsourcefile.vala @@ -258,6 +258,7 @@ public class Vala.CodeGenerator { writer.close (); writer = new CCodeWriter (source_file.get_csource_filename ()); + writer.line_directives = context.debug; if (comment != null) { comment.write (writer); } diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 26ffa1b..df29712 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -55,7 +55,7 @@ public abstract class Vala.CodeNode : Object { set { if (source_reference != null) { value.line = new CCodeLineDirective ( - source_reference.file.filename, + Path.build_filename (Environment.get_current_dir (), source_reference.file.filename), source_reference.first_line); } -- 2.7.4