DI Generation Needs your Help!

Adam Wilson flyboynw at gmail.com
Mon Dec 19 00:11:25 PST 2011


As you may all be aware, I've been trying to improve the automated  
generation of .di files and I now have something that I feel is testable.  
Currently the new code only makes the following changes.

1.	Function Implementations are removed
2.	Private Function Declarations are removed.
3.	Variable Initializers, except for const, are removed.

Everything else is left alone. Templates and mixins are not addressed with  
this code and *should* not be modified. That's where I need your help, the  
test cases I have written cover some basic scenarios but I don't have the  
capability to test these changes with the diverse code base that the  
community has created.

drey_ from IRC was kind enough to test build Derelict with the changes and  
has discovered a potential issue around private imports. Derelict uses  
private imports that contain types which are used in function alias  
declarations. As one would expect, this caused many compiler errors.   
Currently, I feel that private imports should be stripped from the DI file  
as they are intended to be internal to the module. However, I want to put  
it to the community to decide, and I would especially appreciate Mr.  
Bright's opinion on private imports in DI files.

If anyone wishes to test my changes against their code, you can download  
them from my git account here:  
https://LightBender@github.com/LightBender/dmd.git
I only ask that you inform me of anything broken and provide a test case  
that reproduces the error.

The following is my current test case, it comes from a module in my  
project that has been modified to include the various tests I and others  
have been able to think of. I know for a fact that it is missing a great  
number of features available in D, and I would really appreciate any tests  
you might wish to add to this case.

module Horizon.Collections.Basic;

export void TestFunc(int a) {}
private void TestFunc2(int b) {}

const gss = "__gshared";

export interface IEnumerator
{
	export @property Object Current();

	export bool MoveNext();
	export void Reset();
}

export interface ICollection
{
	export @property uint Count();

	export int opApply(int delegate(ref Object) dg);
	export IEnumerator GetEnumerator();
}

export interface IList : ICollection
{
	export @property bool IsFixedSize();
	export @property bool IsReadOnly();

	export void Add(Object Value);
	export void Clear();
	export bool Contains(Object Value);
	export Object opIndex(ulong Index);
	export void opIndexAssign(Object Value, ulong Index);
	export int IndexOf(Object Value);
	export void Insert(ulong Index, Object Value);
	export void Remove(Object Value);
	export void RemoveAt(ulong Index);
}

export struct StructTesting
{
	private int i = 0;
	protected int j = 1;

	export void ExportedStructFunc() {}
	private void PrivateStructFunc() {}
}

export class List : IList
{
	export this(uint Capacity)
	{
		vCapacity = Capacity;
		internal = new Object[4];
	}

	private Object[] internal;

	private uint vCapacity = 0;
	export @property uint Capacity()
	{
		return vCapacity;
	}

	private uint vCount = 0;
	export @property uint Count()
	{
		return vCount;
	}

	export void Add(Object Value)
	{
		if(vCount == vCapacity) internal.length *= 2;

		internal[++vCount] = Value;
	}

	export int opApply(int delegate(ref Object) dg) { return 0; }
	export IEnumerator GetEnumerator() {return null;}

	export @property bool IsFixedSize() {return false;}
	export @property bool IsReadOnly() {return false;}

	export void Clear() { return; }
	export bool Contains(Object Value) {return false;}
	export Object opIndex(ulong Index) {return null;}
	export void opIndexAssign(Object Value, ulong Index) {}
	export int IndexOf(Object Value) {return 0;}
	export void Insert(ulong Index, Object Value) {}
	export void Remove(Object Value) {}
	export void RemoveAt(ulong Index) {}
	private int FooTest(int c) { return c*2; }
	protected int ProtectedTest(int d) { return d*3; }
}



This is the DI file as exported with the generation changes:

// D import file generated from 'Basic.d'
module Horizon.Collections.Basic;
export void TestFunc(int a);
const gss = "__gshared";
export interface IEnumerator
{
     export @property Object Current();

     export bool MoveNext();
     export void Reset();
}

export interface ICollection
{
     export @property uint Count();

     export int opApply(int delegate(ref Object) dg);
     export IEnumerator GetEnumerator();
}

export interface IList : ICollection
{
     export @property bool IsFixedSize();

     export @property bool IsReadOnly();

     export void Add(Object Value);
     export void Clear();
     export bool Contains(Object Value);
     export Object opIndex(ulong Index);
     export void opIndexAssign(Object Value, ulong Index);
     export int IndexOf(Object Value);
     export void Insert(ulong Index, Object Value);
     export void Remove(Object Value);
     export void RemoveAt(ulong Index);
}

export struct StructTesting
{
     private int i;

     protected int j;

     export void ExportedStructFunc();
}

export class List : IList
{
     export this(uint Capacity);
     private Object[] internal;

     private uint vCapacity;

     export @property uint Capacity();

     private uint vCount;

     export @property uint Count();

     export void Add(Object Value);
     export int opApply(int delegate(ref Object) dg);
     export IEnumerator GetEnumerator();
     export @property bool IsFixedSize();

     export @property bool IsReadOnly();

     export void Clear();
     export bool Contains(Object Value);
     export Object opIndex(ulong Index);
     export void opIndexAssign(Object Value, ulong Index);
     export int IndexOf(Object Value);
     export void Insert(ulong Index, Object Value);
     export void Remove(Object Value);
     export void RemoveAt(ulong Index);
     protected int ProtectedTest(int d);
}

Let me know what you think!

-- 
Adam Wilson
Project Coordinator
The Horizon Project
http://www.thehorizonproject.org/


More information about the Digitalmars-d mailing list