Skip to content

Commit

Permalink
2009-07-02 Marek Safar <marek.safar@gmail.com>
Browse files Browse the repository at this point in the history
	* Initial import, revision 25679.


svn path=/trunk/mcs/; revision=137277
  • Loading branch information
marek-safar committed Jul 2, 2009
1 parent 6833026 commit 340222f
Show file tree
Hide file tree
Showing 183 changed files with 52,759 additions and 0 deletions.
36 changes: 36 additions & 0 deletions mcs/class/dlr/License.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<html>

<head>
<title>Microsoft Public License (Ms-PL)</title>
</head>

<body>

<p><b>This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.</b></p>

<h2>1. Definitions</h2>
<p>The terms &#8220;reproduce,&#8221; &#8220;reproduction,&#8221; &#8220;derivative works,&#8221; and &#8220;distribution&#8221; have the same meaning here as under U.S. copyright law.</p>
<p>A &#8220;contribution&#8221; is the original software, or any additions or changes to the software.</p>
<p>A &#8220;contributor&#8221; is any person that distributes its contribution under this license.</p>
<p> &#8220;Licensed patents&#8221; are a contributor&#8217;s patent claims that read directly on its contribution.</p>
<h2>2. Grant of Rights</h2>
<p>(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright
license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.</p>

<p>(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide,
royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative
works of the contribution in the software.</p>

<h2>3. Conditions and Limitations</h2><p>(A) No Trademark License- This license does not grant you rights to use any contributors&#8217; name, logo, or trademarks.</p>
<p>(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.</p>
<p>(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.</p>
<p>(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution.
If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.</p>

<p>(E) The software is licensed &#8220;as-is.&#8221; You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional
consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability,
fitness for a particular purpose and non-infringement.</p>

</body>

</html>
177 changes: 177 additions & 0 deletions mcs/class/dlr/License.rtf

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions mcs/class/dlr/Runtime/Microsoft.Dynamic/ArgBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/
using System; using Microsoft;


#if !SILVERLIGHT

#if CODEPLEX_40
using System.Linq.Expressions;
#else
using Microsoft.Linq.Expressions;
#endif

#if CODEPLEX_40
namespace System.Dynamic {
#else
namespace Microsoft.Scripting {
#endif
/// <summary>
/// ArgBuilder provides an argument value used by the MethodBinder. One ArgBuilder exists for each
/// physical parameter defined on a method.
///
/// Contrast this with ParameterWrapper which represents the logical argument passed to the method.
/// </summary>
internal abstract class ArgBuilder {
/// <summary>
/// Provides the Expression which provides the value to be passed to the argument.
/// </summary>
internal abstract Expression Marshal(Expression parameter);

/// <summary>
/// Provides the Expression which provides the value to be passed to the argument.
/// This method is called when result is intended to be used ByRef.
/// </summary>
internal virtual Expression MarshalToRef(Expression parameter) {
return Marshal(parameter);
}

/// <summary>
/// Provides an Expression which will update the provided value after a call to the method.
/// May return null if no update is required.
/// </summary>
internal virtual Expression UnmarshalFromRef(Expression newValue) {
return newValue;
}
}
}

#endif
82 changes: 82 additions & 0 deletions mcs/class/dlr/Runtime/Microsoft.Dynamic/Assert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/

#define DEBUG
using System; using Microsoft;


using System.Collections.Generic;
using System.Diagnostics;

#if CODEPLEX_40
namespace System.Dynamic {
#else
namespace Microsoft.Scripting {
#endif
internal static class Assert {

internal static Exception Unreachable {
get {
Debug.Assert(false, "Unreachable");
return new InvalidOperationException("Code supposed to be unreachable");
}
}

[Conditional("DEBUG")]
internal static void NotNull(object var) {
Debug.Assert(var != null);
}

[Conditional("DEBUG")]
internal static void NotNull(object var1, object var2) {
Debug.Assert(var1 != null && var2 != null);
}

[Conditional("DEBUG")]
internal static void NotNull(object var1, object var2, object var3) {
Debug.Assert(var1 != null && var2 != null && var3 != null);
}

[Conditional("DEBUG")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
internal static void NotNull(object var1, object var2, object var3, object var4) {
Debug.Assert(var1 != null && var2 != null && var3 != null && var4 != null);
}

[Conditional("DEBUG")]
internal static void NotEmpty(string str) {
Debug.Assert(!String.IsNullOrEmpty(str));
}

[Conditional("DEBUG")]
internal static void NotEmpty<T>(ICollection<T> array) {
Debug.Assert(array != null && array.Count > 0);
}

[Conditional("DEBUG")]
internal static void NotNullItems<T>(IEnumerable<T> items) where T : class {
Debug.Assert(items != null);
foreach (object item in items) {
Debug.Assert(item != null);
}
}

[Conditional("DEBUG")]
internal static void IsTrue(Func<bool> predicate) {
ContractUtils.RequiresNotNull(predicate, "predicate");
Debug.Assert(predicate());
}
}
}
72 changes: 72 additions & 0 deletions mcs/class/dlr/Runtime/Microsoft.Dynamic/BoolArgBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/
using System; using Microsoft;


#if !SILVERLIGHT // ComObject

using System.Collections.Generic;

using System.Diagnostics;
#if CODEPLEX_40
using System.Linq.Expressions;
#else
using Microsoft.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
#if !CODEPLEX_40
using Microsoft.Runtime.CompilerServices;
#endif

using System.Runtime.InteropServices;
#if CODEPLEX_40
using System.Dynamic.Utils;
#else
using Microsoft.Scripting.Utils;
#endif

#if CODEPLEX_40
namespace System.Dynamic {
#else
namespace Microsoft.Scripting {
#endif
internal sealed class BoolArgBuilder : SimpleArgBuilder {
internal BoolArgBuilder(Type parameterType)
: base(parameterType) {
Debug.Assert(parameterType == typeof(bool));
}

internal override Expression MarshalToRef(Expression parameter) {
// parameter ? -1 : 0
return Expression.Condition(
Marshal(parameter),
Expression.Constant((Int16)(-1)),
Expression.Constant((Int16)0)
);
}

internal override Expression UnmarshalFromRef(Expression value) {
//parameter = temp != 0
return base.UnmarshalFromRef(
Expression.NotEqual(
value,
Expression.Constant((Int16)0)
)
);
}
}
}

#endif
138 changes: 138 additions & 0 deletions mcs/class/dlr/Runtime/Microsoft.Dynamic/BoundDispEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Microsoft Public License. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Microsoft Public License, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/
using System; using Microsoft;


#if !SILVERLIGHT // ComObject

#if CODEPLEX_40
using System.Linq.Expressions;
#else
using Microsoft.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
#if !CODEPLEX_40
using Microsoft.Runtime.CompilerServices;
#endif

using System.Security;
using System.Security.Permissions;

#if CODEPLEX_40
namespace System.Dynamic {
#else
namespace Microsoft.Scripting {
#endif
internal sealed class BoundDispEvent : DynamicObject {
private object _rcw;
private Guid _sourceIid;
private int _dispid;

internal BoundDispEvent(object rcw, Guid sourceIid, int dispid) {
_rcw = rcw;
_sourceIid = sourceIid;
_dispid = dispid;
}

/// <summary>
/// Provides the implementation of performing AddAssign and SubtractAssign binary operations.
/// </summary>
/// <param name="binder">The binder provided by the call site.</param>
/// <param name="handler">The handler for the operation.</param>
/// <param name="result">The result of the operation.</param>
/// <returns>true if the operation is complete, false if the call site should determine behavior.</returns>
public override bool TryBinaryOperation(BinaryOperationBinder binder, object handler, out object result) {
if (binder.Operation == ExpressionType.AddAssign) {
result = InPlaceAdd(handler);
return true;
}

if (binder.Operation == ExpressionType.SubtractAssign) {
result = InPlaceSubtract(handler);
return true;
}

result = null;
return false;
}

private static void VerifyHandler(object handler) {
if (handler is Delegate && handler.GetType() != typeof(Delegate)) {
return; // delegate
}

if (handler is IDynamicMetaObjectProvider) {
return; // IDMOP
}

throw Error.UnsupportedHandlerType();
}

/// <summary>
/// Adds a handler to an event.
/// </summary>
/// <param name="handler">The handler to be added.</param>
/// <returns>The original event with handler added.</returns>
#if MICROSOFT_DYNAMIC
[SecurityCritical, SecurityTreatAsSafe]
#else
[SecuritySafeCritical]
#endif
private object InPlaceAdd(object handler) {
ContractUtils.RequiresNotNull(handler, "handler");
VerifyHandler(handler);

//
// Demand Full Trust to proceed with the operation.
//

new PermissionSet(PermissionState.Unrestricted).Demand();

ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, true);
comEventSink.AddHandler(_dispid, handler);
return this;
}

/// <summary>
/// Removes handler from the event.
/// </summary>
/// <param name="handler">The handler to be removed.</param>
/// <returns>The original event with handler removed.</returns>
#if MICROSOFT_DYNAMIC
[SecurityCritical, SecurityTreatAsSafe]
#else
[SecuritySafeCritical]
#endif
private object InPlaceSubtract(object handler) {
ContractUtils.RequiresNotNull(handler, "handler");
VerifyHandler(handler);

//
// Demand Full Trust to proceed with the operation.
//

new PermissionSet(PermissionState.Unrestricted).Demand();

ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, false);
if (comEventSink != null) {
comEventSink.RemoveHandler(_dispid, handler);
}

return this;
}
}
}

#endif
Loading

0 comments on commit 340222f

Please sign in to comment.