2 // ExpressionConstructs.cs
5 // Atsushi Enomoto (atsushi@xamarin.com)
7 // Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections;
30 using System.Collections.Generic;
33 namespace Microsoft.Build.Internal.Expressions
38 public ILocation Location { get; set; }
41 partial class ExpressionList : ILocation, IEnumerable<Expression>
43 public ExpressionList ()
47 public ExpressionList (Expression entry)
53 get { return list.Count; }
57 // get { return list.Count == 0 ? 0 : list [0].Line; }
60 get { return list.Count == 0 ? 0 : list [0].Column; }
63 get { return list.Count == 0 ? null : list [0].File; }
65 public string ToLocationString ()
67 return list.Count == 0 ? null : list [0].Location.ToLocationString ();
70 public IEnumerator<Expression> GetEnumerator ()
72 return list.GetEnumerator ();
75 IEnumerator IEnumerable.GetEnumerator ()
77 return list.GetEnumerator ();
80 List<Expression> list = new List<Expression> ();
82 public ExpressionList Add (Expression expr)
88 public ExpressionList Insert (int pos, Expression expr)
90 list.Insert (pos, expr);
94 public override string ToString ()
96 return string.Join (" ", list.Select (i => i.ToString ()));
100 abstract partial class Expression : Locatable, ILocation
103 // get { return Location.Line; }
106 get { return Location.Column; }
109 get { return Location.File; }
111 public string ToLocationString ()
113 return Location.ToLocationString ();
129 partial class BinaryExpression : Expression
131 public Operator Operator { get; set; }
132 public Expression Left { get; set; }
133 public Expression Right { get; set; }
135 public override string ExpressionString {
136 get { return string.Format ("{0} {1} {2}", Left, Operator, Right); }
140 partial class BooleanLiteral : Expression
142 public bool Value { get; set; }
144 public override string ExpressionString {
145 get { return Value ? "true" : "false"; }
149 partial class NotExpression : Expression
151 public Expression Negated { get; set; }
152 public override string ExpressionString {
153 get { return string.Format ("!{0}", Negated); }
157 partial class PropertyAccessExpression : Expression
159 public PropertyAccess Access { get; set; }
160 public override string ExpressionString {
161 get { return Access.ExpressionString; }
165 enum PropertyTargetType
171 class PropertyAccess : Locatable
173 public NameToken Name { get; set; }
174 public Expression Target { get; set; }
175 public PropertyTargetType TargetType { get; set; }
176 public ExpressionList Arguments { get; set; }
177 public string ExpressionString {
178 get { return string.Format ("$([{0}][{1}][{2}][{3}])", Target, TargetType, Name, Arguments != null && Arguments.Any () ? string.Join (", ", Arguments.Select (e => e.ExpressionString)) : null); }
182 partial class ItemAccessExpression : Expression
184 public ItemApplication Application { get; set; }
185 public override string ExpressionString {
186 get { return Application.ExpressionString; }
190 class ItemApplication : Locatable
192 public NameToken Name { get; set; }
193 public ExpressionList Expressions { get; set; }
194 public string ExpressionString {
195 get { return string.Format ("@([{0}][{1}])", Name, Expressions != null && Expressions.Any () ? string.Join (" ||| ", Expressions.Select (e => e.ExpressionString)) : null); }
199 partial class MetadataAccessExpression : Expression
201 public MetadataAccess Access { get; set; }
202 public override string ExpressionString {
203 get { return Access.ExpressionString; }
207 class MetadataAccess : Locatable
209 public NameToken Metadata { get; set; }
210 public NameToken ItemType { get; set; }
211 public string ExpressionString {
212 get { return string.Format ("%([{0}].[{1}])", ItemType, Metadata); }
216 partial class StringLiteral : Expression
218 public NameToken Value { get; set; }
220 public override string ExpressionString {
221 get { return '"' + Value.ToString () + '"'; }
225 partial class RawStringLiteral : Expression
227 public NameToken Value { get; set; }
229 public override string ExpressionString {
230 get { return "[rawstr] " + Value; }
234 partial class FunctionCallExpression : Expression
236 public NameToken Name { get; set; }
237 public ExpressionList Arguments { get; set; }
239 public override string ExpressionString {
240 get { return string.Format ("[func] {0}({1})", Name, string.Join (", ", Arguments.Select (e => e.ExpressionString))); }