コード例 #1
0
		public override bool Walk(CallExpression node)
		{
			if (foundVariableAssignment) {
				typeName = GetTypeName(node.Target);
			}
			return base.Walk(node);
		}
コード例 #2
0
		bool IsPropertyFunctionBeingCalled(CallExpression callExpression)
		{
			NameExpression nameExpression = callExpression.Target as NameExpression;
			if (nameExpression != null) {
				return nameExpression.Name == "property";
			}
			return false;
		}
コード例 #3
0
		/// <summary>
		/// Gets the arguments passed to the call expression.
		/// </summary>
		public List<object> GetArguments(CallExpression expression)
		{
			List<object> args = new List<object>();
			foreach (Arg a in expression.Args) {
				args.Add(Deserialize(a.Expression));
			}
			return args;
		}		
コード例 #4
0
		public void TypeName_CallExpressionTargetIsNotNameOrMemberExpression_ReturnsEmptyStringAndDoesNotGetStuckInInfiniteLoop()
		{
			string code = "a = 2";
			AssignmentStatement statement = PythonParserHelper.GetAssignmentStatement(code);
			Expression constantExpression = statement.Right;
			
			CallExpression callExpression = new CallExpression(constantExpression, new Arg[0]);
			List<Expression> expressions = new List<Expression>(statement.Left);
			statement = new AssignmentStatement(expressions.ToArray(), callExpression);
			
			PythonLocalVariableAssignment localVariableAssignment = new PythonLocalVariableAssignment(statement);
			string typeName = localVariableAssignment.TypeName;
			
			Assert.AreEqual(String.Empty, typeName);
		}
コード例 #5
0
 public override bool Walk(CallExpression node)
 {
     node.Target?.Walk(this);
     foreach (var arg in node.Args)
     {
         if (arg is StarredExpression starred)
         {
             starred.Value.Walk(this);
         }
         else
         {
             arg.Walk(this);
         }
     }
     foreach (var arg in node.Kwargs)
     {
         arg.Walk(this);
     }
     ;
     return(false);
 }
