示例#1
0
        public Node VisitExpression(MemberExpression exp)
        {
            var changed = false;
            var newCode = exp;

            foreach (var edit in _edits)
            {
                if (edit.CanApply(exp))
                {
                    changed = true;
                    if (edit is Update)
                    {
                        newCode = (MemberExpression)edit.ModifiedNode.InnerNode;
                    }
                    else if (edit is Insert)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
            if (changed)
            {
                return(newCode);
            }

            return(new MemberExpression(VisitExpression(exp.Target), newCode.Name));
        }
示例#2
0
        public override void PostWalk(MemberExpression node)
        {
            Content("{0}.{1}", Content(), node.Name);

            CommonPostWalk(node);
        }
示例#3
0
 public override bool Walk(MemberExpression node)
 {
     CommonWalk(node);
     return true;
 }
		/// <summary>
		/// Deserializes an expression of the form:
		/// 
		/// System.Drawing.Color.FromArgb(0, 192, 0)
		/// </summary>
		object DeserializeMethodCallExpression(CallExpression callExpression, MemberExpression memberExpression)
		{
			PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);			
			Type type = GetType(field);
			if (type != null) {
				foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) {
					if (method.Name == field.MemberName) {
						if (method.GetParameters().Length == callExpression.Args.Count) {
							return method.Invoke(null, GetArguments(callExpression).ToArray());
						}
					}
				}
			} else {
				// Maybe it is a call to a constructor?
				type = componentCreator.GetType(field.FullMemberName);
				if (type != null) {
					return componentCreator.CreateInstance(type, GetArguments(callExpression), null, false);
				}
			}
			return null;
		}
		Type GetType(MemberExpression memberExpression)
		{
			string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);
			return componentCreator.GetType(typeName);
		}
		void ThrowCouldNotFindTypeException(MemberExpression memberExpression)
		{
			string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);
			throw new PythonComponentWalkerException(String.Format(StringParser.Parse("${res:ICSharpCode.PythonBinding.UnknownTypeName}"), typeName));
		}
示例#7
0
        //  decorators ::=
        //      decorator+
        //  decorator ::=
        //      "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE
        private List<Expression> ParseDecorators() {
            List<Expression> decorators = new List<Expression>();

            while (MaybeEat(TokenKind.At)) {
                var start = GetStart();
                Expression decorator = new NameExpression(ReadName());
                decorator.SetLoc(_globalParent, start, GetEnd());
                while (MaybeEat(TokenKind.Dot)) {
                    string name = ReadNameMaybeNone();
                    decorator = new MemberExpression(decorator, name);
                    decorator.SetLoc(_globalParent, GetStart(), GetEnd());
                }
                decorator.SetLoc(_globalParent, start, GetEnd());

                if (MaybeEat(TokenKind.LeftParenthesis)) {
                    if (_sink != null) {
                        _sink.StartParameters(GetSourceSpan());
                    }
                    Arg[] args = FinishArgumentList(null);
                    decorator = FinishCallExpr(decorator, args);
                }
                decorator.SetLoc(_globalParent, start, GetEnd());
                EatNewLine();

                decorators.Add(decorator);
            }

            return decorators;
        }
		/// <summary>
		/// Gets the member names that make up the MemberExpression in order.
		/// </summary>
		public static string[] GetMemberNames(MemberExpression expression)
		{
			List<string> names = new List<string>();
			while (expression != null) {
				names.Insert(0, expression.Name);
				
				NameExpression nameExpression = expression.Target as NameExpression;
				expression = expression.Target as MemberExpression;
				if (expression == null) {
					if (nameExpression != null) {
						names.Insert(0, nameExpression.Name);
					}
				}
			}
			return names.ToArray();
		}
        // We only try to add simple member expr, such "self.something",
        // which are most likely all the possibilites to declare/initialize
        // a class attribute (field).
        static bool IsSelfAttr(PythonFunction func, MemberExpression expr, out string attrName)
        {
            attrName = null;

            // NameExpression -> Simple name access
            var target = expr.Target as NameExpression;
            if (target == null)
                return false;

            if (func.Arguments.Count == 0 ||
                func.Arguments [0].Name != target.Name)
                return false;

            attrName = expr.Name; // self.Name
            return true;
        }
		/// <summary>
		/// Creates a PythonControlField from a member expression:
		/// 
		/// self._textBox1
		/// self._textBox1.Name
		/// </summary>
		public static PythonControlFieldExpression Create(MemberExpression expression)
		{
			return Create(GetMemberNames(expression));
		}
		/// <summary>
		/// Gets the fully qualified name being referenced in the MemberExpression.
		/// </summary>
		public static string GetMemberName(MemberExpression expression)
		{
			return GetMemberName(GetMemberNames(expression));
		}
