1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using IronPython.Compiler.Ast;
7
namespace ICSharpCode.PythonBinding
9
public class PythonLocalVariableAssignment
11
AssignmentStatement assignment;
12
string variableName = String.Empty;
13
string typeName = String.Empty;
15
public PythonLocalVariableAssignment(AssignmentStatement assignment)
17
this.assignment = assignment;
21
public string TypeName {
22
get { return typeName; }
25
public string VariableName {
26
get { return variableName; }
29
public bool IsLocalVariableAssignment()
31
return !String.IsNullOrEmpty(variableName);
34
void ParseAssignment()
36
NameExpression nameExpression = assignment.Left[0] as NameExpression;
37
CallExpression callExpression = assignment.Right as CallExpression;
38
if ((nameExpression != null) && (callExpression != null)) {
39
variableName = nameExpression.Name;
40
typeName = GetTypeName(callExpression.Target);
45
/// Gets the fully qualified name of the type from the expression.
48
/// The expression is the first target of a call expression.
50
/// A call expression is a method or constructor call (right hand side of expression below):
52
/// a = Root.Test.Class1()
54
/// So the expression passed to this method will be a field expression in the
55
/// above example which refers to Class1. The next target will be a field
56
/// expression referring to Test. The The last target will be a name expression
57
/// referring to Root.
63
/// then the expression will be a name expression referring to Class1.
65
string GetTypeName(Expression expression)
67
NameExpression nameExpression = expression as NameExpression;
68
if (nameExpression != null) {
69
return nameExpression.Name;
71
return PythonControlFieldExpression.GetMemberName(expression as MemberExpression);