From: Michael B. Trausch Date: Sun, 27 Sep 2009 20:22:57 +0000 (+0200) Subject: Add `do not modify' note at the top of generated C files X-Git-Tag: 0.7.7~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=728bb93c7fce2725413627a4012fe4a5230bec50;p=thirdparty%2Fvala.git Add `do not modify' note at the top of generated C files Fixes bug 595797. --- diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala index 11559cd54..ff0677bce 100644 --- a/ccode/valaccodewriter.vala +++ b/ccode/valaccodewriter.vala @@ -31,6 +31,11 @@ public class Vala.CCodeWriter { */ public string filename { get; set; } + /** + * Specifies the source file used to generate this one. + */ + private string source_filename; + /** * Specifies whether to emit line directives. */ @@ -55,8 +60,9 @@ public class Vala.CCodeWriter { /* at begin of line */ private bool _bol = true; - public CCodeWriter (string filename) { + public CCodeWriter (string filename, string? source_filename = null) { this.filename = filename; + this.source_filename = source_filename; } /** @@ -74,6 +80,18 @@ public class Vala.CCodeWriter { stream = FileStream.open (filename, "w"); } + write_string ("/* %s generated by valac, the Vala compiler".printf (Path.get_basename (filename))); + + // Write the file name if known + if (source_filename != null) { + write_newline (); + write_string (" * generated from %s".printf (Path.get_basename (source_filename))); + } + + write_string (", do not modify */"); + write_newline (); + write_newline (); + return (stream != null); } diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 50fd405a2..38662ba5d 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -651,7 +651,7 @@ internal class Vala.CCodeBaseModule : CCodeModule { source_type_member_definition.append (cfunc); } - var writer = new CCodeWriter (source_file.get_csource_filename ()); + var writer = new CCodeWriter (source_file.get_csource_filename (), source_file.filename); if (!writer.open ()) { Report.error (null, "unable to open `%s' for writing".printf (writer.filename)); return;