Changed UploadStringAsync to handle UploadString encapsulated exceptions.
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Internal / ExpressionConstructs.cs
1 //
2 // ExpressionConstructs.cs
3 //
4 // Author:
5 //   Atsushi Enomoto (atsushi@xamarin.com)
6 //
7 // Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Linq;
32
33 namespace Microsoft.Build.Internal.Expressions
34 {
35         
36         class Locatable
37         {
38                 public ILocation Location { get; set; }         
39         }
40         
41         partial class ExpressionList : ILocation, IEnumerable<Expression>
42         {
43                 public ExpressionList ()
44                 {
45                 }
46                 
47                 public ExpressionList (Expression entry)
48                 {
49                         Add (entry);
50                 }
51                 
52                 public int Count {
53                         get { return list.Count; }
54                 }
55                 
56                 //public int Line {
57                 //      get { return list.Count == 0 ? 0 : list [0].Line; }
58                 //}
59                 public int Column {
60                         get { return list.Count == 0 ? 0 : list [0].Column; }
61                 }
62                 public string File {
63                         get { return list.Count == 0 ? null : list [0].File; }
64                 }
65                 public string ToLocationString ()
66                 {
67                         return list.Count == 0 ? null : list [0].Location.ToLocationString ();
68                 }
69                         
70                 public IEnumerator<Expression> GetEnumerator ()
71                 {
72                         return list.GetEnumerator ();
73                 }
74                 
75                 IEnumerator IEnumerable.GetEnumerator ()
76                 {
77                         return list.GetEnumerator ();
78                 }
79                 
80                 List<Expression> list = new List<Expression> ();
81                 
82                 public ExpressionList Add (Expression expr)
83                 {
84                         list.Add (expr);
85                         return this;
86                 }
87                 
88                 public ExpressionList Insert (int pos, Expression expr)
89                 {
90                         list.Insert (pos, expr);
91                         return this;
92                 }
93
94                 public override string ToString ()
95                 {
96                         return string.Join (" ", list.Select (i => i.ToString ()));
97                 }
98         }
99
100         abstract partial class Expression : Locatable, ILocation
101         {
102                 //public int Line {
103                 //      get { return Location.Line; }
104                 //}
105                 public int Column {
106                         get { return Location.Column; }
107                 }
108                 public string File {
109                         get { return Location.File; }
110                 }
111                 public string ToLocationString ()
112                 {
113                         return Location.ToLocationString ();
114                 }
115         }
116         
117         enum Operator
118         {
119                 EQ,
120                 NE,
121                 LT,
122                 LE,
123                 GT,
124                 GE,
125                 And,
126                 Or
127         }
128         
129         partial class BinaryExpression : Expression
130         {
131                 public Operator Operator { get; set; }
132                 public Expression Left { get; set; }
133                 public Expression Right { get; set; }
134
135                 public override string ExpressionString {
136                         get { return string.Format ("{0} {1} {2}", Left, Operator, Right); }
137                 }
138         }
139         
140         partial class BooleanLiteral : Expression
141         {
142                 public bool Value { get; set; }
143
144                 public override string ExpressionString {
145                         get { return Value ? "true" : "false"; }
146                 }
147         }
148
149         partial class NotExpression : Expression
150         {
151                 public Expression Negated { get; set; }
152                 public override string ExpressionString {
153                         get { return string.Format ("!{0}", Negated); }
154                 }
155         }
156
157         partial class PropertyAccessExpression : Expression
158         {
159                 public PropertyAccess Access { get; set; }
160                 public override string ExpressionString {
161                         get { return Access.ExpressionString; }
162                 }
163         }
164         
165         enum PropertyTargetType
166         {
167                 Object,
168                 Type,
169         }
170         
171         class PropertyAccess : Locatable
172         {
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); }
179                 }
180         }
181
182         partial class ItemAccessExpression : Expression
183         {
184                 public ItemApplication Application { get; set; }
185                 public override string ExpressionString {
186                         get { return Application.ExpressionString; }
187                 }
188         }
189         
190         class ItemApplication : Locatable
191         {
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); }
196                 }
197         }
198
199         partial class MetadataAccessExpression : Expression
200         {
201                 public MetadataAccess Access { get; set; }
202                 public override string ExpressionString {
203                         get { return Access.ExpressionString; }
204                 }
205         }
206         
207         class MetadataAccess : Locatable
208         {
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); }
213                 }
214         }
215         
216         partial class StringLiteral : Expression
217         {
218                 public NameToken Value { get; set; }
219
220                 public override string ExpressionString {
221                         get { return '"' + Value.ToString () + '"'; }
222                 }
223         }
224
225         partial class RawStringLiteral : Expression
226         {
227                 public NameToken Value { get; set; }
228
229                 public override string ExpressionString {
230                         get { return "[rawstr] " + Value; }
231                 }
232         }
233         
234         partial class FunctionCallExpression : Expression
235         {
236                 public NameToken Name { get; set; }
237                 public ExpressionList Arguments { get; set; }
238
239                 public override string ExpressionString {
240                         get { return string.Format ("[func] {0}({1})", Name, string.Join (", ", Arguments.Select (e => e.ExpressionString))); }
241                 }
242         }
243 }
244