Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DI Generation Improvements #928

Closed
wants to merge 187 commits into from

2 participants

Adam Wilson Hara Kenji
Adam Wilson

This pull request attempt to improve the automatic generation of DI files by DMD.

All function implementations are removed from DI files except for those inside templates and functions with auto return values.
Proper indenting for DI files.

There were some changes to OutBuffer::write() to fix an OutOfMemory error I was getting on Windows (x64).

If anybody has any questions/comments/rants/raves or finds anything broken let me know. I would love to hear feedback.

NOTE: I apologize in advance for the spurious commits, I was apparently misinformed as to how to properly update my git branch (fetch/merge instead of the proper rebasing).

and others added some commits December 18, 2011
Adam Wilson Initial commit for DI generation improvements 4aa8895
Adam Wilson Fixed handling of const types 5ceef9f
Adam Wilson Merge remote-tracking branch 'upstream/master' ce590c0
Adam Wilson All privates now included. Templates class/functions retain implement…
…ation. Immutable variables now keep initializer.
dc6772b
Adam Wilson Merge remote-tracking branch 'upstream/master' 52ea71a
Adam Wilson Merge remote-tracking branch 'upstream/master' b62e855
Adam Wilson Fixed bug that would cause immutables inside template function implem…
…entions to lose their initializers.
bb539fe
Adam Wilson Fixed bug that would cause manifest constants to lose their initializ…
…ers.
e8f065c
Adam Wilson Fixed bug that would cause all function level variables to lose their…
… initializers.
390d2f4
Adam Wilson Merge remote-tracking branch 'upstream/master' c92a39c
Adam Wilson Merge remote-tracking branch 'upstream/master' 49e7c1f
Adam Wilson Merge remote-tracking branch 'upstream/master' 24e7dd1
Adam Wilson Merge remote-tracking branch 'upstream/master' 293b46d
Adam Wilson Merge remote-tracking branch 'upstream/master' 035dbb2
Adam Wilson Merge remote-tracking branch 'upstream/master' 2767224
Adam Wilson Merge remote-tracking branch 'upstream/master' f7faf00
Adam Wilson Merge remote-tracking branch 'upstream/master' 4b7f660
Adam Wilson Merge remote-tracking branch 'upstream/master' 30ca882
Adam Wilson Merge remote-tracking branch 'upstream/master' 15599e9
Adam Wilson Merge remote-tracking branch 'upstream/master' b4da79a
Adam Wilson Merge remote-tracking branch 'upstream/master' 528c456
Adam Wilson Merge remote-tracking branch 'upstream/master' d318588
Adam Wilson Merge remote-tracking branch 'upstream/master' e2d62a2
Adam Wilson Merge remote-tracking branch 'upstream/master' 3b8e2f7
Adam Wilson Merge remote-tracking branch 'upstream/master' 57bfe04
Adam Wilson Merge remote-tracking branch 'upstream/master' ea8b2f3
Adam Wilson Merge remote-tracking branch 'upstream/master' b85ff89
Adam Wilson Merge remote-tracking branch 'upstream/master' 1ea04d5
Adam Wilson Merge remote-tracking branch 'upstream/master' fcc235a
Adam Wilson Merge remote-tracking branch 'upstream/master' 848c4a7
Adam Wilson Merge remote-tracking branch 'upstream/master' 59ec5c6
Adam Wilson Merge remote-tracking branch 'upstream/master' cba7380
Adam Wilson Merge remote-tracking branch 'upstream/master' 429aa77
Adam Wilson Merge remote-tracking branch 'upstream/master' 8664080
Adam Wilson Merge remote-tracking branch 'upstream/master' ed98a4c
Adam Wilson Merge remote-tracking branch 'upstream/master' d7b8065
Adam Wilson Initial indent tracking commit, work not finished. a012440
Adam Wilson Merge remote-tracking branch 'upstream/master' 17fe8dd
Adam Wilson Merge remote-tracking branch 'upstream/master' e2768af
Adam Wilson Merge remote-tracking branch 'upstream/master' d0c7a86
Adam Wilson Initial indent tracking commit, work not finished. 5d6f9d9
Adam Wilson Fixed a merge conflict in statement.c function UnrolledLoopStatement:…
…:toCBuffer
ba922c7
Adam Wilson Merge remote-tracking branch 'upstream/master' dd61ab6
Adam Wilson Merge remote-tracking branch 'upstream/master' 8311847
Adam Wilson Merge remote-tracking branch 'upstream/master' b69e0de
Adam Wilson Merge remote-tracking branch 'upstream/master' 887b425
Adam Wilson Merge remote-tracking branch 'upstream/master' e192b34
Adam Wilson Merge remote-tracking branch 'upstream/master' 82c2071
Adam Wilson Merge remote-tracking branch 'upstream/master' 0f31090
Adam Wilson Merge remote-tracking branch 'upstream/master' 9416fdd
Adam Wilson Merge remote-tracking branch 'upstream/master' b69c06a
Adam Wilson Merge remote-tracking branch 'upstream/master' 45832cf
Adam Wilson Merge remote-tracking branch 'upstream/master' bd3c1e8
Adam Wilson Merge remote-tracking branch 'upstream/master' a16dea1
Adam Wilson Merge remote-tracking branch 'upstream/master' a78e8ed
Adam Wilson Merge remote-tracking branch 'upstream/master' 0d8dc6d
Adam Wilson Merge remote-tracking branch 'upstream/master' f0c77b2
Adam Wilson Merge remote-tracking branch 'upstream/master' 51626a6
Adam Wilson Merge remote-tracking branch 'upstream/master' 8f2aef8
Adam Wilson Merge remote-tracking branch 'upstream/master' e711de4
Adam Wilson Merge remote-tracking branch 'upstream/master' 6e46382
Adam Wilson Merge remote-tracking branch 'upstream/master' c6fa330
Adam Wilson Merge remote-tracking branch 'upstream/master' 40d00de
Adam Wilson Merge remote-tracking branch 'upstream/master' 9237ccc
Adam Wilson Merge remote-tracking branch 'upstream/master' 98532ed
Adam Wilson switched all indenting code to use buf->level 0476a0e
Adam Wilson Merge remote-tracking branch 'upstream/master' c7e5cc5
Adam Wilson Merge remote-tracking branch 'upstream/master' 7c74078
Adam Wilson updated to exclude types that non longer need indenting. 2fd2c06
Adam Wilson Merge remote-tracking branch 'upstream/master' cc75458
Adam Wilson Merge remote-tracking branch 'upstream/master' 7a1ca85
Adam Wilson Merge remote-tracking branch 'upstream/master' 8febdc6
Adam Wilson Merge remote-tracking branch 'upstream/master' 3d98f2e
Adam Wilson testing changes to debug a DMD assert error. 2e25dea
Adam Wilson Merge remote-tracking branch 'upstream/master' e39b6ef
Adam Wilson Merge remote-tracking branch 'upstream/master' 1bbe905
Adam Wilson Merge remote-tracking branch 'upstream/master' 995bfe9
Adam Wilson Merge remote-tracking branch 'upstream/master' bdf1e5c
Adam Wilson Merge remote-tracking branch 'upstream/master' 0b21c38
Adam Wilson Merge remote-tracking branch 'upstream/master' 2a8ddb2
Adam Wilson Merge remote-tracking branch 'upstream/master' 1c978e7
Adam Wilson Merge remote-tracking branch 'upstream/master' 127865a
Adam Wilson Merge remote-tracking branch 'upstream/master' 3f81329
Adam Wilson Merge remote-tracking branch 'upstream/master' abeba48
Adam Wilson Merge remote-tracking branch 'upstream/master' 1acce22
Adam Wilson Merge remote-tracking branch 'upstream/master' 7a9825e
Adam Wilson Merge remote-tracking branch 'upstream/master' b9c9020
Adam Wilson Merge remote-tracking branch 'upstream/master' becbf13
Adam Wilson Merge remote-tracking branch 'upstream/master' 591d005
Adam Wilson Merge remote-tracking branch 'upstream/master' ecf3e2a
Adam Wilson Merge remote-tracking branch 'upstream/master' af4662b
Adam Wilson Merge remote-tracking branch 'upstream/master' fd60d7e
Adam Wilson Merge remote-tracking branch 'upstream/master' 993371e
Adam Wilson Merge remote-tracking branch 'upstream/master' 9351cf9
Adam Wilson Merge remote-tracking branch 'upstream/master' 54fcb78
Adam Wilson Merge remote-tracking branch 'upstream/master' 923ca68
Adam Wilson Merge remote-tracking branch 'upstream/master' ff73c40
Adam Wilson Merge remote-tracking branch 'upstream/master' 017deee
Adam Wilson Merge remote-tracking branch 'upstream/master' cd6107d
Adam Wilson Merge remote-tracking branch 'upstream/master' a9c6c8f
Adam Wilson Merge remote-tracking branch 'upstream/master' 798c188
Adam Wilson Merge remote-tracking branch 'upstream/master' 0c06fb6
Adam Wilson Merge remote-tracking branch 'upstream/master' 0b439a3
Adam Wilson Merge remote-tracking branch 'upstream/master' b62435d
Adam Wilson Merge remote-tracking branch 'upstream/master' 645791c
Adam Wilson Merge remote-tracking branch 'upstream/master' 1985a37
Adam Wilson Merge remote-tracking branch 'upstream/master' 33ad892
Adam Wilson Fixed merge errors with DMD HEAD 36ab5df
Adam Wilson Merge remote-tracking branch 'upstream/master' fcf5016
Adam Wilson Merge remote-tracking branch 'upstream/master' fb2633e
Adam Wilson Merge remote-tracking branch 'upstream/master' 154fa60
Adam Wilson Merge remote-tracking branch 'upstream/master' 058484b
Adam Wilson Merge remote-tracking branch 'upstream/master' 0145ef1
Adam Wilson Merge remote-tracking branch 'upstream/master' 7302ee8
Adam Wilson Merge remote-tracking branch 'upstream/master' 7147d3d
Adam Wilson Merge remote-tracking branch 'upstream/master' fdd2030
Adam Wilson Merge remote-tracking branch 'upstream/master' 6ae406d
Adam Wilson Merge remote-tracking branch 'upstream/master' 2084998
Adam Wilson Merge remote-tracking branch 'upstream/master' 02517d7
Adam Wilson Merge remote-tracking branch 'upstream/master' eacaf5f
Adam Wilson Merge remote-tracking branch 'upstream/master' d97b4ce
Adam Wilson Merge remote-tracking branch 'upstream/master' bf328e4
Adam Wilson Merge remote-tracking branch 'upstream/master' 44e96eb
Adam Wilson Merge remote-tracking branch 'upstream/master' 474f1fd
Adam Wilson Merge remote-tracking branch 'upstream/master' cfa40b3
Adam Wilson Merge remote-tracking branch 'upstream/master' dca4387
Adam Wilson Merge remote-tracking branch 'upstream/master' 416e528
Adam Wilson Merge remote-tracking branch 'upstream/master' a780047
Adam Wilson Merge remote-tracking branch 'upstream/master' f7d6baa
Adam Wilson Merge remote-tracking branch 'upstream/master' be3fcda
Adam Wilson Merge remote-tracking branch 'upstream/master' 2e5ef5c
Adam Wilson Merge remote-tracking branch 'upstream/master' 4589790
Adam Wilson Merge remote-tracking branch 'upstream/master' d5427a8
Adam Wilson Merge remote-tracking branch 'upstream/master' a9b705b
Adam Wilson Merge remote-tracking branch 'upstream/master' d6a16cc
Adam Wilson Merge remote-tracking branch 'upstream/master' e949ec0
Adam Wilson Merge remote-tracking branch 'upstream/master' 1609c73
Adam Wilson Merge remote-tracking branch 'upstream/master' 8be3d56
Adam Wilson Merge remote-tracking branch 'upstream/master' 019a960
Merge remote-tracking branch 'upstream/master' 200afe6
Merge remote-tracking branch 'upstream/master' 9be6981
Merge remote-tracking branch 'upstream/master' d4b2996
Merge remote-tracking branch 'upstream/master' 0d82e7e
Merge remote-tracking branch 'upstream/master' b2678de
Merge remote-tracking branch 'upstream/master' 2aa5796
Merge remote-tracking branch 'upstream/master' aa44359
Merge remote-tracking branch 'upstream/master' ea12018
Merge remote-tracking branch 'upstream/master' bc4acb5
Merge remote-tracking branch 'upstream/master' ad3667c
Merge remote-tracking branch 'upstream/master' c931f7e
Merge remote-tracking branch 'upstream/master' 40f7049
Merge remote-tracking branch 'upstream/master' 13be385
Merge remote-tracking branch 'upstream/master' 305f5f4
Merge remote-tracking branch 'upstream/master' a072aed
Updated to account for Issue 7754 5ec8e39
Adam Wilson Merge remote-tracking branch 'upstream/master' 1c4a55e
Adam Wilson Merge remote-tracking branch 'upstream/master' a32b529
Adam Wilson Merge remote-tracking branch 'upstream/master' f37f3b2
Adam Wilson Merge remote-tracking branch 'upstream/master' 9e867ce
Adam Wilson Merge remote-tracking branch 'upstream/master' 3549a55
Adam Wilson Merge remote-tracking branch 'upstream/master' d08b438
Adam Wilson Merge remote-tracking branch 'upstream/master' 69199ec
Adam Wilson Merge remote-tracking branch 'upstream/master' de166c2
Adam Wilson Merge remote-tracking branch 'upstream/master' 0a5dbe7
Adam Wilson Fix merge conflict on cond.c 5bc0639
Adam Wilson Fixed collisions in class.c and struct.c d4c06b0
Adam Wilson Merge remote-tracking branch 'upstream/master' db3bfc8
Adam Wilson Merge remote-tracking branch 'upstream/master' cd638be
Adam Wilson Merge remote-tracking branch 'upstream/master' b551742
Adam Wilson Merge remote-tracking branch 'upstream/master' ecee9ca
Adam Wilson Merge remote-tracking branch 'upstream/master' 8c551d6
Adam Wilson Merge remote-tracking branch 'upstream/master' 1e7e39a
Adam Wilson Merge remote-tracking branch 'upstream/master' 0549056
Adam Wilson Variables now keep their initializers. Changed assert null check in m…
…type.c at line 5222 to if() null check to fix spurious assert.
0355522
Adam Wilson Cleaned up some dead code in prepartion for the pending pull request. 3d23ee1
Adam Wilson Replaced tabs with spaces per style requirements. d7aaa69
Adam Wilson Merge remote-tracking branch 'upstream/master' 24152fc
Adam Wilson Merge remote-tracking branch 'upstream/master' a366de9
Adam Wilson Merge remote-tracking branch 'upstream/master' f75f205
Adam Wilson Merge remote-tracking branch 'upstream/master' 7f1f7f9
Adam Wilson Merge remote-tracking branch 'upstream/master' b93a698
Adam Wilson Merge remote-tracking branch 'upstream/master' f26612a
Adam Wilson Merge remote-tracking branch 'upstream/master' ede62e7
Adam Wilson Merge remote-tracking branch 'upstream/master' 156bb5c
Adam Wilson Functions with auto return values must keep their implemenations for DMD
to perform type deduction. (Fixes posix build error)
Fixed delegates in template constraints not keeping their implementions.
(Fixes Windows build error)
2587414
Adam Wilson Removed tabs to conform to style guidelines. 35470c0
Adam Wilson Removed an extraneous function that was only used for testing. da7cbe9
Hara Kenji
Collaborator
9rnsr commented May 12, 2012

