summaryrefslogtreecommitdiff
path: root/ccode/valaccodewriter.vala
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2009-04-08 18:28:27 +0200
committerJürg Billeter <j@bitron.ch>2009-04-08 18:30:59 +0200
commit3a1b5894b7c1f6f22541c2298b9dc9640a9d2da9 (patch)
treec0a92e370caaf5c3ea5744b30f5100b039c984bc /ccode/valaccodewriter.vala
parentff45041f9070755c8f9ac8862a6c9beb514fe1d9 (diff)
downloadvala-3a1b5894b7c1f6f22541c2298b9dc9640a9d2da9.tar.gz
Emit line directive when there is no corresponding Vala line
Diffstat (limited to 'ccode/valaccodewriter.vala')
-rw-r--r--ccode/valaccodewriter.vala19
1 files changed, 15 insertions, 4 deletions
diff --git a/ccode/valaccodewriter.vala b/ccode/valaccodewriter.vala
index 9549b8c93..ff2ead63b 100644
--- a/ccode/valaccodewriter.vala
+++ b/ccode/valaccodewriter.vala
@@ -1,6 +1,6 @@
/* valaccodewriter.vala
*
- * Copyright (C) 2006-2008 Jürg Billeter
+ * Copyright (C) 2006-2009 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
@@ -49,6 +49,8 @@ public class Vala.CCodeWriter {
private FileStream stream;
private int indent;
+ private int current_line_number = 1;
+ private bool using_line_directive;
/* at begin of line */
private bool _bol = true;
@@ -111,12 +113,20 @@ public class Vala.CCodeWriter {
* Writes tabs according to the current indent level.
*/
public void write_indent (CCodeLineDirective? line = null) {
- if (line_directives && line != null) {
- line.write (this);
+ if (line_directives) {
+ if (line != null) {
+ line.write (this);
+ using_line_directive = true;
+ } else if (using_line_directive) {
+ // no corresponding Vala line, emit line directive for C line
+ write_string ("#line %d \"%s\"".printf (current_line_number + 1, filename));
+ write_newline ();
+ using_line_directive = false;
+ }
}
if (!bol) {
- stream.putc ('\n');
+ write_newline ();
}
for (int i = 0; i < indent; i++) {
@@ -141,6 +151,7 @@ public class Vala.CCodeWriter {
*/
public void write_newline () {
stream.putc ('\n');
+ current_line_number++;
_bol = true;
}