Browse Source

Merge e729a02051 into 8641fed046

pull/334/merge
figment 9 years ago committed by GitHub
parent
commit
771fe9857e
  1. 1
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  2. 29
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConstructorInfo.cs
  3. 972
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
  4. 69
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PrefixExpressionExtractor.cs

1
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -100,6 +100,7 @@
<Compile Include="Src\CompilingOptionsPanel.cs" /> <Compile Include="Src\CompilingOptionsPanel.cs" />
<Compile Include="Src\IPythonResolver.cs" /> <Compile Include="Src\IPythonResolver.cs" />
<Compile Include="Src\MemberName.cs" /> <Compile Include="Src\MemberName.cs" />
<Compile Include="Src\PrefixExpressionExtractor.cs" />
<Compile Include="Src\PythonBuiltInModuleMemberName.cs" /> <Compile Include="Src\PythonBuiltInModuleMemberName.cs" />
<Compile Include="Src\PythonClass.cs" /> <Compile Include="Src\PythonClass.cs" />
<Compile Include="Src\PythonClassFields.cs" /> <Compile Include="Src\PythonClassFields.cs" />

29
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/ConstructorInfo.cs

@ -9,35 +9,46 @@ namespace ICSharpCode.PythonBinding
{ {
public class PythonConstructorInfo public class PythonConstructorInfo
{ {
ConstructorDeclaration constructor; private ConstructorDeclaration constructor;
List<FieldDeclaration> fields = new List<FieldDeclaration>(); private List<FieldDeclaration> fields = new List<FieldDeclaration>();
private List<PropertyDeclaration> properties = new List<PropertyDeclaration>();
PythonConstructorInfo(ConstructorDeclaration constructor, List<FieldDeclaration> fields) private PythonConstructorInfo(ConstructorDeclaration constructor,
List<FieldDeclaration> fields, List<PropertyDeclaration> properties)
{ {
this.constructor = constructor; this.constructor = constructor;
this.fields = fields; this.fields = fields;
this.properties = properties;
} }
/// <summary> /// <summary>
/// Gets the constructor information from a type declaration. Returns null if there is no /// Gets the constructor information from a type declaration.
/// constructor defined or if there are no fields defined.
/// </summary> /// </summary>
/// <returns>Returns null if there is no constructor defined or
/// if there are no fields/properties defined.</returns>
public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type) public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type)
{ {
List<FieldDeclaration> fields = new List<FieldDeclaration>(); List<FieldDeclaration> fields = new List<FieldDeclaration>();
List<PropertyDeclaration> properties = new List<PropertyDeclaration>();
ConstructorDeclaration constructor = null; ConstructorDeclaration constructor = null;
foreach (INode node in type.Children) { foreach (INode node in type.Children) {
ConstructorDeclaration currentConstructor = node as ConstructorDeclaration; ConstructorDeclaration currentConstructor = node as ConstructorDeclaration;
FieldDeclaration field = node as FieldDeclaration; FieldDeclaration field = node as FieldDeclaration;
PropertyDeclaration property = node as PropertyDeclaration;
if (currentConstructor != null) { if (currentConstructor != null) {
constructor = currentConstructor; constructor = currentConstructor;
} else if (field != null) { } else if (field != null) {
fields.Add(field); fields.Add(field);
} else if (property != null) {
if (property.HasGetRegion && property.GetRegion.Block.IsNull
&& property.HasSetRegion && property.SetRegion.Block.IsNull) {
properties.Add(property); // basically anonymous backed property
}
} }
} }
if ((fields.Count > 0) || (constructor != null)) { if ((properties.Count > 0) || (fields.Count > 0) || (constructor != null)) {
return new PythonConstructorInfo(constructor, fields); return new PythonConstructorInfo(constructor, fields, properties);
} }
return null; return null;
} }
@ -49,5 +60,9 @@ namespace ICSharpCode.PythonBinding
public List<FieldDeclaration> Fields { public List<FieldDeclaration> Fields {
get { return fields; } get { return fields; }
} }
public List<PropertyDeclaration> Properties {
get { return properties; }
}
} }
} }

972
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs

File diff suppressed because it is too large Load Diff

69
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PrefixExpressionExtractor.cs

@ -0,0 +1,69 @@
using System.Collections.Generic;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// This Vistor is used to locate Prefix expressions and insert them
/// in statement block prior to owned statement. This is probably expensive
/// but without caching on statement writes no easy way to do it.
/// May be faster to do once per Method to see if any Prefix exist at all
/// and then disable checks while in that method
/// </summary>
internal class PrefixExpressionExtractor : NodeTrackingAstVisitor
{
readonly List<Expression> statements = new List<Expression>();
private int statementRecursion;
public List<Expression> Statements
{
get { return statements; }
}
public void Reset()
{
statementRecursion = 0;
}
protected override void BeginVisit(INode node)
{
if (node is Statement)
statementRecursion++;
base.BeginVisit(node);
}
protected override void EndVisit(INode node)
{
if (node is Statement)
statementRecursion--;
base.EndVisit(node);
}
public override object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
// only accumulate if current statement is active. And also not immediate parent
if (statementRecursion == 1 && !(unaryOperatorExpression.Parent is Statement)) {
switch (unaryOperatorExpression.Op) {
case UnaryOperatorType.Increment:
case UnaryOperatorType.Decrement:
statements.Add(unaryOperatorExpression);
break;
}
}
return base.TrackedVisitUnaryOperatorExpression(unaryOperatorExpression, data);
}
public override object TrackedVisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data)
{
if (statementRecursion == 1 && !(anonymousMethodExpression.Parent is Statement)) {
statements.Add(anonymousMethodExpression);
}
return null;
}
public override object TrackedVisitLambdaExpression(LambdaExpression lambdaExpression, object data)
{
if (statementRecursion == 1 && !(lambdaExpression.Parent is Statement)) {
if (!lambdaExpression.StatementBody.IsNull)
statements.Add(lambdaExpression);
}
return base.TrackedVisitLambdaExpression(lambdaExpression, data);
}
}
}
Loading…
Cancel
Save