I think correct di generation should run AFTER semantic analysis. When it is necessary to keep original code (e.g. template declaration), we can save AST with syntaxCopy before semantic analysis, and use it after.

Hara Kenji
Collaborator
9rnsr commented May 12, 2012

I think this pull is terrible. You should create new branch for the pull request, instead of using master. And sometimes you can rebase the branch and push -f to your repo to track dmd head.

Adam Wilson

Walter put a big comment mars.c about how DI generation should never be done after semantic analysis. I was merely following his advice.

I think what I may have to do close this one and recreate my fork by hand. I was not well instructed in the proper procedures for DMD work when I started this project.

Adam Wilson

Closing to clean up.

Adam Wilson LightBender closed this May 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
29  src/attrib.c
@@ -26,6 +26,7 @@
26 26
 #include "module.h"
27 27
 #include "parse.h"
28 28
 #include "template.h"
  29
+#include "hdrgen.h"
29 30
 #if TARGET_NET
30 31
  #include "frontend.net/pragma.h"
31 32
 #endif
@@ -348,7 +349,6 @@ void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses)
348 349
     }
349 350
 }
350 351
 
351  
-
352 352
 void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
353 353
 {
354 354
     if (decl)
@@ -362,13 +362,13 @@ void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
362 362
             buf->writenl();
363 363
             buf->writeByte('{');
364 364
             buf->writenl();
365  
-            for (size_t i = 0; i < decl->dim; i++)
  365
+            buf->level++;
  366
+            for (unsigned i = 0; i < decl->dim; i++)
366 367
             {
367 368
                 Dsymbol *s = (*decl)[i];
368  
-
369  
-                buf->writestring("    ");
370 369
                 s->toCBuffer(buf, hgs);
371 370
             }
  371
+            buf->level--;
372 372
             buf->writeByte('}');
373 373
         }
