Insert #line directives in generated C code.
authormjsousa
Sun, 16 Mar 2014 10:16:25 +0000
changeset 877 c25346eac788
parent 876 e2c4f6f4abe2
child 878 89eb85bab58f
Insert #line directives in generated C code.
stage4/generate_c/generate_c_base.cc
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_st.cc
--- a/stage4/generate_c/generate_c_base.cc	Sat Mar 15 20:10:20 2014 +0000
+++ b/stage4/generate_c/generate_c_base.cc	Sun Mar 16 10:16:25 2014 +0000
@@ -90,6 +90,14 @@
         s4o.print(variable_prefix_);
     }
 
+    void print_line_directive(symbol_c *symbol) {
+      s4o.print("#line ");
+      s4o.print(symbol->first_line);
+      s4o.print(" \"");
+      s4o.print(symbol->first_file);
+      s4o.print("\"\n");    
+    }
+    
     void *print_token(token_c *token, int offset = 0) {
       return s4o.printupper((token->value)+offset);
     }
--- a/stage4/generate_c/generate_c_il.cc	Sat Mar 15 20:10:20 2014 +0000
+++ b/stage4/generate_c/generate_c_il.cc	Sun Mar 16 10:16:25 2014 +0000
@@ -704,12 +704,13 @@
 
   /* Declare the backup to the IL implicit variable, that will store the result of the IL operations executed inside a parenthesis... */
   declare_implicit_variable_back();
-  /*
-  s4o.print(s4o.indent_spaces);
-  this->implicit_variable_result_back.accept(*this);
-  s4o.print(".INTvar = 0;\n\n");
-  */
-  print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n");
+  
+  for(int i = 0; i < symbol->n; i++) {
+    print_line_directive(symbol->elements[i]);
+    s4o.print(s4o.indent_spaces);
+    symbol->elements[i]->accept(*this);
+    s4o.print(";\n");
+  }
   return NULL;
 }
 
--- a/stage4/generate_c/generate_c_st.cc	Sat Mar 15 20:10:20 2014 +0000
+++ b/stage4/generate_c/generate_c_st.cc	Sun Mar 16 10:16:25 2014 +0000
@@ -874,7 +874,13 @@
 /* B 3.2 Statements */
 /********************/
 void *visit(statement_list_c *symbol) {
-  return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n");
+  for(int i = 0; i < symbol->n; i++) {
+    print_line_directive(symbol->elements[i]);
+    s4o.print(s4o.indent_spaces);
+    symbol->elements[i]->accept(*this);
+    s4o.print(";\n");
+  }
+  return NULL;
 }
 
 /*********************************/