Exemplo n.º 1
0
        public Node VisitExpression(IronPython.Compiler.Ast.IndexExpression exp)
        {
            var  changed = false;
            Node newCode = exp;

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

            return(new IronPython.Compiler.Ast.IndexExpression(VisitExpression(exp.Target),
                                                               VisitExpression(exp.Index)));
        }
Exemplo n.º 2
0
        public override void PostWalk(IndexExpression node)
        {
            SliceExpression slice = node.Index as SliceExpression;

            if (slice != null)
            {
                List<string> parts = new List<string>();
                parts.Add(slice.SliceStop != null ? Content() : "null");
                if (slice.SliceStep != null)
                {
                    Content();
                }
                parts.Add(slice.SliceStart != null ? Content() : "null");

                string target = Content();

                Content("{0}.slice({1})", target, String.Join(", ", parts));
            }
            else
            {
                string index = Content();
                string target = Content();

                Content("{0}[{1}]", target, index);
            }

            CommonPostWalk(node);
        }
Exemplo n.º 3
0
        public override bool Walk(IndexExpression node)
        {
            CommonWalk(node);

            return true;
        }
 // IndexExpression
 public bool Walk(IndexExpression node)
 {
     return Process(node);
 }
 public void PostWalk(IndexExpression node)
 {
     PostProcess(node);
 }
Exemplo n.º 6
0
 internal Subscript(IndexExpression expr, expr_context ctx)
     : this()
 {
     _value = Convert(expr.Target);
     _ctx = ctx;
     _slice = TrySliceConvert(expr.Index);
     if (_slice == null)
         _slice = new Index(Convert(expr.Index));
 }
		/// <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;
		}
Exemplo n.º 8
0
		public override bool Walk(IndexExpression node)
		{
			writer.WriteLine("Index: " + node.Index.ToString());
			return base.Walk(node);
		}
 public virtual void PostWalk(IndexExpression node)
 {
 }
Exemplo n.º 10
0
 // IndexExpression
 public virtual bool Walk(IndexExpression node)
 {
     return true;
 }
Exemplo n.º 11
0
 public override bool Walk(IndexExpression node)
 {
     node.Walk(_fc);
     return(false);
 }
Exemplo n.º 12
0
 public override bool Walk(IndexExpression node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }
Exemplo n.º 13
0
 // trailer: '(' [ arglist_genexpr ] ')' | '[' subscriptlist ']' | '.' NAME
 private Expression AddTrailers(Expression ret)
 {
     while (true) {
         Token t = PeekToken();
         switch (t.Kind) {
             case TokenKind.LeftParenthesis:
                 NextToken();
                 Arg[] args = FinishArgListOrGenExpr();
                 CallExpression call = FinishCallExpr(ret, args);
                 call.SetLoc(GetExternal(), ret.Start, GetEnd());
                 ret = call;
                 break;
             case TokenKind.LeftBracket:
                 NextToken();
                 Expression index = ParseSubscriptList();
                 IndexExpression ie = new IndexExpression(ret, index);
                 ie.SetLoc(GetExternal(), ret.Start, GetEnd());
                 ret = ie;
                 break;
             case TokenKind.Dot:
                 NextToken();
                 SymbolId name = ReadNameMaybeNone();
                 FieldExpression fe = new FieldExpression(ret, name);
                 fe.SetLoc(GetExternal(), ret.Start, GetEnd());
                 ret = fe;
                 break;
             default:
                 return ret;
         }
     }
 }
Exemplo n.º 14
0
 public string Visit(PyAst.IndexExpression node) => $"{Visit(node.Target)}[{Visit(node.Index)}]";
Exemplo n.º 15
0
            internal Subscript(IndexExpression expr, expr_context ctx)
                : this() {
                _value = Convert(expr.Target);
                AST index = Convert(expr.Index);
                if (index is expr)
                    if (index is Tuple && ((TupleExpression)expr.Index).IsExpandable)
                        _slice = new ExtSlice(((Tuple)index).elts);
                    else
                        _slice = new Index((expr)index);
                else if (index is slice) // includes Ellipsis
                    _slice = (slice)index;
                else
                    throw new ArgumentTypeException("Unexpected index expression: " + expr.Index.GetType());

                _ctx = ctx;
            }
Exemplo n.º 16
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;
            }
        }
Exemplo n.º 17
0
 public override bool Walk(IndexExpression node) {
     node.Walk(_fc);
     return false;
 }