PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/IronPython/Compiler/Ast/Arg.cs

#
C# | 71 lines | 47 code | 10 blank | 14 comment | 12 complexity | 48cddfa1fdbd172b043c5a18779bad15 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16#if !CLR2
17using MSAst = System.Linq.Expressions;
18#else
19using MSAst = Microsoft.Scripting.Ast;
20#endif
21
22using IronPython.Runtime;
23using Microsoft.Scripting;
24using Microsoft.Scripting.Actions;
25
26namespace IronPython.Compiler.Ast {
27    public class Arg : Node {
28        private readonly string _name;
29        private readonly Expression _expression;
30
31        public Arg(Expression expression) : this(null, expression) { }
32
33        public Arg(string name, Expression expression) {
34            _name = name;
35            _expression = expression;
36        }
37
38        public string Name {
39            get { return _name; }
40        }
41
42        public Expression Expression {
43            get { return _expression; }
44        } 
45
46        public override string ToString() {
47            return base.ToString() + ":" + _name;
48        }
49
50        internal Argument GetArgumentInfo() {
51            if (_name == null) {
52                return Argument.Simple;
53            } else if (_name == "*") {
54                return new Argument(ArgumentType.List);
55            } else if (_name == "**") {
56                return new Argument(ArgumentType.Dictionary);
57            } else {
58                return new Argument(_name);
59            }
60        }
61
62        public override void Walk(PythonWalker walker) {
63            if (walker.Walk(this)) {
64                if (_expression != null) {
65                    _expression.Walk(walker);
66                }
67            }
68            walker.PostWalk(this);
69        }
70    }
71}