374 374
     }
@@ -868,18 +868,21 @@ void AnonDeclaration::setFieldOffset(AggregateDeclaration *ad, unsigned *poffset
868 868
 void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
869 869
 {
870 870
     buf->printf(isunion ? "union" : "struct");
871  
-    buf->writestring("\n{\n");
  871
+    buf->writenl();
  872
+    buf->writestring("{");
  873
+    buf->writenl();
  874
+    buf->level++;
872 875
     if (decl)
873 876
     {
874 877
         for (size_t i = 0; i < decl->dim; i++)
875 878
         {
876 879
             Dsymbol *s = (*decl)[i];
877  
-
878  
-            //buf->writestring("    ");
879 880
             s->toCBuffer(buf, hgs);
880 881
         }
881 882
     }
882  
-    buf->writestring("}\n");
  883
+    buf->level--;
  884
+    buf->writestring("}");
  885
+    buf->writenl();
883 886
 }
884 887
 
885 888
 const char *AnonDeclaration::kind()
@@ -1309,16 +1312,16 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1309 1312
         buf->writenl();
1310 1313
         buf->writeByte('{');
1311 1314
         buf->writenl();
  1315
+        buf->level++;
1312 1316
         if (decl)
1313 1317
         {
1314 1318
             for (size_t i = 0; i < decl->dim; i++)
1315 1319
             {
1316 1320
                 Dsymbol *s = (*decl)[i];
1317  
-
1318  
-                buf->writestring("    ");
1319 1321
                 s->toCBuffer(buf, hgs);
1320 1322
             }
1321 1323
         }
  1324
+        buf->level--;
1322 1325
         buf->writeByte('}');
1323 1326
         if (elsedecl)
1324 1327
         {
@@ -1327,13 +1330,13 @@ void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1327 1330
             buf->writenl();
1328 1331
             buf->writeByte('{');
1329 1332
             buf->writenl();
1330  
-            for (size_t i = 0; i < elsedecl->dim; i++)
  1333
+            buf->level++;
  1334
+            for (unsigned i = 0; i < elsedecl->dim; i++)
1331 1335
             {
1332 1336
                 Dsymbol *s = (*elsedecl)[i];
1333  
-
1334  
-                buf->writestring("    ");
1335 1337
                 s->toCBuffer(buf, hgs);
1336 1338
             }
  1339
+            buf->level--;
1337 1340
             buf->writeByte('}');
1338 1341
         }
1339 1342
     }