コード例 #6
0
        // CallExpression
        public override bool Walk(CallExpression node)
        {
            node.Parent = _currentScope;

            if (node.Target is NameExpression nameExpr && nameExpr.Name == "super" && _currentScope is FunctionDefinition func)
            {
                if (node.Args.Length == 0 && func.ParameterNames.Length > 0)
                {
                    if (ShouldExpandSuperSyntaxSugar(node))
                    {
                        // if `super()` is referenced in a class method.
                        _currentScope.Reference(node.Parent.Parent.Name);
                        node.ImplicitArgs.Add(new Arg(new NameExpression(node.Parent.Parent.Name)));
                        node.ImplicitArgs.Add(new Arg(new NameExpression(func.ParameterNames[0])));
                    }
                    else
                    {
                        // otherwise, fallback to default implementation.
                        _currentScope.Reference("__class__");
                        node.ImplicitArgs.Add(new Arg(new NameExpression("__class__")));
                        node.ImplicitArgs.Add(new Arg(new NameExpression(func.ParameterNames[0])));
                    }
                }

                bool ShouldExpandSuperSyntaxSugar(CallExpression node)
                {
                    if (!(node.Parent is FunctionDefinition))
                    {
                        return(false);
                    }
                    if (!(node.Parent.Parent is ClassDefinition))
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            return(base.Walk(node));
        }
コード例 #7
0
 // CallExpression
 public bool Walk(CallExpression node)
 {
     return Process(node);
 }
コード例 #8
0
 public string Visit(PyAst.CallExpression node)
 {
     return($"{Visit(node.Target)}({string.Join(", ", node.Args.Select(a => Visit(a))) })");
 }
コード例 #9
0
		/// <summary>
		/// Walks a method call. Typical method calls are:
		/// 
		/// self._menuItem1.Items.AddRange(...)
		/// 
		/// This method will execute the method call.
		/// </summary>
		void WalkMethodCall(CallExpression node)
		{
			// Try to get the object being called. Try the form first then
			// look for other controls.
			object member = PythonControlFieldExpression.GetMember(component, node);
			PythonControlFieldExpression field = PythonControlFieldExpression.Create(node);
			if (member == null) {
				member = field.GetMember(componentCreator);
			}
			
			// Execute the method on the object.
			if (member != null) {
				object[] args = deserializer.GetArguments(node).ToArray();
				InvokeMethod(member, field.MethodName, args);
			}
		}
コード例 #10
0
 public virtual void PostWalk(CallExpression node)
 {
 }
コード例 #11
0
ファイル: JavascriptGenerator.cs プロジェクト: valdisz/PyToJs
        public override void PostWalk(CallExpression node)
        {
            List<string> args = new List<string>();
            for (int i = 0; i < node.Args.Count; i++)
            {
                args.Add(Content());
            }
            args.Reverse();

            string name = Content();

            Content(
                "{0}({1})",
                functionNameMapping.ContainsKey(name)
                    ? functionNameMapping[name]
                    : name,
                String.Join(", ", args)
            );

            CommonPostWalk(node);
        }
コード例 #12
0
		public override bool Walk(CallExpression node)
		{			
			if (!FoundInitializeComponentMethod) {
				return false;
			}
				
			if (walkingAssignment) {
				WalkAssignmentRhs(node);
			} else {
				WalkMethodCall(node);
			}
			return false;
		}
コード例 #13
0
 public GeneratorExpression(FunctionDefinition function, CallExpression call)
 {
     this.func = function;
     this.call = call;
 }
コード例 #14
0
 public override void PostWalk(CallExpression node)
 {
     MightNeedLocals |= node.MightNeedLocalsDictionary();
 }
コード例 #15
0
		/// <summary>
		/// Gets the member object that matches the field member.
		/// </summary>
		/// <remarks>
		/// The member names array should contain all items including self, for example:
		///  
		/// self
		/// Controls
		/// </remarks>
		public static object GetMember(object obj, CallExpression expression)
		{
			string[] memberNames = GetMemberNames(expression.Target as MemberExpression);
			if (ContainsSelfReference(memberNames)) {
				return GetMember(obj, memberNames, 1, memberNames.Length - 2);
			}
			return null;
		}
コード例 #16
0
		public override void PostWalk(CallExpression node)
		{
			base.PostWalk(node);
			Console.WriteLine("CALL EXPRESSION: Target: " + node.Target + ", Args: "+ node.Args.StringJoin(", "));
		}
コード例 #17
0
		/// <summary>
		/// Creates a PythonControlField from a call expression:
		/// 
		/// self._menuItem1.Items.AddRange(...)
		/// </summary>
		public static PythonControlFieldExpression Create(CallExpression expression)
		{
			string[] allNames = GetMemberNames(expression.Target as MemberExpression);
			
			// Remove last member since it is the method name.
			int lastItemIndex = allNames.Length - 1;
			string[] memberNames = new string[lastItemIndex];
			Array.Copy(allNames, memberNames, lastItemIndex);
			
			PythonControlFieldExpression field = Create(memberNames);
			field.methodName = allNames[lastItemIndex];
			return field;
		}
コード例 #18
0
 // CallExpression
 public virtual bool Walk(CallExpression node)
 {
     return true;
 }
コード例 #19
0
 public static string Format(CallExpression node)
 {
     return(Format(node.Target) + "(" + node.Args.Format() + ")");
 }
コード例 #20
0
 public void PostWalk(CallExpression node)
 {
     PostProcess(node);
 }
コード例 #21
0
		object GetResource(CallExpression callExpression)
		{
			IResourceReader reader = componentCreator.GetResourceReader(CultureInfo.InvariantCulture);
			if (reader != null) {
				using (ResourceSet resources = new ResourceSet(reader)) {
					List<object> args = deserializer.GetArguments(callExpression);
					return resources.GetObject(args[0] as String);
				}
			}
			return null;
		}
コード例 #22
0
ファイル: JavascriptGenerator.cs プロジェクト: valdisz/PyToJs
 public override bool Walk(CallExpression node)
 {
     CommonWalk(node);
     return true;
 }
コード例 #23
0
ファイル: PythonNameBinder.cs プロジェクト: TerabyteX/main
 public override void PostWalk(CallExpression node)
 {
     if (node.NeedsLocalsDictionary()) {
         _currentScope.NeedsLocalsDictionary = true;
     }
 }
コード例 #24
0
 // CallExpression
 public override bool Walk(CallExpression node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }
コード例 #25
0
ファイル: _ast.cs プロジェクト: rchandrashekara/main
            internal Call(CallExpression call)
                : this() {
                _args = PythonOps.MakeEmptyList(call.Args.Count);
                _keywords = new PythonList();
                _func = Convert(call.Target);
                foreach (IronPython.Compiler.Ast.Arg arg in call.Args) {

                    if (arg.Name == null)
                        _args.Add(Convert(arg.Expression));
                    else if (arg.Name == "*")
                        _starargs = Convert(arg.Expression);
                    else if (arg.Name == "**")
                        _kwargs = Convert(arg.Expression);
                    else
                        _keywords.Add(new keyword(arg));
                }
            }
コード例 #26
0
		/// <summary>
		/// Walks the right hand side of an assignment where the assignment expression is a call expression.
		/// Typically the call expression will be a constructor call.
		/// 
		/// Constructor call: System.Windows.Forms.Form()
		/// </summary>
		void WalkAssignmentRhs(CallExpression node)
		{
			MemberExpression memberExpression = node.Target as MemberExpression;
			if (memberExpression != null) {
				string name = fieldExpression.GetInstanceName(componentCreator);
				object instance = CreateInstance(name, node);
				if (instance != null) {
					if (!fieldExpression.SetPropertyValue(componentCreator, instance)) {
						AddComponent(fieldExpression.MemberName, instance);
					}
				} else {
					object obj = deserializer.Deserialize(node);
					if (obj != null) {
						fieldExpression.SetPropertyValue(componentCreator, obj);
					} else if (IsResource(memberExpression)) {
						fieldExpression.SetPropertyValue(componentCreator, GetResource(node));
					} else {
						ThrowCouldNotFindTypeException(memberExpression);
					}
				}
			} else if (node.Target is IndexExpression) {
				WalkArrayAssignmentRhs(node);
			}
		}
コード例 #27
0
ファイル: ResolveWalker.cs プロジェクト: Rpinski/SharpDevelop
		public override bool Walk(CallExpression node)
		{
			writer.WriteLine("Call");
			return base.Walk(node);
		}
コード例 #28
0
		/// <summary>
		/// Creates a new instance with the specified name.
		/// </summary>
		object CreateInstance(string name, CallExpression node)
		{
			MemberExpression memberExpression = node.Target as MemberExpression;
			if (memberExpression != null) {
				string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);
				Type type = componentCreator.GetType(typeName);
				if (type != null) {
					if (type.IsAssignableFrom(typeof(ComponentResourceManager))) {
						return componentCreator.CreateInstance(type, new object[0], name, false);
					}
					List<object> args = deserializer.GetArguments(node);
					return componentCreator.CreateInstance(type, args, name, false);
				}
			}
			return null;
		}
コード例 #29
0
            private static bool GetPropertyAccessors(CallExpression rhsCall, ref NameExpression ne, ref string get, ref string set)
            {
                bool fCantEmit = false;
                for (int i = 0; i < rhsCall.Args.Count; i++) {
                    // fget, fset, fdel, doc
                    if (rhsCall.Args[i].Name != SymbolTable.Empty) {
                        switch (rhsCall.Args[i].Name.GetString()) {
                            case "fget":
                                ne = rhsCall.Args[i].Expression as NameExpression;
                                if (ne == null) { fCantEmit = true; break; }

                                get = ne.Name.GetString();
                                break;
                            case "fset":
                                ne = rhsCall.Args[i].Expression as NameExpression;
                                if (ne == null) { fCantEmit = true; break; }

                                set = ne.Name.GetString();
                                break;
                            default:
                                fCantEmit = true;
                                break;
                        }
                    } else {
                        switch (i) {
                            case 0:
                                ne = rhsCall.Args[i].Expression as NameExpression;
                                if (ne == null) { fCantEmit = true; break; }

                                get = ne.Name.GetString();
                                break;
                            case 1:
                                ne = rhsCall.Args[i].Expression as NameExpression;
                                if (ne == null) { fCantEmit = true; break; }

                                set = ne.Name.GetString();
                                break;
                            default:
                                fCantEmit = true;
                                break;
                        }
                    }
                }
                return fCantEmit;
            }
コード例 #30
0
		/// <summary>
		/// Walks the right hand side of an assignment when the assignment is an array creation.
		/// </summary>
		void WalkArrayAssignmentRhs(CallExpression callExpression)
		{
			object array = deserializer.Deserialize(callExpression);
			fieldExpression.SetPropertyValue(componentCreator, array);	
		}
コード例 #31
0
		/// <summary>
		/// Deserializes expressions of the form:
		/// 
		/// 1) System.Drawing.Color.FromArgb(0, 192, 0)
		/// 2) System.Array[String](["a", "b"])
		/// </summary>
		object Deserialize(CallExpression callExpression)
		{
			MemberExpression memberExpression = callExpression.Target as MemberExpression;
			IndexExpression indexExpression = callExpression.Target as IndexExpression;
			if (memberExpression != null) {
				return DeserializeMethodCallExpression(callExpression, memberExpression);
			} else if (indexExpression != null) {
				return DeserializeCreateArrayExpression(callExpression, indexExpression);
			}
			return null;
		}
コード例 #32
0
ファイル: PythonNameBinder.cs プロジェクト: TerabyteX/main
 public override bool Walk(CallExpression node)
 {
     node.Parent = _currentScope;
     return base.Walk(node);
 }
コード例 #33
0
		/// <summary>
		/// Deserializes a call expression where the target is an array expression.
		/// 
		/// System.Array[String](["a", "b"])
		/// </summary>
		object DeserializeCreateArrayExpression(CallExpression callExpression, IndexExpression target)
		{
			ListExpression list = callExpression.Args[0].Expression as ListExpression;
			Type arrayType = GetType(target.Index as MemberExpression);
			Array array = Array.CreateInstance(arrayType, list.Items.Count);
			for (int i = 0; i < list.Items.Count; ++i) {
				Expression listItemExpression = list.Items[i];
				ConstantExpression constantExpression = listItemExpression as ConstantExpression;
				MemberExpression memberExpression = listItemExpression as MemberExpression;
				NameExpression nameExpression = listItemExpression as NameExpression;
				CallExpression listItemCallExpression = listItemExpression as CallExpression;
				if (constantExpression != null) {
					array.SetValue(constantExpression.Value, i);
				} else if (memberExpression != null) {
					string name = PythonControlFieldExpression.GetVariableName(memberExpression.Name);
					array.SetValue(componentCreator.GetComponent(name), i);
				} else if (nameExpression != null) {
					array.SetValue(componentCreator.GetInstance(nameExpression.Name), i);
				} else if (listItemCallExpression != null) {
					Type arrayInstanceType = GetType(listItemCallExpression.Target as MemberExpression);
					object instance = componentCreator.CreateInstance(arrayInstanceType, GetArguments(listItemCallExpression), null, false);
					array.SetValue(instance, i);
				}
			}
			return array;
		}
コード例 #34
0
ファイル: Parser.cs プロジェクト: bdoot/IronLanguages
        // 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;
            }
        }
コード例 #35
0
		/// <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;
		}