[sgen] Reenable gc-altstack test
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Ast / LabelTarget.cs
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 using System;
17 using System.Dynamic.Utils;
18
19 #if !FEATURE_CORE_DLR
20 namespace Microsoft.Scripting.Ast {
21 #else
22 namespace System.Linq.Expressions {
23 #endif
24
25     /// <summary>
26     /// Used to denote the target of a <see cref="GotoExpression"/>.
27     /// </summary>
28     public sealed class LabelTarget {
29         private readonly Type _type;
30         private readonly string _name;
31
32         internal LabelTarget(Type type, string name) {
33             _type = type;
34             _name = name;
35         }
36
37         /// <summary>
38         /// Gets the name of the label.
39         /// </summary>
40         /// <remarks>The label's name is provided for information purposes only.</remarks>
41         public string Name {
42             get { return _name; }
43         }
44
45         /// <summary>
46         /// The type of value that is passed when jumping to the label
47         /// (or System.Void if no value should be passed).
48         /// </summary>
49         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
50         public Type Type {
51             get { return _type; }
52         }
53
54         /// <summary>
55         /// Returns a <see cref="String"/> that represents the current <see cref="Object"/>. 
56         /// </summary>
57         /// <returns>A <see cref="String"/> that represents the current <see cref="Object"/>. </returns>
58         public override string ToString() {
59             return String.IsNullOrEmpty(this.Name) ? "UnamedLabel" : this.Name;
60         }
61     }
62
63     public partial class Expression {
64         /// <summary>
65         /// Creates a <see cref="LabelTarget"/> representing a label with void type and no name.
66         /// </summary>
67         /// <returns>The new <see cref="LabelTarget"/>.</returns>
68         public static LabelTarget Label() {
69             return Label(typeof(void), null);
70         }
71
72         /// <summary>
73         /// Creates a <see cref="LabelTarget"/> representing a label with void type and the given name.
74         /// </summary>
75         /// <param name="name">The name of the label.</param>
76         /// <returns>The new <see cref="LabelTarget"/>.</returns>
77         public static LabelTarget Label(string name) {
78             return Label(typeof(void), name);
79         }
80
81         /// <summary>
82         /// Creates a <see cref="LabelTarget"/> representing a label with the given type.
83         /// </summary>
84         /// <param name="type">The type of value that is passed when jumping to the label.</param>
85         /// <returns>The new <see cref="LabelTarget"/>.</returns>
86         public static LabelTarget Label(Type type) {
87             return Label(type, null);
88         }
89
90         /// <summary>
91         /// Creates a <see cref="LabelTarget"/> representing a label with the given type and name.
92         /// </summary>
93         /// <param name="type">The type of value that is passed when jumping to the label.</param>
94         /// <param name="name">The name of the label.</param>
95         /// <returns>The new <see cref="LabelTarget"/>.</returns>
96         public static LabelTarget Label(Type type, string name) {
97             ContractUtils.RequiresNotNull(type, "type");
98             TypeUtils.ValidateType(type);
99             return new LabelTarget(type, name);
100         }
101     }
102 }