5  src/class.c
@@ -26,6 +26,7 @@
26 26
 #include "module.h"
27 27
 #include "expression.h"
28 28
 #include "statement.h"
  29
+#include "hdrgen.h"
29 30
 
30 31
 /********************************* ClassDeclaration ****************************/
31 32
 
@@ -819,13 +820,13 @@ void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
819 820
         buf->writenl();
820 821
         buf->writeByte('{');
821 822
         buf->writenl();
  823
+        buf->level++;
822 824
         for (size_t i = 0; i < members->dim; i++)
823 825
         {
824 826
             Dsymbol *s = (*members)[i];
825  
-
826  
-            buf->writestring("    ");
827 827
             s->toCBuffer(buf, hgs);
828 828
         }
  829
+        buf->level--;
829 830
         buf->writestring("}");
830 831
     }
831 832
     else
1  src/cond.c
@@ -22,6 +22,7 @@
22 22
 #include "lexer.h"
23 23
 #include "mtype.h"
24 24
 #include "scope.h"
  25
+#include "hdrgen.h"
25 26
 #include "arraytypes.h"
26 27
 
27 28
 int findCondition(Strings *ids, Identifier *ident)
7  src/declaration.c
@@ -1725,10 +1725,15 @@ void VarDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1725 1725
     /* If changing, be sure and fix CompoundDeclarationStatement::toCBuffer()
1726 1726
      * too.
1727 1727
      */
  1728
+
  1729
+    int ism = 0;
1728 1730
     if (type)
  1731
+    {
1729 1732
         type->toCBuffer(buf, ident, hgs);
  1733
+    }
1730 1734
     else
1731  
-        buf->writestring(ident->toChars());
  1735
+        buf->writestring(ident->toChars());    
  1736
+
1732 1737
     if (init)
1733 1738
     {   buf->writestring(" = ");
1734 1739
 #if DMDV2
1  src/dsymbol.c
@@ -31,6 +31,7 @@
31 31
 #include "import.h"
32 32
 #include "template.h"
33 33
 #include "attrib.h"
  34
+#include "hdrgen.h"
34 35
 
35 36
 /****************************** Dsymbol ******************************/
36 37
 
4  src/enum.c
@@ -18,6 +18,7 @@
18 18
 #include "expression.h"
19 19
 #include "module.h"
20 20
 #include "declaration.h"
  21
+#include "hdrgen.h"
21 22
 
22 23
 /********************************* EnumDeclaration ****************************/
23 24
 
@@ -345,16 +346,17 @@ void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
345 346
     buf->writenl();
346 347
     buf->writeByte('{');
347 348
     buf->writenl();
  349
+    buf->level++;
348 350
     for (size_t i = 0; i < members->dim; i++)
349 351
     {
350 352
         EnumMember *em = (*members)[i]->isEnumMember();
351 353
         if (!em)
352 354
             continue;
353  
-        //buf->writestring("    ");
354 355
         em->toCBuffer(buf, hgs);
355 356
         buf->writeByte(',');
356 357
         buf->writenl();
357 358
     }
  359
+    buf->level--;
358 360
     buf->writeByte('}');
359 361
     buf->writenl();
360 362
 }
40  src/func.c
@@ -1683,7 +1683,22 @@ void FuncDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1683 1683
 
1684 1684
     StorageClassDeclaration::stcToCBuffer(buf, storage_class);
1685 1685
     type->toCBuffer(buf, ident, hgs);
1686  
-    bodyToCBuffer(buf, hgs);
  1686
+    if(hgs->hdrgen == 1)
  1687