示例#12
0
		void AddBaseType(MemberExpression memberExpression)
		{
			string name = PythonControlFieldExpression.GetMemberName(memberExpression);
			AddBaseType(name);
		}
示例#13
0
 public string Visit(PyAst.MemberExpression node) => $"{Visit(node.Target)}.{node.Name}";
示例#14
0
		public override bool Walk(MemberExpression node)
		{
			writer.WriteLine("Member: " + node.Name);
			return base.Walk(node);
		}
		/// <summary>
		/// Gets the property value from the member expression. The member expression is taken from the
		/// right hand side of an assignment.
		/// </summary>
		object GetPropertyValueFromAssignmentRhs(MemberExpression memberExpression)
		{
			return deserializer.Deserialize(memberExpression);
		}
		public override void PostWalk(MemberExpression node)
		{
			base.PostWalk(node);
			Console.WriteLine("MEMBER EXPRESSION: Name: " + node.Name + ", Target:" + node.Target);
		}
		/// <summary>
		/// Returns true if the expression is of the form:
		/// 
		/// resources.GetObject(...) or
		/// resources.GetString(...)
		/// </summary>
		bool IsResource(MemberExpression memberExpression)
		{
			string fullName = PythonControlFieldExpression.GetMemberName(memberExpression);
			return fullName.StartsWith("resources.", StringComparison.InvariantCultureIgnoreCase);
		}
示例#18
0
 public override bool Walk(MemberExpression node) {
     node.Walk(_fc);
     return false;
 }
示例#19
0
 internal Attribute(MemberExpression attr, expr_context ctx)
     : this() {
     _value = Convert(attr.Target);
     _attr = attr.Name;
     _ctx = ctx;
 }
		/// <summary>
		/// Deserializes expressions of the form:
		/// 
		/// 1) System.Windows.Forms.Cursors.AppStarting
		/// </summary>
		object Deserialize(MemberExpression memberExpression)
		{
			PythonControlFieldExpression field = PythonControlFieldExpression.Create(memberExpression);			
			Type type = GetType(field);
			if (type != null) {
				if (type.IsEnum) {
					return Enum.Parse(type, field.MemberName);
				} else {
					BindingFlags propertyBindingFlags = BindingFlags.Public | BindingFlags.GetField | BindingFlags.Static | BindingFlags.Instance;
					PropertyInfo propertyInfo = type.GetProperty(field.MemberName, propertyBindingFlags);
					if (propertyInfo != null) {
						return propertyInfo.GetValue(type, null);
					}
				}
			}
			return componentCreator.GetInstance(PythonControlFieldExpression.GetVariableName(field.MemberName));
		}
示例#21
0
        // trailer: '(' [ arglist_genexpr ] ')' | '[' subscriptlist ']' | '.' NAME
        private Expression AddTrailers(Expression ret, bool allowGeneratorExpression) {
            bool prevAllow = _allowIncomplete;
            try {
                _allowIncomplete = true;
                while (true) {
                    switch (PeekToken().Kind) {
                        case TokenKind.LeftParenthesis:
                            if (!allowGeneratorExpression) return ret;

                            NextToken();
                            Arg[] args = FinishArgListOrGenExpr();
                            CallExpression call;
                            if (args != null) {
                                call = FinishCallExpr(ret, args);
                            } else {
                                call = new CallExpression(ret, new Arg[0]);
                            }

                            call.SetLoc(_globalParent, ret.StartIndex, GetEnd());
                            ret = call;
                            break;
                        case TokenKind.LeftBracket:
                            NextToken();
                            Expression index = ParseSubscriptList();
                            IndexExpression ie = new IndexExpression(ret, index);
                            ie.SetLoc(_globalParent, ret.StartIndex, GetEnd());
                            ret = ie;
                            break;
                        case TokenKind.Dot:
                            NextToken();
                            string name = ReadNameMaybeNone();
                            MemberExpression fe = new MemberExpression(ret, name);
                            fe.SetLoc(_globalParent, ret.StartIndex, GetEnd());
                            ret = fe;
                            break;
                        case TokenKind.Constant:
                            // abc.1, abc"", abc 1L, abc 0j
                            ReportSyntaxError("invalid syntax");
                            return Error();
                        default:
                            return ret;
                    }
                }
            } finally {
                _allowIncomplete = prevAllow;
            }
        }
示例#22
0
 // MemberExpression
 public override bool Walk(MemberExpression node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }