Skip to content

Commit

Permalink
Added Visual Studio 2011 solution file.
Browse files Browse the repository at this point in the history
Added generic overloads for code generation methods:
DoSomething(typeof(Foo), Bar) -> DoSomething<Foo>(Bar),
Method(typeof(void), arguments) -> Void(arguments), etc.
  • Loading branch information
yallie committed Apr 13, 2012
1 parent 41070b5 commit 0e99c20
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 4 deletions.
30 changes: 30 additions & 0 deletions RunSharp.2011.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2011
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunSharp", "RunSharp\RunSharp.csproj", "{C835BB75-7955-4315-B52C-FA59E25219F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{2267D578-07C3-46B8-9EC8-E2C33AC920E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeAnalysis|Any CPU = CodeAnalysis|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C835BB75-7955-4315-B52C-FA59E25219F4}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
{C835BB75-7955-4315-B52C-FA59E25219F4}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
{C835BB75-7955-4315-B52C-FA59E25219F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C835BB75-7955-4315-B52C-FA59E25219F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C835BB75-7955-4315-B52C-FA59E25219F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C835BB75-7955-4315-B52C-FA59E25219F4}.Release|Any CPU.Build.0 = Release|Any CPU
{2267D578-07C3-46B8-9EC8-E2C33AC920E7}.CodeAnalysis|Any CPU.ActiveCfg = Release|Any CPU
{2267D578-07C3-46B8-9EC8-E2C33AC920E7}.CodeAnalysis|Any CPU.Build.0 = Release|Any CPU
{2267D578-07C3-46B8-9EC8-E2C33AC920E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2267D578-07C3-46B8-9EC8-E2C33AC920E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2267D578-07C3-46B8-9EC8-E2C33AC920E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2267D578-07C3-46B8-9EC8-E2C33AC920E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions RunSharp/AssemblyGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ public TypeGen Interface(string name, params Type[] interfaces)
return tg;
}

public DelegateGen DelegateVoid(string name)
{
return Delegate(typeof(void), name);
}

public DelegateGen Delegate<T>(string name)
{
return Delegate(typeof(T), name);
}

public DelegateGen Delegate(Type returnType, string name)
{
return new DelegateGen(this, Qualify(name), returnType, (attrs | TypeAttributes.Sealed) & ~(TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit));
Expand Down
15 changes: 15 additions & 0 deletions RunSharp/CodeGen.Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,21 @@ void DoInvoke(Operand invocation)
}

#region Invocation
public void Invoke<T>(string method)
{
Invoke(typeof(T), method);
}

public void Invoke(Type target, string method)
{
Invoke(target, method, Operand.EmptyArray);
}

public void Invoke<T>(string method, params Operand[] args)
{
Invoke(typeof(T), method, args);
}

public void Invoke(Type target, string method, params Operand[] args)
{
DoInvoke(Static.Invoke(target, method, args));
Expand Down Expand Up @@ -474,6 +484,11 @@ public void While(Operand test)
Begin(new LoopBlock(null, test, null));
}

public Operand ForEach<T>(Operand expression)
{
return ForEach(typeof(T), expression);
}

public Operand ForEach(Type elementType, Operand expression)
{
ForeachBlock fb = new ForeachBlock(elementType, expression);
Expand Down
10 changes: 10 additions & 0 deletions RunSharp/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,21 @@ public Operand Local(Operand init)
return var;
}

public Operand Local<T>()
{
return Local(typeof(T));
}

public Operand Local(Type type)
{
return new _Local(this, type);
}

public Operand Local<T>(Operand init)
{
return Local(typeof(T), init);
}

public Operand Local(Type type, Operand init)
{
Operand var = Local(type);
Expand Down
20 changes: 20 additions & 0 deletions RunSharp/DelegateGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,43 @@ TypeGen GetDelegateType()

#region Custom Attributes

public DelegateGen Attribute<AT>() where AT : Attribute
{
return Attribute(typeof(AT));
}

public DelegateGen Attribute(AttributeType type)
{
BeginAttribute(type);
return this;
}

public DelegateGen Attribute<AT>(params object[] args) where AT : Attribute
{
return Attribute(typeof(AT), args);
}

public DelegateGen Attribute(AttributeType type, params object[] args)
{
BeginAttribute(type, args);
return this;
}

public AttributeGen<DelegateGen> BeginAttribute<AT>() where AT : Attribute
{
return BeginAttribute(typeof(AT));
}

public AttributeGen<DelegateGen> BeginAttribute(AttributeType type)
{
return BeginAttribute(type, EmptyArray<object>.Instance);
}

public AttributeGen<DelegateGen> BeginAttribute<AT>(params object[] args) where AT : Attribute
{
return BeginAttribute(typeof(AT), args);
}

public AttributeGen<DelegateGen> BeginAttribute(AttributeType type, params object[] args)
{
return AttributeGen<DelegateGen>.CreateAndAdd(this, ref customAttributes, AttributeTargets.Delegate, type, args);
Expand Down
25 changes: 24 additions & 1 deletion RunSharp/DynamicMethodGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public sealed class DynamicMethodGen : RoutineGen<DynamicMethodGen>, ICodeGenCon
{
Attributes attrs;
DynamicMethod dm;


public static Attributes Static<TOwner>()
{
return Static(typeof(TOwner));
}

public static Attributes Static(Type owner)
{
return new Attributes(owner, false);
Expand Down Expand Up @@ -78,6 +83,16 @@ public Attributes WithName(string name)
return this;
}

public DynamicMethodGen Void()
{
return Method(typeof(void));
}

public DynamicMethodGen Method<T>()
{
return Method(typeof(T));
}

public DynamicMethodGen Method(Type returnType)
{
return new DynamicMethodGen(this, returnType);
Expand Down Expand Up @@ -183,4 +198,12 @@ bool ICodeGenContext.SupportsScopes

#endregion
}

public static class DynamicMethodExtensions
{
public static T CreateDelegate<T>(this DynamicMethod dm)
{
return (T)(object)dm.CreateDelegate(typeof(T));
}
}
}
20 changes: 20 additions & 0 deletions RunSharp/EventGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,43 @@ public override Type Type

#region Custom Attributes

public EventGen Attribute<AT>() where AT : Attribute
{
return Attribute(typeof(AT));
}

public EventGen Attribute(AttributeType type)
{
BeginAttribute(type);
return this;
}

public EventGen Attribute<AT>(params object[] args) where AT : Attribute
{
return Attribute(typeof(AT), args);
}

public EventGen Attribute(AttributeType type, params object[] args)
{
BeginAttribute(type, args);
return this;
}

public AttributeGen<EventGen> BeginAttribute<AT>() where AT : Attribute
{
return BeginAttribute(typeof(AT));
}

public AttributeGen<EventGen> BeginAttribute(AttributeType type)
{
return BeginAttribute(type, EmptyArray<object>.Instance);
}

public AttributeGen<EventGen> BeginAttribute<AT>(params object[] args) where AT : Attribute
{
return BeginAttribute(typeof(AT), args);
}

public AttributeGen<EventGen> BeginAttribute(AttributeType type, params object[] args)
{
return AttributeGen<EventGen>.CreateAndAdd(this, ref customAttributes, AttributeTargets.Event, type, args);
Expand Down
30 changes: 30 additions & 0 deletions RunSharp/Exp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ public static class Exp
{
#region Construction expressions

public static Operand New<T>()
{
return New(typeof(T));
}

public static Operand New(Type type)
{
return New(type, Operand.EmptyArray);
}

public static Operand New<T>(params Operand[] args)
{
return New(typeof(T), args);
}

public static Operand New(Type type, params Operand[] args)
{
ApplicableFunction ctor = OverloadResolver.Resolve(TypeInfo.GetConstructors(type), args);
Expand All @@ -49,21 +59,41 @@ public static Operand New(Type type, params Operand[] args)
return new NewObject(ctor, args);
}

public static Operand NewArray<T>(params Operand[] indexes)
{
return NewArray(typeof(T), indexes);
}

public static Operand NewArray(Type type, params Operand[] indexes)
{
return new NewArray(type, indexes);
}

public static Operand NewInitializedArray<T>(params Operand[] elements)
{
return NewInitializedArray(typeof(T), elements);
}

public static Operand NewInitializedArray(Type type, params Operand[] elements)
{
return new InitializedArray(type, elements);
}

public static Operand NewDelegate<T>(Type target, string method)
{
return NewDelegate(typeof(T), target, method);
}

public static Operand NewDelegate(Type delegateType, Type target, string method)
{
return new NewDelegate(delegateType, target, method);
}

public static Operand NewDelegate<T>(Operand target, string method)
{
return NewDelegate(typeof(T), target, method);
}

public static Operand NewDelegate(Type delegateType, Operand target, string method)
{
return new NewDelegate(delegateType, target, method);
Expand Down
20 changes: 20 additions & 0 deletions RunSharp/FieldGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,43 @@ public override Type Type

#region Custom Attributes

public FieldGen Attribute<AT>() where AT : Attribute
{
return Attribute(typeof(AT));
}

public FieldGen Attribute(AttributeType type)
{
BeginAttribute(type);
return this;
}

public FieldGen Attribute<AT>(params object[] args) where AT : Attribute
{
return Attribute(typeof(AT), args);
}

public FieldGen Attribute(AttributeType type, params object[] args)
{
BeginAttribute(type, args);
return this;
}

public AttributeGen<FieldGen> BeginAttribute<AT>() where AT : Attribute
{
return BeginAttribute(typeof(AT));
}

public AttributeGen<FieldGen> BeginAttribute(AttributeType type)
{
return BeginAttribute(type, EmptyArray<object>.Instance);
}

public AttributeGen<FieldGen> BeginAttribute<AT>(params object[] args) where AT : Attribute
{
return BeginAttribute(typeof(AT), args);
}

public AttributeGen<FieldGen> BeginAttribute(AttributeType type, params object[] args)
{
return AttributeGen<FieldGen>.CreateAndAdd(this, ref customAttributes, AttributeTargets.Field, type, args);
Expand Down
5 changes: 5 additions & 0 deletions RunSharp/Operand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,11 @@ public Operand Conditional(Operand ifTrue, Operand ifFalse)
return new Conditional(Type == typeof(bool) ? this : IsTrue(), ifTrue, ifFalse);
}

public Operand Cast<T>()
{
return Cast(typeof(T));
}

public Operand Cast(Type type)
{
return new Cast(this, type);
Expand Down
20 changes: 20 additions & 0 deletions RunSharp/ParameterGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,43 @@ internal ParameterGen(ParameterGenCollection owner, int position, Type parameter

#region Custom Attributes

public ParameterGen Attribute<AT>() where AT : Attribute
{
return Attribute(typeof(AT));
}

public ParameterGen Attribute(AttributeType type)
{
BeginAttribute(type);
return this;
}

public ParameterGen Attribute<AT>(params object[] args) where AT : Attribute
{
return Attribute(typeof(AT), args);
}

public ParameterGen Attribute(AttributeType type, params object[] args)
{
BeginAttribute(type, args);
return this;
}

public AttributeGen<ParameterGen> BeginAttribute<AT>() where AT : Attribute
{
return BeginAttribute(typeof(AT));
}

public AttributeGen<ParameterGen> BeginAttribute(AttributeType type)
{
return BeginAttribute(type, EmptyArray<object>.Instance);
}

public AttributeGen<ParameterGen> BeginAttribute<AT>(params object[] args) where AT : Attribute
{
return BeginAttribute(typeof(AT), args);
}

public AttributeGen<ParameterGen> BeginAttribute(AttributeType type, params object[] args)
{
return AttributeGen<ParameterGen>.CreateAndAdd(this, ref customAttributes, position == 0 ? AttributeTargets.ReturnValue : AttributeTargets.Parameter, type, args);
Expand Down
Loading

0 comments on commit 0e99c20

Please sign in to comment.