+    {
  1688
+        if(storage_class & STCauto)
  1689
+        {
  1690
+            hgs->autoMember++;
  1691
+            bodyToCBuffer(buf, hgs);
  1692
+            hgs->autoMember--;
  1693
+        }
  1694
+        else if(hgs->tpltMember == 0)
  1695
+            buf->writestring(";");
  1696
+        else
  1697
+            bodyToCBuffer(buf, hgs);
  1698
+    }
  1699
+    else
  1700
+        bodyToCBuffer(buf, hgs);
  1701
+    buf->writenl();
1687 1702
 }
1688 1703
 
1689 1704
 VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad)
@@ -1778,21 +1793,21 @@ int FuncDeclaration::equals(Object *o)
1778 1793
 
1779 1794
 void FuncDeclaration::bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs)
1780 1795
 {
1781  
-    if (fbody &&
1782  
-        (!hgs->hdrgen || hgs->tpltMember || canInline(1,1,1))
1783  
-       )
  1796
+    if (fbody && (!hgs->hdrgen || hgs->autoMember || hgs->tpltMember))
1784 1797
     {   buf->writenl();
1785 1798
 
1786 1799
         // in{}
1787 1800
         if (frequire)
1788  
-        {   buf->writestring("in");
  1801
+        {   
  1802
+            buf->writestring("in");
1789 1803
             buf->writenl();
1790 1804
             frequire->toCBuffer(buf, hgs);
1791 1805
         }
1792 1806
 
1793 1807
         // out{}
1794 1808
         if (fensure)
1795  
-        {   buf->writestring("out");
  1809
+        {   
  1810
+            buf->writestring("out");
1796 1811
             if (outId)
1797 1812
             {   buf->writebyte('(');
1798 1813
                 buf->writestring(outId->toChars());
@@ -1803,18 +1818,22 @@ void FuncDeclaration::bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs)
1803 1818
         }
1804 1819
 
1805 1820
         if (frequire || fensure)
1806  
-        {   buf->writestring("body");
  1821
+        {   
  1822
+            buf->writestring("body");
1807 1823
             buf->writenl();
1808 1824
         }
1809 1825
 
1810 1826
         buf->writebyte('{');
1811 1827
         buf->writenl();
  1828
+        buf->level++;
1812 1829
         fbody->toCBuffer(buf, hgs);
  1830
+        buf->level--;
1813 1831
         buf->writebyte('}');
1814 1832
         buf->writenl();
1815 1833
     }
1816 1834
     else
1817  
-    {   buf->writeByte(';');
  1835
+    {   
  1836
+        buf->writeByte(';');
1818 1837
         buf->writenl();
1819 1838
     }
1820 1839
 }
@@ -3305,7 +3324,9 @@ void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
3305 3324
     buf->writestring(kind());
3306 3325
     buf->writeByte(' ');
3307 3326
     type->toCBuffer(buf, NULL, hgs);
  3327
+    hgs->tpltMember++;
3308 3328
     bodyToCBuffer(buf, hgs);
  3329
+    hgs->tpltMember--;
3309 3330
 }
3310 3331
 
3311 3332
 
@@ -3711,7 +3732,8 @@ int StaticCtorDeclaration::addPostInvariant()
3711 3732
 void StaticCtorDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
3712 3733
 {
3713 3734
     if (hgs->hdrgen && !hgs->tpltMember)
3714  
-    {   buf->writestring("static this();");
  3735
+    {   
  3736
+        buf->writestring("static this();");
3715 3737
         buf->writenl();
3716 3738
         return;
3717 3739
     }
1  src/hdrgen.c
@@ -51,6 +51,7 @@ void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs);
51 51
 void Module::genhdrfile()
52 52
 {
53 53
     OutBuffer hdrbufr;
  54
+    hdrbufr.doindent = 1;
54 55
 
55 56
     hdrbufr.printf("// D import file generated from '%s'", srcfile->toChars());
56 57
     hdrbufr.writenl();
6  src/hdrgen.h
@@ -22,6 +22,8 @@ struct HdrGenState
22 22
     int inBinExp;
23 23
     int inArrExp;
24 24
     int emitInst;
  25
+    int autoMember;     // Non-zero if function is an auto type
  26
+
25 27
     struct
26 28
     {
27 29
         int init;
@@ -29,6 +31,4 @@ struct HdrGenState
29 31
     } FLinit;
30 32
 
31 33
     HdrGenState() { memset(this, 0, sizeof(HdrGenState)); }
32  
-};
33  
-
34  
-
  34
+};
1  src/init.c
@@ -914,6 +914,7 @@ Expression *ExpInitializer::toExpression()
914 914
 
915 915
 void ExpInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
916 916
 {
  917
+
917 918
     exp->toCBuffer(buf, hgs);
918 919
 }
919 920
 
6  src/mtype.c
@@ -1645,7 +1645,7 @@ Type *Type::merge()
1645 1645
 
1646 1646
         //if (next)
1647 1647
             //next = next->merge();
1648  
-        toDecoBuffer(&buf);
  1648
+        this->toDecoBuffer(&buf);
1649 1649
         sv = stringtable.update((char *)buf.data, buf.offset);
1650 1650
         if (sv->ptrvalue)
1651 1651
         {   t = (Type *) sv->ptrvalue;
@@ -5219,8 +5219,8 @@ void TypeFunction::toDecoBuffer(OutBuffer *buf, int flag)
5219 5219
     Parameter::argsToDecoBuffer(buf, parameters);
5220 5220
     //if (buf->data[buf->offset - 1] == '@') halt();
5221 5221
     buf->writeByte('Z' - varargs);      // mark end of arg list
5222  
-    assert(next);
5223  
-    next->toDecoBuffer(buf);
  5222
+    //assert(next);
  5223
+    if(next != NULL) next->toDecoBuffer(buf);
5224 5224
     inuse--;
5225 5225
 }
5226 5226
 
84  src/root/root.c
@@ -1543,6 +1543,10 @@ OutBuffer::OutBuffer()
1543 1543
     data = NULL;
1544 1544
     offset = 0;
1545 1545
     size = 0;
  1546
+
  1547
+    doindent = 0;
  1548
+    level = 0;
  1549
+    linehead = 1;
1546 1550
 }
1547 1551
 
1548 1552
 OutBuffer::~OutBuffer()
@@ -1588,7 +1592,33 @@ void OutBuffer::setsize(unsigned size)
1588 1592
 
1589 1593
 void OutBuffer::write(const void *data, unsigned nbytes)
1590 1594
 {
1591  
-    reserve(nbytes);
  1595
+    //if (doindent && linehead)
  1596
+    //{
  1597
+    //    if (level)
  1598
+    //    {
  1599
+    //        reserve(level);
  1600
+    //        for (size_t i=0; i<level; i++)
  1601
+    //        {
  1602
+    //            this->data[offset] = '\t';
  1603
+    //            offset++;
  1604
+    //        }
  1605
+    //    }
  1606
+    //    linehead = 0;
  1607
+    //}
  1608
+    char t = '\t';
  1609
+    reserve(nbytes + level);
  1610
+    if (doindent && linehead)
  1611
+    {
  1612
+        if (level)
  1613
+        {
  1614
+            for (size_t i=0; i<level; i++)
  1615
+            {
  1616
+                memcpy(this->data + offset, &t, sizeof(t));
  1617
+                offset++;
  1618
+            }
  1619
+        }
  1620
+        linehead = 0;
  1621
+    }
1592 1622
     memcpy(this->data + offset, data, nbytes);
1593 1623
     offset += nbytes;
1594 1624
 }
@@ -1652,10 +1682,26 @@ void OutBuffer::writenl()
1652 1682
     writeByte('\n');
1653 1683
 #endif
1654 1684
 #endif
  1685
+    if (doindent)
  1686
+        linehead = 1;
1655 1687
 }
1656 1688
 
1657 1689
 void OutBuffer::writeByte(unsigned b)
1658 1690
 {
  1691
+    if (doindent && linehead
  1692
+        && b != '\n')
  1693
+    {
  1694
+        if (level)
  1695
+        {
  1696
+            reserve(level);
  1697
+            for (size_t i=0; i<level; i++)
  1698
+            {
  1699
+                this->data[offset] = '\t';
  1700
+                offset++;
  1701
+            }
  1702
+        }
  1703
+        linehead = 0;
  1704
+    }    
1659 1705
     reserve(1);
1660 1706
     this->data[offset] = (unsigned char)b;
1661 1707
     offset++;
@@ -1730,6 +1776,24 @@ void OutBuffer::prependbyte(unsigned b)
1730 1776
 
1731 1777
 void OutBuffer::writeword(unsigned w)
1732 1778
 {
  1779
+    if (doindent && linehead
  1780
+#if _WIN32
  1781
+        && w != 0x0A0D)
  1782
+#else
  1783
+        && w != '\n')
  1784
+#endif
  1785
+    {
  1786
+        if (level)
  1787
+        {
  1788
+            reserve(level);
  1789
+            for (size_t i=0; i<level; i++)
  1790
+            {
  1791
+                this->data[offset] = '\t';
  1792
+                offset++;
  1793
+            }
  1794
+        }
  1795
+        linehead = 0;
  1796
+    }
1733 1797
     reserve(2);
1734 1798
     *(unsigned short *)(this->data + offset) = (unsigned short)w;
1735 1799
     offset += 2;
@@ -1755,6 +1819,24 @@ void OutBuffer::writeUTF16(unsigned w)
1755 1819
 
1756 1820
 void OutBuffer::write4(unsigned w)
1757 1821
 {
  1822
+    if (doindent && linehead
  1823
+#if _WIN32
  1824
+        && w != 0x000A000D)
  1825
+#else
  1826
+        )
  1827
+#endif
  1828
+    {
  1829
+        if (level)
  1830
+        {
  1831
+            reserve(level);
  1832
+            for (size_t i=0; i<level; i++)
  1833
+            {
  1834
+                this->data[offset] = '\t';
  1835
+                offset++;
  1836
+            }
  1837
+        }
  1838
+        linehead = 0;
  1839
+    }
1758 1840
     reserve(4);
1759 1841
     *(unsigned *)(this->data + offset) = w;
1760 1842
     offset += 4;
2  src/root/root.h
@@ -271,6 +271,8 @@ struct OutBuffer : Object
271 271
     unsigned offset;
272 272
     unsigned size;
273 273
 
  274
+    int doindent, level, linehead;
  275
+
274 276
     OutBuffer();
275 277
     ~OutBuffer();
276 278
     char *extractData();
73  src/statement.c
@@ -860,15 +860,16 @@ void UnrolledLoopStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
860 860
 {
861 861
     buf->writestring("unrolled {");
862 862
     buf->writenl();
  863
+    buf->level++;
863 864
 
864 865
     for (size_t i = 0; i < statements->dim; i++)
865  
-    {   Statement *s;
866  
-
  866
+    {   
  867
+        Statement *s;
867 868
         s = (*statements)[i];
868 869
         if (s)
869 870
             s->toCBuffer(buf, hgs);
870 871
     }
871  
-
  872
+    buf->level--;
872 873
     buf->writeByte('}');
873 874
     buf->writenl();
874 875
 }
@@ -1021,10 +1022,13 @@ void ScopeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1021 1022
 {
1022 1023
     buf->writeByte('{');
1023 1024
     buf->writenl();
  1025
+    buf->level++;
1024 1026
 
1025 1027
     if (statement)
  1028
+    {
1026 1029
         statement->toCBuffer(buf, hgs);
1027  
-
  1030
+    }
  1031
+    buf->level--;
1028 1032
     buf->writeByte('}');
1029 1033
     buf->writenl();
1030 1034
 }
@@ -1484,7 +1488,9 @@ void ForStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
1484 1488
     buf->writenl();
1485 1489
     buf->writebyte('{');
1486 1490
     buf->writenl();
  1491
+    buf->level++;
1487 1492
     body->toCBuffer(buf, hgs);
  1493
+    buf->level--;
1488 1494
     buf->writebyte('}');
1489 1495
     buf->writenl();
1490 1496
 }
@@ -2351,8 +2357,10 @@ void ForeachStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2351 2357
     buf->writenl();
2352 2358
     buf->writebyte('{');
2353 2359
     buf->writenl();
  2360
+    buf->level++;
2354 2361
     if (body)
2355 2362
         body->toCBuffer(buf, hgs);
  2363
+    buf->level--;
2356 2364
     buf->writebyte('}');
2357 2365
     buf->writenl();
2358 2366
 }
@@ -2580,8 +2588,10 @@ void ForeachRangeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2580 2588
     buf->writenl();
2581 2589
     buf->writebyte('{');
2582 2590
     buf->writenl();
  2591
+    buf->level++;
2583 2592
     if (body)
2584 2593
         body->toCBuffer(buf, hgs);
  2594
+    buf->level--;
2585 2595
     buf->writebyte('}');
2586 2596
     buf->writenl();
2587 2597
 }
