Browse files

code gardening

  • Loading branch information...
1 parent 6046e83 commit ea26d134c6883b6c2dc9b4f59cb1ab67e6117387 @bamboo committed May 8, 2012
View
99 src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs
@@ -232,65 +232,72 @@ override public void OnProperty(Property node)
{
if (WasVisited(node))
return;
-
MarkVisited(node);
- Method setter = node.Setter;
- Method getter = node.Getter;
-
Visit(node.Attributes);
Visit(node.Type);
Visit(node.Parameters);
ResolvePropertyOverride(node);
- if (null != getter)
- {
- if (null != node.Type)
- {
- getter.ReturnType = node.Type.CloneNode();
- }
- getter.Parameters.ExtendWithClones(node.Parameters);
+ ProcessGetter(node);
- Visit(getter);
- }
+ if (node.Type == null)
+ node.Type = CodeBuilder.CreateTypeReference(node.LexicalInfo, InferTypeOfProperty(node));
+
+ if (node.Getter != null)
+ node.Getter.ReturnType = node.Type.CloneNode();
+
+ ProcessSetter(node);
+ }
- IType typeInfo = null;
- if (null != node.Type)
+ private void ProcessSetter(Property node)
+ {
+ if (node.Setter != null)
{
- typeInfo = GetType(node.Type);
- }
- else
- {
- if (null != getter)
- {
- typeInfo = GetEntity(node.Getter).ReturnType;
- if (typeInfo == TypeSystemServices.VoidType)
- {
- typeInfo = TypeSystemServices.ObjectType;
- node.Getter.ReturnType = CodeBuilder.CreateTypeReference(getter.LexicalInfo, typeInfo);
- }
- }
- else
- {
- typeInfo = TypeSystemServices.ObjectType;
- }
- node.Type = CodeBuilder.CreateTypeReference(node.LexicalInfo, typeInfo);
+ NormalizeSetterOf(node);
+ Visit(node.Setter);
}
+ }
- if (null != setter)
+ private void ProcessGetter(Property node)
+ {
+ if (node.Getter != null)
{
- ParameterDeclaration parameter = new ParameterDeclaration();
- parameter.Type = CodeBuilder.CreateTypeReference(typeInfo);
- parameter.Name = "value";
- parameter.Entity = new InternalParameter(parameter, node.Parameters.Count+CodeBuilder.GetFirstParameterIndex(setter));
- setter.Parameters.ExtendWithClones(node.Parameters);
- setter.Parameters.Add(parameter);
- setter.Name = "set_" + node.Name;
- Visit(setter);
+ NormalizeGetterOf(node);
+ Visit(node.Getter);
}
}
+ private static void NormalizeGetterOf(Property node)
+ {
+ node.Getter.Parameters.ExtendWithClones(node.Parameters);
+ if (node.Getter.ReturnType == null && node.Type != null)
+ node.Getter.ReturnType = node.Type.CloneNode();
+ }
+
+ private IType InferTypeOfProperty(Property node)
+ {
+ if (node.Getter == null)
+ return TypeSystemServices.ObjectType;
+
+ var getterType = GetEntity(node.Getter).ReturnType;
+ if (getterType != TypeSystemServices.VoidType)
+ return getterType;
+
+ return TypeSystemServices.ObjectType;
+ }
+
+ private void NormalizeSetterOf(Property node)
+ {
+ var setter = node.Setter;
+ setter.Name = "set_" + node.Name;
+
+ var setterParameters = setter.Parameters;
+ setterParameters.ExtendWithClones(node.Parameters);
+ setterParameters.Add(CodeBuilder.CreateParameterDeclaration(CodeBuilder.GetFirstParameterIndex(setter) + setterParameters.Count, "value", GetType(node.Type)));
+ }
+
override public void OnStatementTypeMember(StatementTypeMember node)
{
// statement type members are later
@@ -337,7 +344,7 @@ override public void OnField(Field node)
CheckFieldType(node.Type);
}
- bool IsValidLiteralInitializer(Expression e)
+ static bool IsValidLiteralInitializer(Expression e)
{
switch (e.NodeType)
{
@@ -346,9 +353,7 @@ bool IsValidLiteralInitializer(Expression e)
case NodeType.DoubleLiteralExpression:
case NodeType.NullLiteralExpression:
case NodeType.StringLiteralExpression:
- {
- return true;
- }
+ return true;
}
return false;
}
@@ -1056,7 +1061,7 @@ IProperty ResolvePropertyOverride(IProperty p, IEntity[] candidates)
return null;
}
- bool CheckOverrideSignature(IProperty p, IProperty candidate)
+ static bool CheckOverrideSignature(IProperty p, IProperty candidate)
{
return TypeSystemServices.CheckOverrideSignature(p.GetParameters(), candidate.GetParameters());
}
View
1 src/Boo.Lang.Compiler/TypeSystem/Services/TypeCompatibilityRules.cs
@@ -26,7 +26,6 @@
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
-
namespace Boo.Lang.Compiler.TypeSystem.Services
{
public static class TypeCompatibilityRules

0 comments on commit ea26d13

Please sign in to comment.