@@ -2733,12 +2743,21 @@ void IfStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2733 2743
     condition->toCBuffer(buf, hgs);
2734 2744
     buf->writebyte(')');
2735 2745
     buf->writenl();
  2746
+    if (!ifbody->isScopeStatement())
  2747
+        buf->level++;
2736 2748
     ifbody->toCBuffer(buf, hgs);
  2749
+    if (!ifbody->isScopeStatement())
  2750
+        buf->level--;
2737 2751
     if (elsebody)
2738  
-    {   buf->writestring("else");
  2752
+    {   
  2753
+        buf->writestring("else");
2739 2754
         buf->writenl();
  2755
+        if (!elsebody->isScopeStatement())
  2756
+            buf->level++;
2740 2757
         elsebody->toCBuffer(buf, hgs);
2741  
-    }
  2758
+         if (!elsebody->isScopeStatement())
  2759
+            buf->level--;
  2760
+   }
2742 2761
 }
2743 2762
 
2744 2763
 /******************************** ConditionalStatement ***************************/
@@ -2829,9 +2848,11 @@ void ConditionalStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2829 2848
     condition->toCBuffer(buf, hgs);
2830 2849
     buf->writenl();
2831 2850
     buf->writeByte('{');
  2851
+    buf->level++;
2832 2852
     buf->writenl();
2833 2853
     if (ifbody)
2834 2854
         ifbody->toCBuffer(buf, hgs);
  2855
+    buf->level--;
2835 2856
     buf->writeByte('}');
2836 2857
     buf->writenl();
2837 2858
     if (elsebody)
@@ -2840,7 +2861,9 @@ void ConditionalStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2840 2861
         buf->writenl();
2841 2862
         buf->writeByte('{');
2842 2863
         buf->writenl();
  2864
+        buf->level++;
2843 2865
         elsebody->toCBuffer(buf, hgs);
  2866
+        buf->level--;
2844 2867
         buf->writeByte('}');
2845 2868
         buf->writenl();
2846 2869
     }
@@ -2993,9 +3016,9 @@ void PragmaStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2993 3016
         buf->writenl();
2994 3017
         buf->writeByte('{');
2995 3018
         buf->writenl();
2996  
-
  3019
+        buf->level++;
2997 3020
         body->toCBuffer(buf, hgs);
2998  
-
  3021
+        buf->level--;
2999 3022
         buf->writeByte('}');
3000 3023
         buf->writenl();
3001 3024
     }
@@ -3227,9 +3250,12 @@ void SwitchStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
3227 3250
     if (body)
3228 3251
     {
3229 3252
         if (!body->isScopeStatement())
3230  
-        {   buf->writebyte('{');
  3253
+        {   
  3254
+            buf->writebyte('{');
3231 3255
             buf->writenl();
  3256
+            buf->level++;
3232 3257
             body->toCBuffer(buf, hgs);
  3258
+            buf->level--;
3233 3259
             buf->writebyte('}');
3234 3260
             buf->writenl();
3235 3261
         }
@@ -3512,7 +3538,8 @@ int DefaultStatement::comeFrom()
3512 3538
 
3513 3539
 void DefaultStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
3514 3540
 {
3515  
-    buf->writestring("default:\n");
  3541
+    buf->writestring("default:");
  3542
+    buf->writenl();
3516 3543
     statement->toCBuffer(buf, hgs);
3517 3544
 }
3518 3545
 
@@ -3546,7 +3573,8 @@ int GotoDefaultStatement::blockExit(bool mustNotThrow)
3546 3573
 
3547 3574
 void GotoDefaultStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
3548 3575
 {
3549  
-    buf->writestring("goto default;\n");
  3576
+    buf->writestring("goto default;");
  3577
+    buf->writenl();
3550 3578
 }
3551 3579
 
3552 3580
 /******************************** GotoCaseStatement ***************************/
@@ -4427,7 +4455,8 @@ void WithStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
4427 4455
 {
4428 4456
     buf->writestring("with (");
4429 4457
     exp->toCBuffer(buf, hgs);
4430  
-    buf->writestring(")\n");
  4458
+    buf->writestring(")");
  4459
+    buf->writenl();
4431 4460
     if (body)
4432 4461
         body->toCBuffer(buf, hgs);
4433 4462
 }
@@ -4650,8 +4679,10 @@ void Catch::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
4650 4679
     buf->writenl();
4651 4680
     buf->writebyte('{');
4652 4681
     buf->writenl();
  4682
+    buf->level++;
4653 4683
     if (handler)
4654 4684
         handler->toCBuffer(buf, hgs);
  4685
+    buf->level--;
4655 4686
     buf->writebyte('}');
4656 4687
     buf->writenl();
4657 4688
 }
@@ -4695,10 +4726,22 @@ Statement *TryFinallyStatement::semantic(Scope *sc)
4695 4726
 
4696 4727
 void TryFinallyStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
4697 4728
 {
4698  
-    buf->printf("try\n{\n");
  4729
+    buf->writestring("try");
  4730
+    buf->writenl();
  4731
+    buf->writebyte('{');
  4732
+    buf->writenl();
  4733
+    buf->level++;
4699 4734
     body->toCBuffer(buf, hgs);
4700  
-    buf->printf("}\nfinally\n{\n");
  4735
+    buf->level--;
  4736
+    buf->writebyte('}');
  4737
+    buf->writenl();
  4738
+    buf->writestring("finally");
  4739
+    buf->writenl();
  4740
+    buf->writebyte('{');
  4741
+    buf->writenl();
  4742
+    buf->level++;
4701 4743
     finalbody->toCBuffer(buf, hgs);
  4744
+    buf->level--;
4702 4745
     buf->writeByte('}');
4703 4746
     buf->writenl();
4704 4747
 }
@@ -5176,6 +5219,7 @@ int AsmStatement::blockExit(bool mustNotThrow)
5176 5219
 void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
5177 5220
 {
5178 5221
     buf->writestring("asm { ");
  5222
+    buf->level++;
5179 5223
     Token *t = tokens;
5180 5224
     while (t)
5181 5225
     {
@@ -5197,6 +5241,7 @@ void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
5197 5241
         }
5198 5242
         t = t->next;
5199 5243
     }
  5244
+    buf->level--;
5200 5245
     buf->writestring("; }");
5201 5246
     buf->writenl();
5202 5247
 }
5  src/struct.c
@@ -20,6 +20,7 @@
20 20
 #include "id.h"
21 21
 #include "statement.h"
22 22
 #include "template.h"
  23
+#include "hdrgen.h"
23 24
 
24 25
 FuncDeclaration *StructDeclaration::xerreq;     // object.xopEquals
25 26
 
@@ -705,13 +706,13 @@ void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
705 706
     buf->writenl();
706 707
     buf->writeByte('{');
707 708
     buf->writenl();
  709
+    buf->level++;
708 710
     for (size_t i = 0; i < members->dim; i++)
709 711
     {
710 712
         Dsymbol *s = (*members)[i];
711  
-
712  
-        buf->writestring("    ");
713 713
         s->toCBuffer(buf, hgs);
714 714
     }
  715
+    buf->level--;
715 716
     buf->writeByte('}');
716 717
     buf->writenl();
717 718
 }
2  src/template.c
@@ -2181,11 +2181,13 @@ void TemplateDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2181 2181
         buf->writenl();
2182 2182
         buf->writebyte('{');
2183 2183
         buf->writenl();
  2184
+        buf->level++;
2184 2185
         for (size_t i = 0; i < members->dim; i++)
2185 2186
         {
2186 2187
             Dsymbol *s = (*members)[i];
2187 2188
             s->toCBuffer(buf, hgs);
2188 2189
         }
  2190
+        buf->level--;
2189 2191
         buf->writebyte('}');
2190 2192
         buf->writenl();
2191 2193
         hgs->tpltMember--;
1  src/version.c
@@ -17,6 +17,7 @@
17 17
 #include "cond.h"
18 18
 #include "version.h"
19 19
 #include "module.h"
  20
+#include "hdrgen.h"
20 21
 
21 22
 /* ================================================== */
22 23
 
663  test/compilable/extra-files/header.di
@@ -7,146 +7,147 @@ typedef double mydbl = 10;
7 7
 int main()
8 8
 in
9 9
 {
10  
-assert(1 + (2 + 3) == -(1 - 2 * 3));
  10
+	assert(1 + (2 + 3) == -(1 - 2 * 3));
11 11
 }
12 12
 out(result)
13 13
 {
14  
-assert(result == 0);
  14
+	assert(result == 0);
15 15
 }
16 16
 body
17 17
 {
18  
-float f = (float).infinity;
19  
-int i = cast(int)f;
20  
-writeln((i , 1),2);
21  
-writeln(cast(int)(float).max);
22  
-assert(i == cast(int)(float).max);
23  
-assert(i == -2147483648u);
24  
-return 0;
  18
+	float f = (float).infinity;
  19
+	int i = cast(int)f;
  20
+	writeln((i , 1),2);
  21
+	writeln(cast(int)(float).max);
  22
+	assert(i == cast(int)(float).max);
  23
+	assert(i == -2147483648u);
  24
+	return 0;
25 25
 }
26 26
 template Foo(T,int V)
27 27
 {
28  
-int bar(double d, int x)
29  
-{
30  
-if (d)
31  
-{
32  
-d++;
33  
-}
34  
-else
35  
-d--;
36  
-asm { naked; }
37  
-asm { mov EAX,3; }
38  
-for (;;)
39  
-{
40  
-{
41  
-d = d + 1;
42  
-}
43  
-}
44  
-{
45  
-for (int i = 0;
46  
- i < 10; i++)
47  
-{
48  
-{
49  
-d = i ? d + 1 : 5;
50  
-}
51  
-}
52  
-}
53  
-char[] s;
54  
-foreach (char c; s)
55  
-{
56  
-d *= 2;
57  
-if (d)
58  
-break;
59  
-else
60  
-continue;
61  
-}
62  
-switch (V)
63  
-{
64  
-case 1:
65  
-{
66  
-}
67  
-case 2:
68  
-{
69  
-break;
70  
-}
71  
-case 3:
72  
-{
73  
-goto case 1;
74  
-}
75  
-case 4:
76  
-{
77  
-goto default;
78  
-}
79  
-default:
80  
-{
81  
-d /= 8;
82  
-break;
83  
-}
84  
-}
85  
-enum Label 
86  
-{
87  
-A,
88  
-B,
89  
-C,
90  
-}
91  
-;
92  
-void fswitch(Label l)
93  
-{
94  
-final switch (l)
95  
-{
96  
-case A:
97  
-{
98  
-break;
99  
-}
100  
-case B:
101  
-{
102  
-break;
103  
-}
104  
-case C:
105  
-{
106  
-break;
107  
-}
108  
-}
109  
-}
110  
-loop:
111