This commit is contained in:
Jelle Luteijn 2022-05-15 11:19:49 +02:00
parent 16e76d6b31
commit 484dbfc9d9
529 changed files with 113694 additions and 0 deletions

View file

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AspClassic.Parser\AspClassic.Parser.csproj" />
<ProjectReference Include="..\AspClassic.Scripting\AspClassic.Scripting.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using Debug = System.Diagnostics.Debug;
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Binders
{
public class VBScriptBinaryOperationBinder : BinaryOperationBinder
{
public VBScriptBinaryOperationBinder(ExpressionType operation)
: base(operation)
{
}
public override DynamicMetaObject FallbackBinaryOperation(
DynamicMetaObject target, DynamicMetaObject arg,
DynamicMetaObject errorSuggestion)
{
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!target.HasValue || !arg.HasValue)
{
return Defer(target, arg);
}
var restrictions = target.Restrictions.Merge(arg.Restrictions);
if (target.Value == null)
{
restrictions = restrictions.Merge(
BindingRestrictions.GetInstanceRestriction(target.Expression, null)
);
}
else
{
restrictions = restrictions.Merge(BindingRestrictions.GetTypeRestriction(
target.Expression, target.LimitType));
}
if (arg.Value == null)
{
restrictions = restrictions.Merge(BindingRestrictions.GetInstanceRestriction(
arg.Expression, null));
}
else
{
restrictions = restrictions.Merge(BindingRestrictions.GetTypeRestriction(
arg.Expression, arg.LimitType));
}
if (this.Operation == ExpressionType.Add)
{
if (target.LimitType == typeof(string) && arg.LimitType == typeof(string))
{
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(Expression.Call(
typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }),
Expression.Convert(target.Expression, target.LimitType),
Expression.Convert(arg.Expression, arg.LimitType))),
restrictions
);
}
if (target.LimitType == typeof(DateTime))
{
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult( Expression.Call(
typeof(BuiltInFunctions).GetMethod("DateAdd"),
Expression.Constant("d"),
Expression.Convert(arg.Expression, typeof(object)),
target.Expression)),
restrictions
);
}
else if (arg.LimitType == typeof(DateTime))
{
return new DynamicMetaObject(
Expression.Call(
typeof(BuiltInFunctions).GetMethod("DateAdd"),
Expression.Constant("d"),
Expression.Convert(target.Expression, typeof(object)),
arg.Expression),
restrictions
);
}
else if (!target.LimitType.IsPrimitive || !arg.LimitType.IsPrimitive)
{
DynamicMetaObject[] args = new DynamicMetaObject[] { target, arg };
List<MethodInfo> res = RuntimeHelpers.GetExtensionMethods("op_Addition", target, args);
if (res.Count > 0)
{
MethodInfo mi = null;
if (res.Count > 1)
{
//If more than one results found, attempt overload resolution
mi = RuntimeHelpers.ResolveOverload(res, args);
}
else
{
mi = res[0];
}
// restrictions and conversion must be done consistently.
var callArgs = RuntimeHelpers.ConvertArguments(args, mi.GetParameters());
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(null, mi, callArgs)
),
restrictions
);
}
}
}
if (target.LimitType.IsPrimitive && arg.LimitType.IsPrimitive)
{
Type targetType;
Expression first;
Expression second;
if (target.LimitType == arg.LimitType || target.LimitType.IsAssignableFrom(arg.LimitType))
{
targetType = target.LimitType;
first = Expression.Convert(target.Expression, targetType);
//if variable is object type, need to convert twice (unbox + convert)
second = Expression.Convert(
Expression.Convert(arg.Expression, arg.LimitType),
targetType
);
}
else
{
targetType = arg.LimitType;
first = Expression.Convert(
Expression.Convert(target.Expression, target.LimitType),
targetType
);
second = Expression.Convert(arg.Expression, targetType);
}
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.MakeBinary(
this.Operation,
first,
second
)
),
restrictions
);
}
else
{
DynamicMetaObject[] args = null;
MethodInfo mi = null;
mi = typeof(HelperFunctions).GetMethod("BinaryOp");
Expression op = Expression.Constant(this.Operation);
DynamicMetaObject mop = new DynamicMetaObject(Expression.Constant(this.Operation), BindingRestrictions.Empty, this.Operation);
args = new DynamicMetaObject[] { mop, target, arg };
// restrictions and conversion must be done consistently.
var callArgs = RuntimeHelpers.ConvertArguments(args, mi.GetParameters());
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(
mi,
callArgs
)
),
restrictions
);
}
}
}
}

View file

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq;
using System.Linq.Expressions;
#endif
using Dlrsoft.VBScript.Runtime;
using Debug = System.Diagnostics.Debug;
namespace Dlrsoft.VBScript.Binders
{
public class VBScriptCreateInstanceBinder : CreateInstanceBinder
{
public VBScriptCreateInstanceBinder(CallInfo callinfo)
: base(callinfo)
{
}
public override DynamicMetaObject FallbackCreateInstance(
DynamicMetaObject target,
DynamicMetaObject[] args,
DynamicMetaObject errorSuggestion)
{
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!target.HasValue || args.Any((a) => !a.HasValue))
{
var deferArgs = new DynamicMetaObject[args.Length + 1];
for (int i = 0; i < args.Length; i++)
{
deferArgs[i + 1] = args[i];
}
deferArgs[0] = target;
return Defer(deferArgs);
}
// Make sure target actually contains a Type.
if (!typeof(Type).IsAssignableFrom(target.LimitType))
{
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
target, args, BindingRestrictions.Empty,
typeof(InvalidOperationException),
"Type object must be used when creating instance -- " +
args.ToString());
}
var type = target.Value as Type;
Debug.Assert(type != null);
var constructors = type.GetConstructors();
// Get constructors with right arg counts.
var ctors = constructors.
Where(c => c.GetParameters().Length == args.Length);
List<ConstructorInfo> res = new List<ConstructorInfo>();
foreach (var c in ctors)
{
if (RuntimeHelpers.ParametersMatchArguments(c.GetParameters(),
args))
{
res.Add(c);
}
}
// We generate an instance restriction on the target since it is a
// Type and the constructor is associate with the actual Type instance.
var restrictions =
RuntimeHelpers.GetTargetArgsRestrictions(
target, args, true);
if (res.Count == 0)
{
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
target, args, restrictions,
typeof(MissingMemberException),
"Can't bind create instance -- " + args.ToString());
}
var ctorArgs =
RuntimeHelpers.ConvertArguments(
args, res[0].GetParameters());
return new DynamicMetaObject(
// Creating an object, so don't need EnsureObjectResult.
Expression.New(res[0], ctorArgs),
restrictions);
}
}
}

View file

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.ComInterop;
#else
using System.Linq;
using System.Linq.Expressions;
using AspClassic.Scripting.ComInterop;
#endif
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Binders
{
public class VBScriptGetIndexBinder : GetIndexBinder
{
public VBScriptGetIndexBinder(CallInfo callinfo)
: base(callinfo)
{
}
public override DynamicMetaObject FallbackGetIndex(
DynamicMetaObject target, DynamicMetaObject[] indexes,
DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
// First try COM binding.
DynamicMetaObject result;
if (ComBinder.TryBindGetIndex(this, target, indexes, out result))
{
return result;
}
#endif
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!target.HasValue || indexes.Any((a) => !a.HasValue))
{
var deferArgs = new DynamicMetaObject[indexes.Length + 1];
for (int i = 0; i < indexes.Length; i++)
{
deferArgs[i + 1] = indexes[i];
}
deferArgs[0] = target;
return Defer(deferArgs);
}
var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(
target, indexes, false);
if (target.HasValue && target.Value == null)
{
return errorSuggestion?? RuntimeHelpers.CreateThrow(target,
indexes,
restrictions,
typeof(NullReferenceException),
"Object reference not set to an instance of an object.");
}
var indexingExpr = RuntimeHelpers.EnsureObjectResult(
RuntimeHelpers.GetIndexingExpression(target,
indexes));
return new DynamicMetaObject(indexingExpr, restrictions);
}
}
}

View file

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.ComInterop;
#else
using System.Linq.Expressions;
using AspClassic.Scripting.ComInterop;
#endif
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Binders
{
// VBScriptGetMemberBinder is used for general dotted expressions for fetching
// members.
//
public class VBScriptGetMemberBinder : GetMemberBinder
{
public VBScriptGetMemberBinder(string name)
: base(name, true)
{
}
public override DynamicMetaObject FallbackGetMember(
DynamicMetaObject targetMO, DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
// First try COM binding.
DynamicMetaObject result;
if (ComBinder.TryBindGetMember(this, targetMO, out result))
{
return result;
}
#endif
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!targetMO.HasValue) return Defer(targetMO);
// Find our own binding.
var flags = BindingFlags.IgnoreCase | BindingFlags.Static |
BindingFlags.Instance | BindingFlags.Public;
var members = targetMO.LimitType.GetMember(this.Name, flags);
if (members.Length == 1)
{
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.MakeMemberAccess(
Expression.Convert(targetMO.Expression,
members[0].DeclaringType),
members[0])),
// Don't need restriction test for name since this
// rule is only used where binder is used, which is
// only used in sites with this binder.Name.
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType));
}
else
{
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
targetMO, null,
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType),
typeof(MissingMemberException),
"cannot bind member, " + this.Name +
", on object " + targetMO.Value.ToString());
}
}
}
}

View file

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#if !SILVERLIGHT
using AspClassic.Scripting.ComInterop;
#endif
#else
using System.Linq;
using System.Linq.Expressions;
using AspClassic.Scripting.ComInterop;
#endif
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Binders
{
public class VBScriptInvokeBinder : InvokeBinder
{
public VBScriptInvokeBinder(CallInfo callinfo)
: base(callinfo)
{
}
public override DynamicMetaObject FallbackInvoke(
DynamicMetaObject targetMO, DynamicMetaObject[] argMOs,
DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
// First try COM binding.
DynamicMetaObject result;
if (ComBinder.TryBindInvoke(this, targetMO, argMOs, out result))
{
return result;
}
#endif
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!targetMO.HasValue || argMOs.Any((a) => !a.HasValue))
{
var deferArgs = new DynamicMetaObject[argMOs.Length + 1];
for (int i = 0; i < argMOs.Length; i++)
{
deferArgs[i + 1] = argMOs[i];
}
deferArgs[0] = targetMO;
return Defer(deferArgs);
}
// Find our own binding.
if (targetMO.LimitType.IsSubclassOf(typeof(Delegate)))
{
var parms = targetMO.LimitType.GetMethod("Invoke").GetParameters();
if (parms.Length == argMOs.Length)
{
// Don't need to check if argument types match parameters.
// If they don't, users get an argument conversion error.
var callArgs = RuntimeHelpers.ConvertArguments(argMOs, parms);
var expression = Expression.Invoke(
Expression.Convert(targetMO.Expression, targetMO.LimitType),
callArgs);
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(expression),
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType));
}
}
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
targetMO, argMOs,
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType),
typeof(InvalidOperationException),
"Wrong number of arguments for function -- " +
targetMO.LimitType.ToString() + " got " + argMOs.ToString());
}
}
}

View file

@ -0,0 +1,215 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.ComInterop;
#else
using System.Linq;
using System.Linq.Expressions;
using AspClassic.Scripting.ComInterop;
#endif
using Dlrsoft.VBScript.Runtime;
using Debug = System.Diagnostics.Debug;
namespace Dlrsoft.VBScript.Binders
{
// VBScriptInvokeMemberBinder is used for general dotted expressions in function
// calls for invoking members.
//
public class VBScriptInvokeMemberBinder : InvokeMemberBinder
{
public VBScriptInvokeMemberBinder(string name, CallInfo callinfo)
: base(name, true, callinfo)
{ // true = ignoreCase
}
public override DynamicMetaObject FallbackInvokeMember(
DynamicMetaObject targetMO, DynamicMetaObject[] args,
DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
// First try COM binding.
DynamicMetaObject result;
if (ComBinder.TryBindInvokeMember(this, targetMO, args, out result))
{
return result;
}
#endif
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!targetMO.HasValue || args.Any((a) => !a.HasValue))
{
var deferArgs = new DynamicMetaObject[args.Length + 1];
for (int i = 0; i < args.Length; i++)
{
deferArgs[i + 1] = args[i];
}
deferArgs[0] = targetMO;
return Defer(deferArgs);
}
// Find our own binding.
// Could consider allowing invoking static members from an instance.
var flags = BindingFlags.IgnoreCase | BindingFlags.Instance |
BindingFlags.Public;
var members = targetMO.LimitType.GetMember(this.Name, flags);
var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(
targetMO, args, false);
// Assigned a Null
if (targetMO.HasValue && targetMO.Value == null)
{
return RuntimeHelpers.CreateThrow(targetMO,
args,
restrictions,
typeof(NullReferenceException),
"Object reference not set to an instance of an object.");
}
if ((members.Length == 1) && (members[0] is PropertyInfo ||
members[0] is FieldInfo))
{
// NEED TO TEST, should check for delegate value too
var mem = members[0];
var target = new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.MakeMemberAccess(
Expression.Convert(targetMO.Expression,
members[0].DeclaringType),
members[0])),
// Don't need restriction test for name since this
// rule is only used where binder is used, which is
// only used in sites with this binder.Name.
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType));
//If no arguments, to allow scenario like Request.QueryString()
if (args == null || args.Length == 0)
{
return target;
}
return new DynamicMetaObject(
RuntimeHelpers.GetIndexingExpression(target, args),
restrictions
);
// Don't test for eventinfos since we do nothing with them now.
}
else
{
bool isExtension = false;
// Get MethodInfos with right arg counts.
var mi_mems = members.
Select(m => m as MethodInfo).
Where(m => m is MethodInfo &&
((MethodInfo)m).GetParameters().Length ==
args.Length);
// Get MethodInfos with param types that work for args. This works
// except for value args that need to pass to reftype params.
// We could detect that to be smarter and then explicitly StrongBox
// the args.
List<MethodInfo> res = new List<MethodInfo>();
foreach (var mem in mi_mems)
{
if (RuntimeHelpers.ParametersMatchArguments(
mem.GetParameters(), args))
{
res.Add(mem);
}
}
List<DynamicMetaObject> argList = new List<DynamicMetaObject>(args);
//Try extension methods if no methods found
if (res.Count == 0)
{
isExtension = true;
argList.Insert(0, targetMO);
res = RuntimeHelpers.GetExtensionMethods(this.Name, targetMO, argList.ToArray());
}
// False below means generate a type restriction on the MO.
// We are looking at the members targetMO's Type.
if (res.Count == 0)
{
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
targetMO, args, restrictions,
typeof(MissingMemberException),
string.Format("Can't bind member invoke {0}.{1}({2})", targetMO.RuntimeType.Name, this.Name, args.ToString()));
}
//If more than one results found, attempt overload resolution
MethodInfo mi = null;
if (res.Count > 1)
{
mi = RuntimeHelpers.ResolveOverload(res, argList.ToArray());
}
else
{
mi = res[0];
}
// restrictions and conversion must be done consistently.
var callArgs = RuntimeHelpers.ConvertArguments(
argList.ToArray(), mi.GetParameters());
if (isExtension)
{
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(
null,
mi, callArgs)),
restrictions);
}
else
{
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(
Expression.Convert(targetMO.Expression,
targetMO.LimitType),
mi, callArgs)),
restrictions);
}
// Could hve tried just letting Expr.Call factory do the work,
// but if there is more than one applicable method using just
// assignablefrom, Expr.Call throws. It does not pick a "most
// applicable" method or any method.
}
}
public override DynamicMetaObject FallbackInvoke(
DynamicMetaObject targetMO, DynamicMetaObject[] args,
DynamicMetaObject errorSuggestion)
{
var argexprs = new Expression[args.Length + 1];
for (int i = 0; i < args.Length; i++)
{
argexprs[i + 1] = args[i].Expression;
}
argexprs[0] = targetMO.Expression;
// Just "defer" since we have code in SymplInvokeBinder that knows
// what to do, and typically this fallback is from a language like
// Python that passes a DynamicMetaObject with HasValue == false.
return new DynamicMetaObject(
Expression.Dynamic(
// This call site doesn't share any L2 caching
// since we don't call GetInvokeBinder from Sympl.
// We aren't plumbed to get the runtime instance here.
new VBScriptInvokeBinder(new CallInfo(args.Length)),
typeof(object), // ret type
argexprs),
// No new restrictions since SymplInvokeBinder will handle it.
targetMO.Restrictions.Merge(
BindingRestrictions.Combine(args)));
}
}
}

View file

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.ComInterop;
#else
using System.Linq;
using System.Linq.Expressions;
using AspClassic.Scripting.ComInterop;
#endif
using Debug = System.Diagnostics.Debug;
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Binders
{
public class VBScriptSetIndexBinder : SetIndexBinder
{
public VBScriptSetIndexBinder(CallInfo callinfo)
: base(callinfo)
{
}
public override DynamicMetaObject FallbackSetIndex(
DynamicMetaObject target, DynamicMetaObject[] indexes,
DynamicMetaObject value, DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
// First try COM binding.
DynamicMetaObject result;
if (ComBinder.TryBindSetIndex(this, target, indexes, value, out result))
{
return result;
}
# endif
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!target.HasValue || indexes.Any((a) => !a.HasValue) ||
!value.HasValue)
{
var deferArgs = new DynamicMetaObject[indexes.Length + 2];
for (int i = 0; i < indexes.Length; i++)
{
deferArgs[i + 1] = indexes[i];
}
deferArgs[0] = target;
deferArgs[indexes.Length + 1] = value;
return Defer(deferArgs);
}
// Find our own binding.
Expression valueExpr = value.Expression;
//we convert a value of TypeModel to Type.
if (value.LimitType == typeof(TypeModel))
{
valueExpr = RuntimeHelpers.GetRuntimeTypeMoFromModel(value).Expression;
}
Debug.Assert(target.HasValue && target.LimitType != typeof(Array));
Expression setIndexExpr;
Expression indexingExpr = RuntimeHelpers.GetIndexingExpression(
target, indexes);
if (valueExpr.Type != indexingExpr.Type && !indexingExpr.Type.IsAssignableFrom(valueExpr.Type))
{
valueExpr = RuntimeHelpers.ConvertExpression(valueExpr, indexingExpr.Type);
}
setIndexExpr = Expression.Assign(indexingExpr, valueExpr);
//TODO review the restriction because the value may be important for proper conversion
//Also need to handle the null value
BindingRestrictions restrictions =
RuntimeHelpers.GetTargetArgsRestrictions(target, indexes, false);
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(setIndexExpr),
restrictions);
}
}
}

View file

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.ComInterop;
#else
using System.Linq.Expressions;
using AspClassic.Scripting.ComInterop;
#endif
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Binders
{
// VBScriptSetMemberBinder is used for general dotted expressions for setting
// members.
//
public class VBScriptSetMemberBinder : SetMemberBinder
{
public VBScriptSetMemberBinder(string name)
: base(name, true)
{
}
public override DynamicMetaObject FallbackSetMember(
DynamicMetaObject targetMO, DynamicMetaObject value,
DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
// First try COM binding.
DynamicMetaObject result;
if (ComBinder.TryBindSetMember(this, targetMO, value, out result))
{
return result;
}
#endif
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!targetMO.HasValue) return Defer(targetMO);
// Find our own binding.
var flags = BindingFlags.IgnoreCase | BindingFlags.Static |
BindingFlags.Instance | BindingFlags.Public;
var members = targetMO.LimitType.GetMember(this.Name, flags);
if (members.Length == 1)
{
MemberInfo mem = members[0];
Expression val;
// Should check for member domain type being Type and value being
// TypeModel, similar to ConvertArguments, and building an
// expression like GetRuntimeTypeMoFromModel.
if (mem.MemberType == MemberTypes.Property)
val = Expression.Convert(value.Expression,
((PropertyInfo)mem).PropertyType);
else if (mem.MemberType == MemberTypes.Field)
val = Expression.Convert(value.Expression,
((FieldInfo)mem).FieldType);
else
return (errorSuggestion ??
RuntimeHelpers.CreateThrow(
targetMO, null,
BindingRestrictions.GetTypeRestriction(
targetMO.Expression,
targetMO.LimitType),
typeof(InvalidOperationException),
"Sympl only supports setting Properties and " +
"fields at this time."));
return new DynamicMetaObject(
// Assign returns the stored value, so we're good for Sympl.
RuntimeHelpers.EnsureObjectResult(
Expression.Assign(
Expression.MakeMemberAccess(
Expression.Convert(targetMO.Expression,
members[0].DeclaringType),
members[0]),
val)),
// Don't need restriction test for name since this
// rule is only used where binder is used, which is
// only used in sites with this binder.Name.
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType));
}
else
{
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
targetMO, null,
BindingRestrictions.GetTypeRestriction(targetMO.Expression,
targetMO.LimitType),
typeof(MissingMemberException),
"IDynObj member name conflict.");
}
}
}
}

View file

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using Dlrsoft.VBScript.Runtime;
using Debug = System.Diagnostics.Debug;
namespace Dlrsoft.VBScript.Binders
{
public class VBScriptUnaryOperationBinder : UnaryOperationBinder
{
public VBScriptUnaryOperationBinder(ExpressionType operation)
: base(operation)
{
}
public override DynamicMetaObject FallbackUnaryOperation(
DynamicMetaObject target, DynamicMetaObject errorSuggestion)
{
// Defer if any object has no value so that we evaulate their
// Expressions and nest a CallSite for the InvokeMember.
if (!target.HasValue)
{
return Defer(target);
}
var restrictions = target.Restrictions;
if (target.Value == null)
{
restrictions = restrictions.Merge(
BindingRestrictions.GetInstanceRestriction(target.Expression, null)
);
}
else
{
restrictions = restrictions.Merge(
BindingRestrictions.GetTypeRestriction(
target.Expression, target.LimitType));
}
if (this.Operation == ExpressionType.Not)
{
if (target.LimitType != typeof(bool))
{
MethodInfo mi = typeof(HelperFunctions).GetMethod("Not");
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(mi, target.Expression)
),
restrictions);
}
}
else if (this.Operation == ExpressionType.Negate)
{
if (!target.LimitType.IsPrimitive || target.LimitType == typeof(bool))
{
MethodInfo mi = typeof(HelperFunctions).GetMethod("Negate");
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(mi, target.Expression)
),
restrictions);
}
}
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.MakeUnary(
this.Operation,
Expression.Convert(target.Expression, target.LimitType),
target.LimitType)),
restrictions);
}
}
}

View file

@ -0,0 +1,295 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting.Runtime;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using AspClassic.Scripting.Utils;
namespace Dlrsoft.VBScript.Compiler
{
// AnalysisScope holds identifier information so that we can do name binding
// during analysis. It manages a map from names to ParameterExprs so ET
// definition locations and reference locations can alias the same variable.
//
// These chain from inner most BlockExprs, through LambdaExprs, to the root
// which models a file or top-level expression. The root has non-None
// ModuleExpr and RuntimeExpr, which are ParameterExprs.
//
internal class AnalysisScope
{
private AnalysisScope _parent;
private string _name;
// Need runtime for interning VBScript constants at code gen time.
private VBScript _runtime;
private ParameterExpression _runtimeParam;
private ParameterExpression _moduleParam;
private ParameterExpression _traceParam;
private ISourceMapper _mapper;
// Need IsLambda when support return to find tightest closing fun.
private bool _isLambda = false;
private bool _isLambdaBody = false;
private bool _isDoLoop = false;
private bool _isForLoop = false;
private bool _isWith = false;
private bool _isOptionExplicitOn = false;
private bool _isOnErrorResumeNextOn = false;
private LabelTarget _loopBreak = null;
private LabelTarget _continueBreak = null;
private LabelTarget _methodExit = null;
private Dictionary<string, ParameterExpression> _names;
private Set<string> _functionTable;
private IList<VBScriptSyntaxError> _errors;
private Expression _withExpression;
private IDictionary<string, SymbolDocumentInfo> _docInfos;
public AnalysisScope(AnalysisScope parent, string name)
: this(parent, name, null, null, null, null) { }
public AnalysisScope(AnalysisScope parent,
string name,
VBScript runtime,
ParameterExpression runtimeParam,
ParameterExpression moduleParam,
ISourceMapper mapper)
{
_parent = parent;
_name = name;
_runtime = runtime;
_runtimeParam = runtimeParam;
_moduleParam = moduleParam;
_mapper = mapper;
if (_moduleParam != null)
{
_functionTable = new Set<string>(StringComparer.InvariantCultureIgnoreCase);
_errors = new List<VBScriptSyntaxError>();
_docInfos = new Dictionary<string, SymbolDocumentInfo>();
}
_names = new Dictionary<string, ParameterExpression>();
}
public AnalysisScope Parent { get { return _parent; } }
public ParameterExpression ModuleExpr { get { return _moduleParam; } }
public ParameterExpression RuntimeExpr { get { return _runtimeParam; } }
public VBScript Runtime { get { return _runtime; } }
public ISourceMapper SourceMapper { get { return _mapper; } }
public string Name { get { return _name; } }
public bool IsModule { get { return _moduleParam != null; } }
public bool IsOptionExplicitOn
{
get { return _isOptionExplicitOn; }
set { _isOptionExplicitOn = value; }
}
public bool IsOnErrorResumeNextOn
{
get { return _isOnErrorResumeNextOn; }
set { _isOnErrorResumeNextOn = value; }
}
public bool IsLambda
{
get { return _isLambda; }
set { _isLambda = value; }
}
public bool IsLambdaBody
{
get { return _isLambdaBody; }
set { _isLambdaBody = value; }
}
public bool IsDoLoop
{
get { return _isDoLoop; }
set { _isDoLoop = value; }
}
public bool IsForLoop
{
get { return _isForLoop; }
set { _isForLoop = value; }
}
public bool IsWith
{
get { return _isWith; }
set { _isWith = value; }
}
public Expression WithExpression
{
get { return _withExpression; }
set { _withExpression = value; }
}
public Expression NearestWithExpression
{
get
{
var curScope = this;
while (!curScope.IsWith && !curScope.IsLambdaBody && !curScope.IsModule) //With cannot across those boundaries
{
curScope = curScope.Parent;
}
return curScope.WithExpression;
}
}
public Expression ErrExpression
{
get
{
return this.ModuleScope.Names[Dlrsoft.VBScript.VBScript.ERR_PARAMETER];
}
}
public Expression TraceExpression
{
get
{
return this.ModuleScope.Names[Dlrsoft.VBScript.VBScript.TRACE_PARAMETER];
}
}
public LabelTarget LoopBreak
{
get { return _loopBreak; }
set { _loopBreak = value; }
}
public LabelTarget LoopContinue
{
get { return _continueBreak; }
set { _continueBreak = value; }
}
public LabelTarget MethodExit
{
get { return _methodExit; }
set { _methodExit = value; }
}
public Dictionary<string, ParameterExpression> Names
{
get { return _names; }
set { _names = value; }
}
public ParameterExpression GetModuleExpr()
{
var curScope = this;
while (!curScope.IsModule)
{
curScope = curScope.Parent;
}
return curScope.ModuleExpr;
}
public AnalysisScope ModuleScope
{
get
{
var curScope = this;
while (!curScope.IsModule)
{
curScope = curScope.Parent;
}
return curScope;
}
}
public AnalysisScope VariableScope
{
get
{
var curScope = this;
while (!curScope.IsModule && !curScope.IsLambdaBody)
{
curScope = curScope.Parent;
}
return curScope;
}
}
public Set<string> FunctionTable
{
get
{
return ModuleScope._functionTable;
}
}
public IList<VBScriptSyntaxError> Errors
{
get { return _errors; }
}
public VBScript GetRuntime()
{
var curScope = this;
while (curScope.Runtime == null)
{
curScope = curScope.Parent;
}
return curScope.Runtime;
}
//Can only call it on ModuleScope
public SymbolDocumentInfo GetDocumentInfo(string path)
{
SymbolDocumentInfo docInfo;
if (_docInfos.ContainsKey(path))
{
docInfo = _docInfos[path];
}
else
{
docInfo = Expression.SymbolDocument(path);
_docInfos.Add(path, docInfo);
}
return docInfo;
}
public void GetVariablesInScope(List<string> names, List<ParameterExpression> parameters)
{
AnalysisScope scope = this;
while (!scope.IsModule)
{
foreach (string name in _names.Keys)
{
names.Add(name);
parameters.Add(_names[name]);
}
scope = scope.Parent;
}
//Now we are dealing with module scope. We want to exclude lambda variables
Set<string> functionTable = FunctionTable;
foreach (string name in _names.Keys)
{
if (!functionTable.Contains(name))
{
names.Add(name);
parameters.Add(_names[name]);
}
}
}
} //AnalysisScope}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting;
namespace Dlrsoft.VBScript.Compiler
{
public class DocSpan
{
public DocSpan(string uri, SourceSpan span)
{
this.Uri = uri;
this.Span = span;
}
public string Uri { get; set; }
public SourceSpan Span { get; set; }
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting;
namespace Dlrsoft.VBScript.Compiler
{
public interface ISourceMapper
{
DocSpan Map(SourceSpan span);
}
}

View file

@ -0,0 +1,88 @@
/* ****************************************************************************
*
* 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.Collections;
using System.Collections.Generic;
namespace Dlrsoft.VBScript.Compiler {
/// <summary>
/// A simple hashset, built on Dictionary{K, V}
/// </summary>
internal sealed class Set<T> : ICollection<T> {
private readonly Dictionary<T, object> _data;
internal Set() {
_data = new Dictionary<T, object>();
}
internal Set(IEqualityComparer<T> comparer) {
_data = new Dictionary<T, object>(comparer);
}
internal Set(IList<T> list) {
_data = new Dictionary<T, object>(list.Count);
foreach (T t in list) {
Add(t);
}
}
internal Set(IEnumerable<T> list) {
_data = new Dictionary<T, object>();
foreach (T t in list) {
Add(t);
}
}
internal Set(int capacity) {
_data = new Dictionary<T, object>(capacity);
}
public void Add(T item) {
_data[item] = null;
}
public void Clear() {
_data.Clear();
}
public bool Contains(T item) {
return _data.ContainsKey(item);
}
public void CopyTo(T[] array, int arrayIndex) {
_data.Keys.CopyTo(array, arrayIndex);
}
public int Count {
get { return _data.Count; }
}
public bool IsReadOnly {
get { return false; }
}
public bool Remove(T item) {
return _data.Remove(item);
}
public IEnumerator<T> GetEnumerator() {
return _data.Keys.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return _data.Keys.GetEnumerator();
}
}
}

View file

@ -0,0 +1,179 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting;
namespace Dlrsoft.VBScript.Compiler
{
public class SourceUtil
{
public static int GetLineCount(string source)
{
int lineCount = 0;
if (string.IsNullOrEmpty(source))
return lineCount;
int start = 0;
int len = source.Length;
while (start < len)
{
int pos = source.IndexOf('\r', start);
if (pos > -1)
{
lineCount++;
}
else
{
break;
}
start = pos + 1;
if (start < len && source[start] == '\n')
{
start++;
}
}
//Last line with CR/LF
//We got an empty line in this situation
if (len >= start)
{
lineCount++;
}
return lineCount;
}
public static Range[] GetLineRanges(string source)
{
if (string.IsNullOrEmpty(source))
return new Range[]{};
List<Range> lineRanges = new List<Range>();
int start = 0;
int len = source.Length;
while (start < len)
{
int pos = source.IndexOf('\r', start);
if (pos < 0)
{
break;
}
if (pos + 1 < len && source[pos + 1] == '\n')
{
pos++;
}
lineRanges.Add(new Range(start, pos));
start = pos + 1;
}
//Last line with CR/LF
if (len > start)
{
lineRanges.Add(new Range(start, len-1));
}
return lineRanges.ToArray();
}
public static LineColumn GetLineColumn(Range[] lineRanges, int index)
{
IComparer comparer = new RangeComparer();
int i = Array.BinarySearch(lineRanges, 0, lineRanges.Length, index, comparer);
return new LineColumn(i + 1, index - lineRanges[i].Start + 1);
}
public static SourceSpan GetSpan(Range[] lineRanges, int start, int end)
{
LineColumn lcStart = GetLineColumn(lineRanges, start);
SourceLocation slStart = new SourceLocation(start, lcStart.Line, lcStart.Column);
LineColumn lcEnd = GetLineColumn(lineRanges, end);
SourceLocation slEnd = new SourceLocation(end, lcEnd.Line, lcEnd.Column);
return new SourceSpan(slStart, slEnd);
}
internal static SourceSpan ConvertSpan(AspClassic.Parser.Span span)
{
AspClassic.Parser.Location start = span.Start;
AspClassic.Parser.Location end = span.Finish;
return new SourceSpan(
new SourceLocation(start.Index, start.Line, start.Column),
new SourceLocation(end.Index, end.Line, end.Column)
);
}
}
public struct Range
{
public int Start;
public int End;
public Range(int start, int end)
{
this.Start = start;
this.End = end;
}
}
public struct LineColumn
{
public int Line;
public int Column;
public LineColumn(int line, int column)
{
this.Line = line;
this.Column = column;
}
}
internal class RangeComparer : IComparer
{
#region IComparer Members
public int Compare(object range, object index)
{
Range theRange = (Range)range;
int theIndex = (int)index;
if (theRange.End < theIndex)
{
return -1;
}
else if (theRange.Start > theIndex)
{
return 1;
}
return 0;
}
#endregion
}
internal class SpanComparer : IComparer<SourceSpan>
{
#region IComparer Members
public int Compare(SourceSpan x, SourceSpan y)
{
if (x.End.Line < y.Start.Line)
{
return -1;
}
else if (x.Start.Line > y.End.Line)
{
return 1;
}
else
{
return 0;
}
}
#endregion
}
}

View file

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Text;
using VB = AspClassic.Parser;
using AspClassic.Scripting.Runtime;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using AspClassic.Scripting.Utils;
using System.Reflection;
using System.IO;
using Dlrsoft.VBScript.Binders;
using Dlrsoft.VBScript.Compiler;
using Dlrsoft.VBScript.Runtime;
using Debug = System.Diagnostics.Debug;
namespace Dlrsoft.VBScript.Compiler
{
/// <summary>
/// The analysis phase. We don't do much except for generating the global functions, constants and variables table
/// </summary>
internal class VBScriptAnalyzer
{
public static void AnalyzeFile(AspClassic.Parser.ScriptBlock block, AnalysisScope scope)
{
Debug.Assert(scope.IsModule);
if (block.Statements != null)
{
foreach (VB.Statement s in block.Statements)
{
AnalyzeStatement(s, scope);
}
}
}
private static void AnalyzeStatement(VB.Statement s, AnalysisScope scope)
{
if (s is VB.MethodDeclaration)
{
string methodName = ((VB.MethodDeclaration)s).Name.Name.ToLower();
scope.FunctionTable.Add(methodName);
ParameterExpression method = Expression.Parameter(typeof(object));
scope.Names[methodName] = method;
}
else if (s is VB.LocalDeclarationStatement)
{
AnalyzeDeclarationExpr((VB.LocalDeclarationStatement)s, scope);
}
else if (s is VB.IfBlockStatement)
{
AnalyzeIfBlockStatement((VB.IfBlockStatement)s, scope);
}
else if (s is VB.SelectBlockStatement)
{
AnalyzeSelectBlockStatement((VB.SelectBlockStatement)s, scope);
}
else if (s is VB.BlockStatement)
{
AnalyzeBlockStatement((VB.BlockStatement)s, scope);
}
}
private static void AnalyzeDeclarationExpr(VB.LocalDeclarationStatement stmt, AnalysisScope scope)
{
bool isConst = false;
if (stmt.Modifiers != null)
{
if (stmt.Modifiers.ModifierTypes == VB.ModifierTypes.Const)
{
isConst = true;
}
}
foreach (VB.VariableDeclarator d in stmt.VariableDeclarators)
{
foreach (VB.VariableName v in d.VariableNames)
{
string name = v.Name.Name.ToLower();
ParameterExpression p = Expression.Parameter(typeof(object), name);
scope.Names.Add(name, p);
}
}
}
private static void AnalyzeIfBlockStatement(VB.IfBlockStatement block, AnalysisScope scope)
{
AnalyzeBlockStatement(block, scope);
if (block.ElseIfBlockStatements != null && block.ElseIfBlockStatements.Count > 0)
{
foreach (VB.ElseIfBlockStatement elseif in block.ElseIfBlockStatements)
{
AnalyzeBlockStatement(elseif, scope);
}
}
if (block.ElseBlockStatement != null)
{
AnalyzeBlockStatement(block.ElseBlockStatement, scope);
}
}
private static void AnalyzeSelectBlockStatement(VB.SelectBlockStatement block, AnalysisScope scope)
{
AnalyzeBlockStatement(block, scope);
if (block.CaseBlockStatements != null && block.CaseBlockStatements.Count > 0)
{
foreach (VB.CaseBlockStatement caseStmt in block.CaseBlockStatements)
{
AnalyzeBlockStatement(caseStmt, scope);
}
}
if (block.CaseElseBlockStatement != null)
{
AnalyzeBlockStatement(block.CaseElseBlockStatement, scope);
}
}
public static void AnalyzeBlockStatement(VB.BlockStatement block, AnalysisScope scope)
{
if (block.Statements != null)
{
foreach (VB.Statement stmt in block.Statements)
{
AnalyzeStatement(stmt, scope);
}
}
}
}
}

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Dlrsoft.VBScript.Compiler
{
public class VBScriptCompilerException : Exception
{
private IList<VBScriptSyntaxError> _errors;
public VBScriptCompilerException(IList<VBScriptSyntaxError> errors)
{
_errors = errors;
}
public IList<VBScriptSyntaxError> SyntaxErrors
{
get { return _errors; }
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using AspClassic.Scripting;
namespace Dlrsoft.VBScript.Compiler
{
public class VBScriptSourceCodeReader : SourceCodeReader
{
private ISourceMapper _mapper;
public VBScriptSourceCodeReader(TextReader textReader, Encoding encoding, ISourceMapper mapper)
: base(textReader, encoding)
{
_mapper = mapper;
}
public ISourceMapper SourceMapper
{
get { return _mapper; }
}
}
}

View file

@ -0,0 +1,66 @@
using System;
using System.Collections;
using System.Collections.Generic;
using AspClassic.Scripting;
using System.Text;
namespace Dlrsoft.VBScript.Compiler
{
public class VBScriptSourceMapper : ISourceMapper
{
//Here the range is start line number and the end line number
private List<SourceSpan> _spans = new List<SourceSpan>(); //use ArrayList so that we can use the binary search method
private IDictionary<SourceSpan, DocSpan> _mappings = new Dictionary<SourceSpan, DocSpan>();
static private SpanComparer _comparer = new SpanComparer();
public VBScriptSourceMapper() {}
public void AddMapping(SourceSpan generatedSpan, DocSpan span)
{
_spans.Add(generatedSpan);
_mappings[generatedSpan] = span;
}
#region ISourceMapper Members
public DocSpan Map(SourceSpan span)
{
int generatedStartLine = span.Start.Line;
int index = _spans.BinarySearch(span, _comparer);
SourceSpan containingSpan = (SourceSpan)_spans[index];
DocSpan docSpan = _mappings[containingSpan];
int rawStartIndex = docSpan.Span.Start.Index + span.Start.Index - containingSpan.Start.Index;
int lineOffSet = generatedStartLine - containingSpan.Start.Line;
int rawStartLine = docSpan.Span.Start.Line + lineOffSet;
int rawStartColumn;
if (lineOffSet == 0)
{
rawStartColumn = docSpan.Span.Start.Column + span.Start.Column;
}
else
{
rawStartColumn = span.Start.Column;
}
int lines = span.End.Line - generatedStartLine;
int rawEndIndex = rawStartIndex + span.End.Index + span.Start.Index;
int rawEndLine = rawStartLine + lines;
int rawEndColumn;
if (lines == 0)
{
rawEndColumn = rawStartColumn + span.End.Column - span.Start.Column;
}
else
{
rawEndColumn = span.End.Column;
}
return new DocSpan(docSpan.Uri,
new SourceSpan(
new SourceLocation(rawStartIndex, rawStartLine, rawStartColumn),
new SourceLocation(rawEndIndex, rawEndLine, rawEndColumn)
)
);
}
#endregion
}
}

View file

@ -0,0 +1,27 @@
using System;
using System.IO;
using System.Dynamic;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting;
using AspClassic.Scripting.Utils;
namespace Dlrsoft.VBScript.Compiler
{
public class VBScriptStringContentProvider : TextContentProvider {
private readonly string _code;
private ISourceMapper _mapper;
public VBScriptStringContentProvider(string code, ISourceMapper mapper)
{
ContractUtils.RequiresNotNull(code, "code");
_code = code;
_mapper = mapper;
}
public override SourceCodeReader GetReader() {
return new VBScriptSourceCodeReader(new StringReader(_code), null, _mapper);
}
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting;
namespace Dlrsoft.VBScript.Compiler
{
public class VBScriptSyntaxError
{
public VBScriptSyntaxError(string fileName, SourceSpan span, int errCode, string errorDesc)
{
this.FileName = fileName;
this.Span = span;
this.ErrorCode = errCode;
this.ErrorDescription = errorDesc;
}
public string FileName { get; set; }
public SourceSpan Span { get; set; }
public int ErrorCode { get; set; }
public string ErrorDescription { get; set; }
}
}

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Dlrsoft.VBScript.Runtime
{
class BuiltInConstants
{
public const int vbUseSystem = 0;
public const int vbUseSystemDayOfWeek = 0;
public const int vbSunday = 1;
public const int vbMonday = 2;
public const int vbTuesday = 3;
public const int vbWednesday = 4;
public const int vbThursday = 5;
public const int vbFriday = 6;
public const int vbSaturday = 7;
public const int vbFirstJan1 = 1;
public const int vbFirstFourDays = 2;
public const int vbFirstFullWeek = 3;
public const int vbOKOnly = 0;
public const int vbOKCancel = 1;
public const int vbAbortRetryIgnore = 2;
public const int vbYesNoCancel = 3;
public const int vbYesNo = 4;
public const int vbRetryCancel = 5;
public const int vbCritical = 16;
public const int vbQuestion = 32;
public const int vbExclamation = 48;
public const int vbInformation = 64;
public const int vbDefaultButton1 = 0;
public const int vbDefaultButton2 = 256;
public const int vbDefaultButton3 = 512;
public const int vbDefaultButton4 = 768;
public const int vbApplicationModal = 0;
public const int vbSystemModal = 4096;
public const int vbOK = 1;
public const int vbCancel = 2;
public const int vbAbort = 3;
public const int vbRetry = 4;
public const int vbIgnore = 5;
public const int vbYes = 6;
public const int vbNo = 7;
public const int vbEmpty = 0;
public const int vbNull = 1;
public const int vbInteger = 2;
public const int vbLong = 3;
public const int vbSingle = 4;
public const int vbDouble = 5;
public const int vbCurrency = 6;
public const int vbDate = 7;
public const int vbString = 8;
public const int vbObject = 9;
public const int vbError = 10;
public const int vbBoolean = 11;
public const int vbVariant = 12;
public const int vbDataObject = 13;
public const int vbDecimal = 14;
public const int vbByte = 17;
public const int vbArray = 8192;
public const bool vbTrue = true;
public const bool vbFalse = false;
public const int vbUseDefault = -2;
public const int vbBinaryCompare = 0;
public const int vbTextCompare = 1;
public const int vbDatabaseCompare = 2;
public const int vbGeneralDate = 0;
public const int vbLongDate = 1;
public const int vbShortDate = 2;
public const int vbLongTime = 3;
public const int vbShortTime = 4;
public const int vbObjectError = -2147221504;
public const int vbBlack = 0x00;
public const int vbBlue = 0xFF;
public const int vbCyan = 0xFFFF00;
public const int vbGreen = 0xFF00;
public const int vbMagenta = 0xFF00FF;
public const int vbRed = 0xFF;
public const int vbWhite = 0xFFFFFF;
public const int vbYellow = 0xFFFF;
public const string vbCr = "\r";
public const string vbCrLf = "\r\n";
public const string vbNewLine = "\r\n";
public const string vbFormFeed = "\u0012";
public const string vbLf = "\n";
public const string vbNullChar = "\u0000";
public const string vbNullString = "";
public const string vbTab = "\t";
public const string vbVerticalTab = "\u0011";
public const int vbMsgBoxHelpButton = 0x4000;
public const int VbMsgBoxSetForeground = 0x10000;
public const int vbMsgBoxRight = 0x80000;
public const int vbMsgBoxRtlReading = 0x100000;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
namespace Dlrsoft.VBScript.Runtime
{
//#####################################################
//# Dynamic Helpers for HasMember, GetMember, SetMember
//#####################################################
// DynamicObjectHelpers provides access to IDynObj members given names as
// data at runtime. When the names are known at compile time (o.foo), then
// they get baked into specific sites with specific binders that encapsulate
// the name. We need this in python because hasattr et al are case-sensitive.
//
class DynamicObjectHelpers
{
static private object _sentinel = new object();
static internal object Sentinel { get { return _sentinel; } }
internal static bool HasMember(IDynamicMetaObjectProvider o,
string name)
{
return (DynamicObjectHelpers.GetMember(o, name) !=
DynamicObjectHelpers.Sentinel);
//Alternative impl used when EOs had bug and didn't call fallback ...
//var mo = o.GetMetaObject(Expression.Parameter(typeof(object), null));
//foreach (string member in mo.GetDynamicMemberNames()) {
// if (string.Equals(member, name, StringComparison.OrdinalIgnoreCase)) {
// return true;
// }
//}
//return false;
}
static private Dictionary<string,
CallSite<AspClassic.Scripting.Utils.Func<CallSite, object, object>>>
_getSites = new Dictionary<string,
CallSite<AspClassic.Scripting.Utils.Func<CallSite, object, object>>>();
internal static object GetMember(IDynamicMetaObjectProvider o,
string name)
{
CallSite<AspClassic.Scripting.Utils.Func<CallSite, object, object>> site;
if (!DynamicObjectHelpers._getSites.TryGetValue(name, out site))
{
site = CallSite<AspClassic.Scripting.Utils.Func<CallSite, object, object>>
.Create(new DoHelpersGetMemberBinder(name));
DynamicObjectHelpers._getSites[name] = site;
}
return site.Target(site, o);
}
static private Dictionary<string,
CallSite<AspClassic.Scripting.Utils.Action<CallSite, object, object>>>
_setSites = new Dictionary<string,
CallSite<AspClassic.Scripting.Utils.Action<CallSite, object, object>>>();
internal static void SetMember(IDynamicMetaObjectProvider o, string name,
object value)
{
CallSite<AspClassic.Scripting.Utils.Action<CallSite, object, object>> site;
if (!DynamicObjectHelpers._setSites.TryGetValue(name, out site))
{
site = CallSite<AspClassic.Scripting.Utils.Action<CallSite, object, object>>
.Create(new DoHelpersSetMemberBinder(name));
DynamicObjectHelpers._setSites[name] = site;
}
site.Target(site, o, value);
}
}
class DoHelpersGetMemberBinder : GetMemberBinder
{
internal DoHelpersGetMemberBinder(string name) : base(name, true) { }
public override DynamicMetaObject FallbackGetMember(
DynamicMetaObject target, DynamicMetaObject errorSuggestion)
{
return errorSuggestion ??
new DynamicMetaObject(
Expression.Constant(DynamicObjectHelpers.Sentinel),
target.Restrictions.Merge(
BindingRestrictions.GetTypeRestriction(
target.Expression, target.LimitType)));
}
}
class DoHelpersSetMemberBinder : SetMemberBinder
{
internal DoHelpersSetMemberBinder(string name) : base(name, true) { }
public override DynamicMetaObject FallbackSetMember(
DynamicMetaObject target, DynamicMetaObject value,
DynamicMetaObject errorSuggestion)
{
return errorSuggestion ??
RuntimeHelpers.CreateThrow(
target, null, BindingRestrictions.Empty,
typeof(MissingMemberException),
"If IDynObj doesn't support setting members, " +
"DOHelpers can't do it for the IDO.");
}
}
}

View file

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Dlrsoft.VBScript.Runtime
{
public class ErrObject
{
private int _number;
private string _description = string.Empty;
private string _source = string.Empty;
private string _helpContext = string.Empty;
private string _helpFile = string.Empty;
public int Number { get { return _number; } }
public string Description { get { return _description; } }
public string Source { get { return _source; } }
public string HelpContext { get { return _helpContext; } }
public string HelpFile { get { return _helpFile; } }
public void Clear()
{
if (_number != 0)
{
_number = 0;
_description = string.Empty;
_source = string.Empty;
_helpContext = string.Empty;
_helpFile = string.Empty;
}
}
public void Raise(int number)
{
Raise(number, string.Empty);
}
public void Raise(int number, string source)
{
Raise(number, source, string.Empty);
}
public void Raise(int number, string source, string description)
{
Raise(number, source, description, string.Empty);
}
public void Raise(int number, string source, string description, string helpFile)
{
Raise(number, source, description, helpFile, string.Empty);
}
public void Raise(int number, string source, string description, string helpFile, string helpContext)
{
throw new VBScriptRuntimeException(number, source, description, helpFile, helpContext);
}
public override string ToString()
{
return _number.ToString();
}
internal void internalRaise(int number, string source, string description, string helpFile, string helpContext)
{
this._number = number;
this._description = description;
this._source = source;
this._helpContext = helpContext;
this._helpFile = helpFile;
}
internal void internalRaise(Exception ex)
{
VBScriptRuntimeException vbEx = ex as VBScriptRuntimeException;
if (vbEx == null)
{
vbEx = new VBScriptRuntimeException(ex);
}
internalRaise(vbEx.Number, vbEx.Source, vbEx.Description, vbEx.HelpFile, vbEx.HelpContext);
}
}
}

View file

@ -0,0 +1,667 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Threading;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
namespace Dlrsoft.VBScript.Runtime
{
public class HelperFunctions
{
public static object GetDefaultPropertyValue(object target)
{
if (target == null) return target;
while (target.GetType().IsCOMObject)
{
target = target.GetType().InvokeMember(string.Empty,
BindingFlags.Default | BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetProperty,
null,
target,
null);
}
return target;
}
public static object Concatenate(object left, object right)
{
bool leftDBNull = false;
if (left == null)
{
left = String.Empty;
}
else if (left is DBNull)
{
left = String.Empty;
leftDBNull = true;
}
else
{
if (left.GetType().IsCOMObject)
{
left = GetDefaultPropertyValue(left);
}
if (!(left is string))
{
left = left.ToString();
}
}
if (right == null)
{
right = string.Empty;
}
else if (right is DBNull)
{
if (leftDBNull) return DBNull.Value;
right = string.Empty;
}
else
{
if (right.GetType().IsCOMObject)
{
right = GetDefaultPropertyValue(right);
}
if (!(right is string))
{
right = right.ToString();
}
}
return (string)left + (string)right;
}
public static object BinaryOp(ExpressionType op, object left, object right)
{
if (left == null || right == null)
{
if (op == ExpressionType.Equal)
{
if (left == null && right == null)
{
return true;
}
else if (string.Empty.Equals(left) || string.Empty.Equals(right))
{
return true;
}
else
{
return false;
}
}
else if (op == ExpressionType.NotEqual)
{
if (left == null && right == null)
{
return false;
}
else if (string.Empty.Equals(left) || string.Empty.Equals(right))
{
return false;
}
else
{
return true;
}
}
else
{
return null;
}
}
Type ltype = left.GetType();
Type rtype = right.GetType();
if (op == ExpressionType.Equal)
{
if (left == right) return true;
}
if (ltype.IsCOMObject)
{
left = GetDefaultPropertyValue(left);
ltype = left.GetType();
}
if (rtype.IsCOMObject)
{
right = GetDefaultPropertyValue(right);
rtype = right.GetType();
}
if (!ltype.IsValueType && ltype != typeof(string))
{
left = left.ToString();
ltype = typeof(string);
}
if (!rtype.IsValueType && rtype != typeof(string))
{
right = right.ToString();
rtype = typeof(string);
}
Type targetType;
if (ltype == rtype || CanConvert(rtype, ltype))
{
targetType = ltype;
}
else
{
targetType = rtype;
}
switch (op)
{
case ExpressionType.Add:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) + Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) + Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) + Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) + Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) + Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
return (string)left + (string)right;
}
break;
case ExpressionType.Subtract:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) - Convert.ToInt32(right);
}
else if (targetType == typeof(double) || targetType == typeof(string))
{
return Convert.ToDouble(left) - Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) - Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) - Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) - Convert.ToDecimal(right);
}
break;
case ExpressionType.Multiply:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) * Convert.ToInt32(right);
}
else if (targetType == typeof(double) || targetType == typeof(string))
{
return Convert.ToDouble(left) * Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) * Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) * Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) * Convert.ToDecimal(right);
}
break;
case ExpressionType.Divide:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) / Convert.ToInt32(right);
}
else if (targetType == typeof(double) || targetType == typeof(string))
{
return Convert.ToDouble(left) / Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) / Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) / Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) / Convert.ToDecimal(right);
}
break;
case ExpressionType.Equal:
try
{
if (targetType == typeof(int))
{
return Convert.ToInt32(left) == Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) == Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) == Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) == Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) == Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
return ((string)left).Equals(right);
}
else
{
return left == right;
}
}
catch (Exception ex)
{
return false;
}
case ExpressionType.NotEqual:
try
{
if (targetType == typeof(int))
{
return Convert.ToInt32(left) != Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) != Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) != Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) != Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) != Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
return !((string)left).Equals(right);
}
else
{
return left != right;
}
}
catch (Exception ex)
{
return true;
}
case ExpressionType.GreaterThan:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) > Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) > Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) > Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) > Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) > Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
int result = ((string)left).CompareTo(right);
return (result > 0);
}
break;
case ExpressionType.GreaterThanOrEqual:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) >= Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) >= Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) >= Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) >= Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) >= Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
int result = ((string)left).CompareTo(right);
return (result >= 0);
}
break;
case ExpressionType.LessThan:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) < Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) < Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) < Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) < Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) < Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
int result = ((string)left).CompareTo(right);
return (result < 0);
}
break;
case ExpressionType.LessThanOrEqual:
if (targetType == typeof(int))
{
return Convert.ToInt32(left) <= Convert.ToInt32(right);
}
else if (targetType == typeof(double))
{
return Convert.ToDouble(left) <= Convert.ToDouble(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) <= Convert.ToInt64(right);
}
else if (targetType == typeof(float))
{
return Convert.ToSingle(left) <= Convert.ToSingle(right);
}
else if (targetType == typeof(decimal))
{
return Convert.ToDecimal(left) <= Convert.ToDecimal(right);
}
else if (targetType == typeof(string))
{
int result = ((string)left).CompareTo(right);
return (result <= 0);
}
break;
case ExpressionType.And:
if (targetType == typeof(bool))
{
return (bool)left && (bool)right;
}
else if (targetType == typeof(int))
{
return Convert.ToInt32(left) & Convert.ToInt32(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) & Convert.ToInt64(right);
}
else
{
return (bool)BuiltInFunctions.CBool(left) && (bool)BuiltInFunctions.CBool(right);
}
break;
case ExpressionType.Or:
if (targetType == typeof(bool))
{
return (bool)left || (bool)right;
}
else if (targetType == typeof(int))
{
return Convert.ToInt32(left) | Convert.ToInt32(right);
}
else if (targetType == typeof(long))
{
return Convert.ToInt64(left) | Convert.ToInt64(right);
}
else
{
return (bool)BuiltInFunctions.CBool(left) || (bool)BuiltInFunctions.CBool(right);
}
break;
}
throw new ArgumentException(string.Format("Operation {0} between {1} and {2} is not implemeted.", op, ltype.Name, rtype.Name));
}
private static bool CanConvert(Type fromType, Type toType)
{
if (toType.IsAssignableFrom(fromType)) return true;
if (fromType == typeof(string) && (toType.IsPrimitive))
{
return true;
}
return false;
}
public static object Redim(Type t, params int[] ubounds)
{
return redimInternal(t, ubounds);
}
public static Array redimInternal(Type t, params int[] ubounds)
{
if (ubounds == null) throw new ArgumentException("Must supply bound(s) when redim an array.");
for (int i = 0; i < ubounds.Length; i++)
{
//Convert from ubound to length
ubounds[i] += 1;
}
return Array.CreateInstance(t, ubounds);
}
//public static object RedimPreserve(object array, int length1)
//{
// return redimPreserveInternal(array, length1);
//}
//public static object RedimPreserve(object array, int length1, int length2)
//{
// return redimPreserveInternal(array, length1, length2);
//}
//public static object RedimPreserve(object array, int length1, int length2, int length3)
//{
// return redimPreserveInternal(array, length1, length2, length3);
//}
//public static object RedimPreserve(object array, int length1, int length2, int length3, int length4)
//{
// return redimPreserveInternal(array, length1, length2, length3, length4);
//}
//public static object RedimPreserve(object array, int length1, int length2, int length3, int length4, int length5)
//{
// return redimPreserveInternal(array, length1, length2, length3, length4, length5);
//}
//public static object RedimPreserve(object array, int length1, int length2, int length3, int length4, int length5, int length6)
//{
// return redimPreserveInternal(array, length1, length2, length3, length4, length5, length6);
//}
public static object RedimPreserve(object array, params int[] lengths)
{
return redimPreserveInternal(array, lengths);
}
private static Array redimPreserveInternal(object array, params int[] lengths)
{
if (array == null) throw new ArgumentException("To redim an array, the array must be a previously declared array.");
Type t = array.GetType();
if (!t.IsArray) throw new ArgumentException("Redim variable is not an array.");
int oldDimension = ((Array)array).Rank;
int newDimension = lengths.Length;
if (oldDimension != newDimension) throw new ArgumentException(string.Format("Cannot change dimension of the array from {0} to {1}", oldDimension, newDimension));
int elementsToCopy = 1;
for (int i = 0; i < oldDimension - 1; i++)
{
int oldBound = ((Array)array).GetUpperBound(i);
if (oldBound != lengths[i])
throw new ArgumentException(string.Format("Can only resize the last dimension. You are trying to resize dimension {0} from {1} to {2}",
i + 1, oldBound, lengths[i]));
elementsToCopy *= ((Array)array).GetLength(i);
}
elementsToCopy *= (((Array)array).GetLength(oldDimension - 1) < lengths[oldDimension - 1]) ? ((Array)array).GetLength(oldDimension - 1) : lengths[oldDimension - 1];
Array newArray = redimInternal(t.GetElementType(), lengths);
Array.Copy((Array)array, newArray, elementsToCopy);
return newArray;
}
public static void SetError(ErrObject err, Exception ex)
{
//Don't catch ThreadAbortException since it is captured by Response.Redirect
if (ex is ThreadAbortException)
throw ex;
err.internalRaise(ex);
}
public static object Eqv(object left, object right)
{
if (left is DBNull || right is DBNull) return DBNull.Value;
CheckLogicOperand(ref left);
CheckLogicOperand(ref right);
if (left is int) BoolToInt(ref right);
if (right is int) BoolToInt(ref left);
if (left is bool)
return (bool)left == (bool)right;
return ~((int)left ^ (int)right);
}
public static object Imp(object left, object right)
{
throw new NotImplementedException("Imp method is not implemented.");
}
public static object Not(object target)
{
if (target == null) return null;
if (target.GetType().IsCOMObject)
{
target = GetDefaultPropertyValue(target);
}
return !(bool)BuiltInFunctions.CBool(target);
}
public static object Negate(object target)
{
if (target == null) return null;
if (target.GetType().IsCOMObject)
{
target = GetDefaultPropertyValue(target);
}
return -(double)BuiltInFunctions.CDbl(target);
}
private static void CheckLogicOperand(ref object value)
{
if (value == null) value = 0;
if (value is float || value is double)
{
value = Convert.ToInt32(value);
}
if (value is string)
{
bool boolResult;
int intResult;
if (bool.TryParse((string)value, out boolResult))
{
value = boolResult;
}
else if (int.TryParse((string)value, out intResult))
{
value = intResult;
}
}
if (value is bool || value is int) return;
throw new ArgumentException("Logic functions or operators requires arguments that can be converted to bool or int.");
}
private static void BoolToInt(ref object value)
{
if (value is bool) value = (bool)value ? -1 : 0;
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Dlrsoft.VBScript.Runtime
{
public interface IAssert
{
void AreEqual(object expected, object actual);
void AreEqual(object expected, object actual, string message);
void AreNotEqual(object notExpected, object actual);
void AreNotEqual(object notExpected, object actual, string message);
void Fail();
void Fail(string message);
void IsFalse(bool condition);
void IsFalse(bool condition, string message);
void IsTrue(bool condition);
void IsTrue(bool condition, string message);
}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
namespace Dlrsoft.VBScript.Runtime
{
public interface ITrace
{
//void TraceDebugInfo(SymbolDocumentInfo docInfo, int startLine, int startColumn, int endLine, int endColumn);
void TraceDebugInfo(string source, int startLine, int startColumn, int endLine, int endColumn);
//void RegisterRuntimeVariables(string[] varNames, IRuntimeVariables runtimeVariables);
}
}

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
namespace Dlrsoft.VBScript.Runtime
{
// This class is needed to canonicalize InvokeMemberBinders in Sympl. See
// the comment above the GetXXXBinder methods at the end of the Sympl class.
//
public class InvokeMemberBinderKey
{
string _name;
CallInfo _info;
public InvokeMemberBinderKey(string name, CallInfo info)
{
_name = name;
_info = info;
}
public string Name { get { return _name; } }
public CallInfo Info { get { return _info; } }
public override bool Equals(object obj)
{
InvokeMemberBinderKey key = obj as InvokeMemberBinderKey;
// Don't lower the name. Sympl is case-preserving in the metadata
// in case some DynamicMetaObject ignores ignoreCase. This makes
// some interop cases work, but the cost is that if a Sympl program
// spells ".foo" and ".Foo" at different sites, they won't share rules.
return key != null && key._name == _name && key._info.Equals(_info);
}
public override int GetHashCode()
{
// Stolen from DLR sources when it overrode GetHashCode on binders.
return 0x28000000 ^ _name.GetHashCode() ^ _info.GetHashCode();
}
} //InvokeMemberBinderKey
}

View file

@ -0,0 +1,683 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq;
using System.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
using Path = System.IO.Path;
using File = System.IO.File;
using Directory = System.IO.Directory;
using Debug = System.Diagnostics.Debug;
#if SILVERLIGHT
using w = System.Windows;
using System.Windows.Resources;
#endif
namespace Dlrsoft.VBScript.Runtime
{
// RuntimeHelpers is a collection of functions that perform operations at
// runtime of Sympl code, such as performing an import or eq.
//
public static class RuntimeHelpers {
// VBScriptImport takes the runtime and module as context for the import.
// It takes a list of names, what, that either identify a (possibly dotted
// sequence) of names to fetch from Globals or a file name to load. Names
// is a list of names to fetch from the final object that what indicates
// and then set each name in module. Renames is a list of names to add to
// module instead of names. If names is empty, then the name set in
// module is the last name in what. If renames is not empty, it must have
// the same cardinality as names.
//
public static object VBScriptImport(VBScript runtime, IDynamicMetaObjectProvider module,
string[] what, string[] names,
string[] renames)
{
// Get object or file scope.
object value = null;
if (what.Length == 1)
{
string name = what[0];
if (DynamicObjectHelpers.HasMember(runtime.Globals, name))
{
value = DynamicObjectHelpers.GetMember(runtime.Globals, name);
// Since runtime.Globals has Sympl's reflection of namespaces and
// types, we pick those up first above and don't risk hitting a
// NamespaceTracker for assemblies added when we initialized Sympl.
// The next check will correctly look up case-INsensitively for
// globals the host adds to ScriptRuntime.Globals.
}
else if (DynamicObjectHelpers.HasMember(runtime.DlrGlobals, name))
{
value = DynamicObjectHelpers.GetMember(runtime.DlrGlobals, name);
}
else
{
throw new ArgumentException(
"Import: can't find name in globals -- " + name);
}
}
else
{
// What has more than one name, must be Globals access.
value = runtime.Globals;
// For more correctness and generality, shouldn't assume all
// globals are dynamic objects, or that a look up like foo.bar.baz
// cascades through all dynamic objects.
// Would need to manually create a CallSite here with Sympl's
// GetMemberBinder, and think about a caching strategy per name.
foreach (string name in what)
{
value = DynamicObjectHelpers.GetMember(
(IDynamicMetaObjectProvider)value, name);
}
}
// Assign variables in module.
if (names.Length == 0)
{
if (renames.Length == 0)
{
DynamicObjectHelpers.SetMember((IDynamicMetaObjectProvider)module,
what[what.Length - 1], value);
}
else
{
DynamicObjectHelpers.SetMember((IDynamicMetaObjectProvider)module,
renames[0], value);
}
}
else
{
if (renames.Length == 0) renames = names;
for (int i = 0; i < names.Length; i++)
{
string name = names[i];
string rename = renames[i];
DynamicObjectHelpers.SetMember(
(IDynamicMetaObjectProvider)module, rename,
DynamicObjectHelpers.GetMember(
(IDynamicMetaObjectProvider)value, name));
}
}
return null;
} // SymplImport
// Uses of the 'eq' keyword form in Sympl compile to a call to this
// helper function.
//
public static bool SymplEq (object x, object y) {
if (x == null)
return y == null;
else if (y == null)
return x == null;
else {
var xtype = x.GetType();
var ytype = y.GetType();
if (xtype.IsPrimitive && xtype != typeof(string) &&
ytype.IsPrimitive && ytype != typeof(string))
return x.Equals(y);
else
return object.ReferenceEquals(x, y);
}
}
//////////////////////////////////////////////////
// Array Utilities (slicing) and some LINQ helpers
//////////////////////////////////////////////////
public static T[] RemoveFirstElt<T>(IList<T> list) {
// Make array ...
if (list.Count == 0) {
return new T[0];
}
T[] res = new T[list.Count];
list.CopyTo(res, 0);
// Shift result
return ShiftLeft(res, 1);
}
public static T[] RemoveFirstElt<T>(T[] array) {
return ShiftLeft(array, 1);
}
private static T[] ShiftLeft<T>(T[] array, int count) {
//ContractUtils.RequiresNotNull(array, "array");
if (count < 0) throw new ArgumentOutOfRangeException("count");
T[] result = new T[array.Length - count];
System.Array.Copy(array, count, result, 0, result.Length);
return result;
}
public static T[] RemoveLast<T>(T[] array) {
//ContractUtils.RequiresNotNull(array, "array");
System.Array.Resize(ref array, array.Length - 1);
return array;
}
#if USE35
// Need to reproduce these helpers from DLR codeplex-only sources and
// from LINQ functionality to avoid referencing System.Core.dll and
// AspClassic.Scripting.Core.dll for internal building.
internal static IEnumerable<U> Select<T, U>(this IEnumerable<T> enumerable, AspClassic.Scripting.Utils.Func<T, U> select) {
foreach (T t in enumerable) {
yield return select(t);
}
}
internal static IEnumerable<T> Where<T>(this IEnumerable<T> enumerable, AspClassic.Scripting.Utils.Func<T, bool> where) {
foreach (T t in enumerable) {
if (where(t)) {
yield return t;
}
}
}
internal static bool Any<T>(this IEnumerable<T> source, AspClassic.Scripting.Utils.Func<T, bool> predicate) {
foreach (T element in source) {
if (predicate(element)) {
return true;
}
}
return false;
}
internal static T[] ToArray<T>(this IEnumerable<T> enumerable) {
var c = enumerable as ICollection<T>;
if (c != null) {
var result = new T[c.Count];
c.CopyTo(result, 0);
return result;
}
return new List<T>(enumerable).ToArray();
}
internal static TSource Last<TSource>(this IList<TSource> list) {
if (list == null) throw new ArgumentNullException("list");
int count = list.Count;
if (count > 0) return list[count - 1];
throw new ArgumentException("list is empty");
}
internal static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value) {
IEqualityComparer<TSource> comparer = EqualityComparer<TSource>.Default;
if (source == null) throw new ArgumentNullException("source");
foreach (TSource element in source)
if (comparer.Equals(element, value)) return true;
return false;
}
#endif
///////////////////////////////////////
// Utilities used by binders at runtime
///////////////////////////////////////
// ParamsMatchArgs returns whether the args are assignable to the parameters.
// We specially check for our TypeModel that wraps .NET's RuntimeType, and
// elsewhere we detect the same situation to convert the TypeModel for calls.
//
// Consider checking p.IsByRef and returning false since that's not CLS.
//
// Could check for a.HasValue and a.Value is None and
// ((paramtype is class or interface) or (paramtype is generic and
// nullable<t>)) to support passing nil anywhere.
//
public static bool ParametersMatchArguments(ParameterInfo[] parameters,
DynamicMetaObject[] args) {
// We only call this after filtering members by this constraint.
Debug.Assert(args.Length == parameters.Length,
"Internal: args are not same len as params?!");
for (int i = 0; i < args.Length; i++) {
var paramType = parameters[i].ParameterType;
// We consider arg of TypeModel and param of Type to be compatible.
if (paramType == typeof(Type) &&
(args[i].LimitType == typeof(TypeModel))) {
continue;
}
//LC OK to assign null to any reference type
if (!paramType.IsValueType && args[i].Value == null)
continue;
if (!paramType
// Could check for HasValue and Value==null AND
// (paramtype is class or interface) or (is generic
// and nullable<T>) ... to bind nullables and null.
.IsAssignableFrom(args[i].LimitType)) {
return false;
}
}
return true;
}
public static int[] GetMatchRank(ParameterInfo[] parameters,
DynamicMetaObject[] args)
{
Debug.Assert(args.Length == parameters.Length,
"Internal: args are not same len as params?!");
int[] rank = new int[parameters.Length];
for (int i = 0; i < args.Length; i++)
{
var paramType = parameters[i].ParameterType;
// We consider arg of TypeModel and param of Type to be compatible.
if (paramType == typeof(Type) &&
(args[i].LimitType == typeof(TypeModel)))
{
rank[i] = 0;
}
else if (paramType == args[i].LimitType)
{
rank[i] = 0;
}
else
{
rank[i] = 1;
}
}
return rank;
}
public static MethodInfo ResolveOverload(IList<MethodInfo> mis, DynamicMetaObject[] args)
{
MethodInfo best = mis[0];
int[] bestRank = GetMatchRank(mis[0].GetParameters(), args);
foreach (MethodInfo mi in mis)
{
int[] rank = GetMatchRank(mi.GetParameters(), args);
if (Compare(rank, bestRank) < 0)
{
best = mi;
bestRank = rank;
}
}
return best;
}
private static int Compare(int[] a, int[] b)
{
for (int i = 0; i < a.Length; i++)
{
int result = a[i].CompareTo(b[i]);
if (result == 0)
continue;
return result;
}
return 0;
}
// Returns a DynamicMetaObject with an expression that fishes the .NET
// RuntimeType object from the TypeModel MO.
//
public static DynamicMetaObject GetRuntimeTypeMoFromModel(
DynamicMetaObject typeModelMO) {
Debug.Assert((typeModelMO.LimitType == typeof(TypeModel)),
"Internal: MO is not a TypeModel?!");
// Get tm.ReflType
var pi = typeof(TypeModel).GetProperty("ReflType");
Debug.Assert(pi != null);
return new DynamicMetaObject(
Expression.Property(
Expression.Convert(typeModelMO.Expression, typeof(TypeModel)),
pi),
typeModelMO.Restrictions.Merge(
BindingRestrictions.GetTypeRestriction(
typeModelMO.Expression, typeof(TypeModel)))//,
// Must supply a value to prevent binder FallbackXXX methods
// from infinitely looping if they do not check this MO for
// HasValue == false and call Defer. After Sympl added Defer
// checks, we could verify, say, FallbackInvokeMember by no
// longer passing a value here.
//((TypeModel)typeModelMO.Value).ReflType
);
}
// Returns list of Convert exprs converting args to param types. If an arg
// is a TypeModel, then we treat it special to perform the binding. We need
// to map from our runtime model to .NET's RuntimeType object to match.
//
// To call this function, args and pinfos must be the same length, and param
// types must be assignable from args.
//
// NOTE, if using this function, then need to use GetTargetArgsRestrictions
// and make sure you're performing the same conversions as restrictions.
//
public static Expression[] ConvertArguments(
DynamicMetaObject[] args, ParameterInfo[] ps) {
Debug.Assert(args.Length == ps.Length,
"Internal: args are not same len as params?!");
Expression[] callArgs = new Expression[args.Length];
for (int i = 0; i < args.Length; i++) {
Expression argExpr = args[i].Expression;
if (args[i].LimitType == typeof(TypeModel) &&
ps[i].ParameterType == typeof(Type)) {
// Get arg.ReflType
argExpr = GetRuntimeTypeMoFromModel(args[i]).Expression;
}
Type paramType;
if (ps[i].ParameterType.IsByRef)
{
paramType = ps[i].ParameterType.GetElementType();
}
else
{
paramType = ps[i].ParameterType;
}
if (argExpr.Type != paramType)
{
argExpr = Expression.Convert(argExpr, paramType);
}
callArgs[i] = argExpr;
}
return callArgs;
}
public static Expression ConvertExpression(Expression expr, Type type)
{
if (type == expr.Type)
{
return expr;
}
else if (type == typeof(string))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CStr"),
expr
);
}
else if (type == typeof(int))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CLng"),
expr
);
}
else if (type == typeof(double))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CDbl"),
expr
);
}
else if (type == typeof(bool))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CBool"),
expr
);
}
else if (type == typeof(decimal))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CCur"),
expr
);
}
else if (type == typeof(DateTime))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CDate"),
expr
);
}
else if (type == typeof(short))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CInt"),
expr
);
}
else if (type == typeof(float))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CSng"),
expr
);
}
else if (type == typeof(byte))
{
return Expression.Call(
typeof(BuiltInFunctions).GetMethod("CByte"),
expr
);
}
else
{
return Expression.Convert(expr, type);
}
}
// GetTargetArgsRestrictions generates the restrictions needed for the
// MO resulting from binding an operation. This combines all existing
// restrictions and adds some for arg conversions. targetInst indicates
// whether to restrict the target to an instance (for operations on type
// objects) or to a type (for operations on an instance of that type).
//
// NOTE, this function should only be used when the caller is converting
// arguments to the same types as these restrictions.
//
public static BindingRestrictions GetTargetArgsRestrictions(
DynamicMetaObject target, DynamicMetaObject[] args,
bool instanceRestrictionOnTarget){
// Important to add existing restriction first because the
// DynamicMetaObjects (and possibly values) we're looking at depend
// on the pre-existing restrictions holding true.
var restrictions = target.Restrictions.Merge(BindingRestrictions
.Combine(args));
//LC Use instance restriction is value is null
if (instanceRestrictionOnTarget || target.Value == null)
{
restrictions = restrictions.Merge(
BindingRestrictions.GetInstanceRestriction(
target.Expression,
target.Value
));
} else {
restrictions = restrictions.Merge(
BindingRestrictions.GetTypeRestriction(
target.Expression,
target.LimitType
));
}
for (int i = 0; i < args.Length; i++) {
BindingRestrictions r;
if (args[i].HasValue && args[i].Value == null) {
r = BindingRestrictions.GetInstanceRestriction(
args[i].Expression, null);
} else {
r = BindingRestrictions.GetTypeRestriction(
args[i].Expression, args[i].LimitType);
}
restrictions = restrictions.Merge(r);
}
return restrictions;
}
// Return the expression for getting target[indexes]
//
// Note, callers must ensure consistent restrictions are added for
// the conversions on args and target.
//
public static Expression GetIndexingExpression(
DynamicMetaObject target,
DynamicMetaObject[] indexes) {
//Debug.Assert(target.HasValue && target.LimitType != typeof(Array));
// ARRAY
if (target.LimitType.IsArray)
{
var indexExpressions = indexes.Select(
i => Expression.Convert(i.Expression, i.LimitType))
.ToArray();
return Expression.ArrayAccess(
Expression.Convert(target.Expression,
target.LimitType),
indexExpressions
);
// INDEXER
} else {
var props = target.LimitType.GetProperties();
var indexers = props.
Where(p => p.GetIndexParameters().Length > 0).ToArray();
indexers = indexers.
Where(idx => idx.GetIndexParameters().Length ==
indexes.Length).ToArray();
var res = new List<PropertyInfo>();
foreach (var idxer in indexers) {
if (RuntimeHelpers.ParametersMatchArguments(
idxer.GetIndexParameters(), indexes)) {
// all parameter types match
res.Add(idxer);
}
}
if (res.Count == 0) {
return Expression.Throw(
Expression.New(
typeof(MissingMemberException)
.GetConstructor(new Type[] { typeof(string) }),
Expression.Constant(
"Can't bind because there is no matching indexer.")
)
);
}
return Expression.MakeIndex(
Expression.Convert(target.Expression, target.LimitType),
res[0], ConvertArguments(indexes, res[0].GetIndexParameters()));
}
}
// CreateThrow is a convenience function for when binders cannot bind.
// They need to return a DynamicMetaObject with appropriate restrictions
// that throws. Binders never just throw due to the protocol since
// a binder or MO down the line may provide an implementation.
//
// It returns a DynamicMetaObject whose expr throws the exception, and
// ensures the expr's type is object to satisfy the CallSite return type
// constraint.
//
// A couple of calls to CreateThrow already have the args and target
// restrictions merged in, but BindingRestrictions.Merge doesn't add
// duplicates.
//
public static DynamicMetaObject CreateThrow
(DynamicMetaObject target, DynamicMetaObject[] args,
BindingRestrictions moreTests,
Type exception, params object[] exceptionArgs) {
Expression[] argExprs = null;
Type[] argTypes = Type.EmptyTypes;
int i;
if (exceptionArgs != null) {
i = exceptionArgs.Length;
argExprs = new Expression[i];
argTypes = new Type[i];
i = 0;
foreach (object o in exceptionArgs) {
Expression e = Expression.Constant(o);
argExprs[i] = e;
argTypes[i] = e.Type;
i += 1;
}
}
ConstructorInfo constructor = exception.GetConstructor(argTypes);
if (constructor == null) {
throw new ArgumentException(
"Type doesn't have constructor with a given signature");
}
return new DynamicMetaObject(
Expression.Throw(
Expression.New(constructor, argExprs),
// Force expression to be type object so that DLR CallSite
// code things only type object flows out of the CallSite.
typeof(object)),
target.Restrictions.Merge(BindingRestrictions.Combine(args))
.Merge(moreTests));
}
// EnsureObjectResult wraps expr if necessary so that any binder or
// DynamicMetaObject result expression returns object. This is required
// by CallSites.
//
public static Expression EnsureObjectResult (Expression expr) {
if (! expr.Type.IsValueType)
return expr;
if (expr.Type == typeof(void))
return Expression.Block(
expr, Expression.Default(typeof(object)));
else
return Expression.Convert(expr, typeof(object));
}
public static Expression GetDefaultValue(Expression target)
{
return Expression.Call(
typeof(HelperFunctions).GetMethod("GetDefaultPropertyValue", new Type[] { typeof(object) }),
EnsureObjectResult(target)
);
}
public static List<MethodInfo> GetExtensionMethods(string name, DynamicMetaObject targetMO, DynamicMetaObject[] args)
{
List<MethodInfo> res = new List<MethodInfo>();
#if !SILVERLIGHT
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
#else
foreach (w.AssemblyPart ap in w.Deployment.Current.Parts)
{
StreamResourceInfo sri = w.Application.GetResourceStream(new Uri(ap.Source, UriKind.Relative));
Assembly a = new w.AssemblyPart().Load(sri.Stream);
#endif
Type[] types;
try
{
types = a.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
types = ex.Types;
}
foreach (Type t in types)
{
if (t != null && t.IsPublic && t.IsAbstract && t.IsSealed)
{
foreach (MethodInfo mem in t.GetMember(name, MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase))
{
//Should test using mem.IsDefined(attr) but typeof(ExtenssionAttribute) in Microsoft.Scription.Extensions and System.Core are infact two different types
//Type attr = typeof(System.Runtime.CompilerServices.ExtensionAttribute);
if (mem.GetParameters().Length == args.Length
&& mem.GetParameters()[0].ParameterType == targetMO.RuntimeType)
{
if (RuntimeHelpers.ParametersMatchArguments(
mem.GetParameters(), args))
{
res.Add(mem);
}
}
}
}
}
}
return res;
}
public static bool IsNumericType(Type t)
{
if (t == typeof(int) || t == typeof(long) || t == typeof(float) || t == typeof(double) || t == typeof(decimal) || t == typeof(short) || t == typeof(sbyte))
return true;
return false;
}
} // RuntimeHelpers
} // namespace

View file

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Dlrsoft.VBScript.Runtime
{
public static class StringExtensionsClass
{
public static string RemoveNonNumeric(this string s)
{
MatchCollection col = Regex.Matches(s, "[0-9]");
StringBuilder sb = new StringBuilder();
foreach (Match m in col)
sb.Append(m.Value);
return sb.ToString();
}
public static StringBuilder op_Addition(this StringBuilder sb, object o)
{
sb.Append(o);
return sb;
}
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Dlrsoft.VBScript.Runtime
{
public class TraceHelper : ITrace
{
private static TraceSource _ts = new TraceSource("Dlrsoft.VBScript");
//private SymbolDocumentInfo _docInfo;
private string _source;
private int _startLine;
private int _startColumn;
private int _endLine;
private int _endColumn;
#region ITrace Members
//public void TraceDebugInfo(SymbolDocumentInfo docInfo, int startLine, int startColumn, int endLine, int endColumn)
public void TraceDebugInfo(string source, int startLine, int startColumn, int endLine, int endColumn)
{
//_docInfo = docInfo;
_source = source;
_startLine = startLine;
_startColumn = startColumn;
_endLine = endLine;
_endColumn = endColumn;
//_ts.TraceData(TraceEventType.Information, 1, Thread.CurrentThread.ManagedThreadId, docInfo.FileName, startLine, startColumn, endLine, endColumn);
_ts.TraceData(TraceEventType.Information, 1, Thread.CurrentThread.ManagedThreadId, source, startLine, startColumn, endLine, endColumn);
}
public string Source { get { return _source; } }
public int StartLine { get { return _startLine; } }
public int StartColumn { get { return _startColumn; } }
public int EndLine { get { return _endLine; } }
public int EndColumn { get { return _endColumn; } }
#endregion
}
}

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
namespace Dlrsoft.VBScript.Runtime
{
////////////////////////////////////
// TypeModel and TypeModelMetaObject
////////////////////////////////////
// TypeModel wraps System.Runtimetypes. When Sympl code encounters
// a type leaf node in Sympl.Globals and tries to invoke a member, wrapping
// the ReflectionTypes in TypeModels allows member access to get the type's
// members and not ReflectionType's members.
//
public class TypeModel : IDynamicMetaObjectProvider
{
private Type _reflType;
public TypeModel(Type type)
{
_reflType = type;
}
public Type ReflType { get { return _reflType; } }
DynamicMetaObject IDynamicMetaObjectProvider
.GetMetaObject(Expression parameter)
{
return new TypeModelMetaObject(parameter, this);
}
}
}

View file

@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
//using System.Text;
using System.Reflection;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq;
using System.Linq.Expressions;
#endif
using System.Runtime.CompilerServices;
namespace Dlrsoft.VBScript.Runtime
{
public class TypeModelMetaObject : DynamicMetaObject
{
private TypeModel _typeModel;
public TypeModel TypeModel { get { return _typeModel; } }
public Type ReflType { get { return _typeModel.ReflType; } }
// Constructor takes ParameterExpr to reference CallSite, and a TypeModel
// that the new TypeModelMetaObject represents.
//
public TypeModelMetaObject(Expression objParam, TypeModel typeModel)
: base(objParam, BindingRestrictions.Empty, typeModel)
{
_typeModel = typeModel;
}
public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
{
var flags = BindingFlags.IgnoreCase | BindingFlags.Static |
BindingFlags.Public;
// consider BindingFlags.Instance if want to return wrapper for
// inst members that is callable.
var members = ReflType.GetMember(binder.Name, flags);
if (members.Length == 1)
{
return new DynamicMetaObject(
// We always access static members for type model objects, so the
// first argument in MakeMemberAccess should be null.
RuntimeHelpers.EnsureObjectResult(
Expression.MakeMemberAccess(
null,
members[0])),
// Don't need restriction test for name since this
// rule is only used where binder is used, which is
// only used in sites with this binder.Name.
this.Restrictions.Merge(
BindingRestrictions.GetInstanceRestriction(
this.Expression,
this.Value)
)
);
}
else
{
return binder.FallbackGetMember(this);
}
}
// Because we don't ComboBind over several MOs and operations, and no one
// is falling back to this function with MOs that have no values, we
// don't need to check HasValue. If we did check, and HasValue == False,
// then would defer to new InvokeMemberBinder.Defer().
//
public override DynamicMetaObject BindInvokeMember(
InvokeMemberBinder binder, DynamicMetaObject[] args)
{
var flags = BindingFlags.IgnoreCase | BindingFlags.Static |
BindingFlags.Public;
var members = ReflType.GetMember(binder.Name, flags);
if ((members.Length == 1) && (members[0] is PropertyInfo ||
members[0] is FieldInfo))
{
// NEED TO TEST, should check for delegate value too
var mem = members[0];
throw new NotImplementedException();
//return new DynamicMetaObject(
// Expression.Dynamic(
// new SymplInvokeBinder(new CallInfo(args.Length)),
// typeof(object),
// args.Select(a => a.Expression).AddFirst(
// Expression.MakeMemberAccess(this.Expression, mem)));
// Don't test for eventinfos since we do nothing with them now.
}
else
{
// Get MethodInfos with right arg counts.
var mi_mems = members.
Select(m => m as MethodInfo).
Where(m => m is MethodInfo &&
((MethodInfo)m).GetParameters().Length ==
args.Length);
// Get MethodInfos with param types that work for args. This works
// for except for value args that need to pass to reftype params.
// We could detect that to be smarter and then explicitly StrongBox
// the args.
List<MethodInfo> res = new List<MethodInfo>();
foreach (var mem in mi_mems)
{
if (RuntimeHelpers.ParametersMatchArguments(
mem.GetParameters(), args))
{
res.Add(mem);
}
}
// True below means generate an instance restriction on the MO.
// We are only looking at the members defined in this Type instance.
var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(
this, args, true);
if (res.Count == 0)
{
//LC Try to find method that support params
//Limited to the case params is the only argument and it is and object[]
//To bind something like BuiltInFunction.Array
MethodInfo mi = ReflType.GetMethod(binder.Name, new Type[] { typeof(object[]) });
if (mi != null)
{
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(
mi,
Expression.NewArrayInit(typeof(object), args.Select(a => a.Expression))
)
),
restrictions);
}
// Sometimes when binding members on TypeModels the member
// is an intance member since the Type is an instance of Type.
// We fallback to the binder with the Type instance to see if
// it binds. The SymplInvokeMemberBinder does handle this.
var typeMO = RuntimeHelpers.GetRuntimeTypeMoFromModel(this);
var result = binder.FallbackInvokeMember(typeMO, args, null);
return result;
}
// restrictions and conversion must be done consistently.
var callArgs =
RuntimeHelpers.ConvertArguments(
args, res[0].GetParameters());
return new DynamicMetaObject(
RuntimeHelpers.EnsureObjectResult(
Expression.Call(res[0], callArgs)),
restrictions);
// Could hve tried just letting Expr.Call factory do the work,
// but if there is more than one applicable method using just
// assignablefrom, Expr.Call throws. It does not pick a "most
// applicable" method or any method.
}
}
public override DynamicMetaObject BindCreateInstance(
CreateInstanceBinder binder, DynamicMetaObject[] args)
{
var constructors = ReflType.GetConstructors();
var ctors = constructors.
Where(c => c.GetParameters().Length == args.Length);
List<ConstructorInfo> res = new List<ConstructorInfo>();
foreach (var c in ctors)
{
if (RuntimeHelpers.ParametersMatchArguments(c.GetParameters(),
args))
{
res.Add(c);
}
}
if (res.Count == 0)
{
// Binders won't know what to do with TypeModels, so pass the
// RuntimeType they represent. The binder might not be Sympl's.
return binder.FallbackCreateInstance(
RuntimeHelpers.GetRuntimeTypeMoFromModel(this),
args);
}
// For create instance of a TypeModel, we can create a instance
// restriction on the MO, hence the true arg.
var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(
this, args, true);
var ctorArgs =
RuntimeHelpers.ConvertArguments(
args, res[0].GetParameters());
return new DynamicMetaObject(
// Creating an object, so don't need EnsureObjectResult.
Expression.New(res[0], ctorArgs),
restrictions);
}
}//TypeModelMetaObject
}

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting.Runtime;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
namespace Dlrsoft.VBScript.Runtime
{
// This class represents Sympl modules or globals scopes. We derive from
// DynamicObject for an easy IDynamicMetaObjectProvider implementation, and
// just hold onto the DLR internal scope object. Languages typically have
// their own scope so that 1) it can flow around an a dynamic object and 2)
// to dope in any language-specific behaviors, such as case-INsensitivity.
//
public sealed class VBScriptDlrScope : DynamicObject
{
private readonly Scope _scope;
public VBScriptDlrScope(Scope scope)
{
_scope = scope;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
return _scope.TryGetVariable(SymbolTable.StringToCaseInsensitiveId(binder.Name),
out result);
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_scope.SetVariable(SymbolTable.StringToId(binder.Name), value);
return true;
}
}
}

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Dlrsoft.VBScript.Runtime
{
public class VBScriptRuntimeException : Exception
{
private int _number;
private string _source = string.Empty;
private string _helpContext = string.Empty;
private string _helpFile = string.Empty;
public VBScriptRuntimeException()
{
}
public VBScriptRuntimeException(Exception ex)
: base(ex.Message, ex)
{
this._number = 507; //An exception occurred
}
public VBScriptRuntimeException(Exception ex, string source)
: base(source, ex)
{
this._source = source;
}
public VBScriptRuntimeException(int number, string description)
: this(number, description, null, null, null)
{
}
public VBScriptRuntimeException(int number, string description, string source, string helpFile, string helpContext)
: base(description)
{
this._number = number;
this._source = source;
this._helpContext = helpContext;
this._helpFile = helpFile;
}
public int Number { get { return _number; } }
public string Description { get { return base.Message; } }
public string Source { get { return _source; } }
public string HelpContext { get { return _helpContext; } }
public string HelpFile { get { return _helpFile; } }
}
}

View file

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting;
using AspClassic.Scripting.Debugging;
using System.Diagnostics;
namespace Dlrsoft.VBScript.Runtime
{
public class VBScriptTraceCallbackListener : ITraceCallback
{
#region ITraceCallback Members
public void OnTraceEvent(TraceEventKind kind, string name, string sourceFileName, AspClassic.Scripting.SourceSpan sourceSpan, AspClassic.Scripting.Utils.Func<AspClassic.Scripting.IAttributesCollection> scopeCallback, object payload, object customPayload)
{
switch (kind)
{
case TraceEventKind.TracePoint:
case TraceEventKind.FrameEnter:
case TraceEventKind.FrameExit:
Trace.TraceInformation("{4} at {0} Line {1} column {2}-{3}", sourceFileName, sourceSpan.Start.Line, sourceSpan.Start.Column, sourceSpan.End.Column, kind);
if (scopeCallback != null)
{
IAttributesCollection attr = scopeCallback();
if (attr != null)
{
Trace.TraceInformation("Attrs {0}", attr);
}
}
break;
case TraceEventKind.Exception:
case TraceEventKind.ExceptionUnwind:
//Don't know what to do
break;
case TraceEventKind.ThreadExit:
Trace.TraceInformation("Page completed successfully.");
break;
default:
//Do nothing
break;
}
}
#endregion
}
}

View file

@ -0,0 +1,465 @@
using System;
using System.Collections.Generic;
using System.Text;
using VB = AspClassic.Parser;
using AspClassic.Scripting;
using AspClassic.Scripting.Runtime;
//using AspClassic.Scripting.Debugging.CompilerServices;
//using AspClassic.Scripting.Debugging;
using System.Dynamic;
#if USE35
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq;
using System.Linq.Expressions;
#endif
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.IO;
using Dlrsoft.VBScript.Binders;
using Dlrsoft.VBScript.Compiler;
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript
{
public class VBScript
{
public const string ERR_PARAMETER = "err";
public const string TRACE_PARAMETER = "__trace";
private IList<Assembly> _assemblies;
private ExpandoObject _globals = new ExpandoObject();
private Scope _dlrGlobals;
public VBScript(IList<Assembly> assms, Scope dlrGlobals)
{
_assemblies = assms;
_dlrGlobals = dlrGlobals;
AddAssemblyNamesAndTypes();
}
// _addNamespacesAndTypes builds a tree of ExpandoObjects representing
// .NET namespaces, with TypeModel objects at the leaves. Though Sympl is
// case-insensitive, we store the names as they appear in .NET reflection
// in case our globals object or a namespace object gets passed as an IDO
// to another language or library, where they may be looking for names
// case-sensitively using EO's default lookup.
//
public void AddAssemblyNamesAndTypes() {
foreach (var assm in _assemblies) {
foreach (var typ in assm.GetExportedTypes()) {
string[] names = typ.FullName.Split('.');
var table = _globals;
for (int i = 0; i < names.Length - 1; i++) {
string name = names[i].ToLower();
if (DynamicObjectHelpers.HasMember(
(IDynamicMetaObjectProvider)table, name)) {
// Must be Expando since only we have put objs in
// the tables so far.
table = (ExpandoObject)(DynamicObjectHelpers
.GetMember(table, name));
} else {
var tmp = new ExpandoObject();
DynamicObjectHelpers.SetMember(table, name, tmp);
table = tmp;
}
}
DynamicObjectHelpers.SetMember(table, names[names.Length - 1],
new TypeModel(typ));
}
}
}
// ExecuteFile executes the file in a new module scope and stores the
// scope on Globals, using either the provided name, globalVar, or the
// file's base name. This function returns the module scope.
//
public IDynamicMetaObjectProvider ExecuteFile(string filename) {
return ExecuteFile(filename, null);
}
public IDynamicMetaObjectProvider ExecuteFile(string filename,
string globalVar) {
var moduleEO = CreateScope();
ExecuteFileInScope(filename, moduleEO);
globalVar = globalVar ?? Path.GetFileNameWithoutExtension(filename);
DynamicObjectHelpers.SetMember(this._globals, globalVar, moduleEO);
return moduleEO;
}
// ExecuteFileInScope executes the file in the given module scope. This
// does NOT store the module scope on Globals. This function returns
// nothing.
//
public void ExecuteFileInScope(string filename,
IDynamicMetaObjectProvider moduleEO) {
var f = new StreamReader(filename);
// Simple way to convey script rundir for RuntimeHelpes.SymplImport
// to load .sympl files.
DynamicObjectHelpers.SetMember(moduleEO, "__file__",
Path.GetFullPath(filename));
try {
var moduleFun = ParseFileToLambda(filename, f);
var d = moduleFun;
d(this, moduleEO);
} finally {
f.Close();
}
}
internal AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider>
ParseFileToLambda(string filename, TextReader reader) {
var scanner = new VB.Scanner(reader);
var errorTable = new List<VB.SyntaxError>();
var block = new VB.Parser().ParseScriptFile(scanner, errorTable);
if (errorTable.Count > 0)
{
List<VBScriptSyntaxError> errors = new List<VBScriptSyntaxError>();
foreach (VB.SyntaxError error in errorTable)
{
errors.Add(new VBScriptSyntaxError(
filename,
SourceUtil.ConvertSpan(error.Span),
(int)error.Type,
error.Type.ToString())
);
}
throw new VBScriptCompilerException(errors);
}
VBScriptSourceCodeReader sourceReader = reader as VBScriptSourceCodeReader;
ISourceMapper mapper = null;
if (sourceReader != null)
{
mapper = sourceReader.SourceMapper;
}
var scope = new AnalysisScope(
null,
filename,
this,
Expression.Parameter(typeof(VBScript), "vbscriptRuntime"),
Expression.Parameter(typeof(IDynamicMetaObjectProvider), "fileModule"),
mapper);
//Generate function table
List<Expression> body = new List<Expression>();
//Add the built in globals
ParameterExpression err = Expression.Parameter(typeof(ErrObject), ERR_PARAMETER);
scope.Names.Add(ERR_PARAMETER, err);
body.Add(
Expression.Assign(
err,
Expression.New(typeof(ErrObject))
)
);
if (Trace)
{
ParameterExpression trace = Expression.Parameter(typeof(ITrace), TRACE_PARAMETER);
scope.Names.Add(TRACE_PARAMETER, trace);
body.Add(
Expression.Assign(
trace,
Expression.Convert(
Expression.Dynamic(
scope.GetRuntime().GetGetMemberBinder(TRACE_PARAMETER),
typeof(object),
scope.GetModuleExpr()
),
typeof(ITrace)
)
)
);
}
//Put module variables and functions into the scope
VBScriptAnalyzer.AnalyzeFile(block, scope);
//Generate the module level code other than the methods:
if (block.Statements != null)
{
foreach (var s in block.Statements)
{
if (s is VB.MethodDeclaration)
{
//Make sure methods are created first before being executed
body.Insert(0, VBScriptGenerator.GenerateExpr(s, scope));
}
else
{
Expression stmt = VBScriptGenerator.GenerateExpr(s, scope);
if (scope.VariableScope.IsOnErrorResumeNextOn)
{
stmt = VBScriptGenerator.WrapTryCatchExpression(stmt, scope);
}
Expression debugInfo = null;
Expression clearDebugInfo = null;
if (Trace && s is VB.Statement && !(s is VB.BlockStatement))
{
debugInfo = VBScriptGenerator.GenerateDebugInfo(s, scope, out clearDebugInfo);
body.Add(debugInfo);
}
body.Add(stmt);
if (clearDebugInfo != null)
{
body.Add(clearDebugInfo);
}
}
}
}
body.Add(Expression.Constant(null)); //Stop anything from returning
if (scope.Errors.Count > 0)
{
throw new VBScriptCompilerException(scope.Errors);
}
//if (Debug)
//{
// Expression registerRuntimeVariables = VBScriptGenerator.GenerateRuntimeVariablesExpression(scope);
// body.Insert(0, registerRuntimeVariables);
//}
var moduleFun = Expression.Lambda<AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider>>(
Expression.Block(
scope.Names.Values,
body),
scope.RuntimeExpr,
scope.ModuleExpr);
//if (!Debug)
//{
return moduleFun.Compile();
//}
//else
//{
// Expression<Action<VBScript, IDynamicMetaObjectProvider>> lambda = (Expression<Action<VBScript, IDynamicMetaObjectProvider>>)DebugContext.TransformLambda(moduleFun);
// return lambda.Compile();
//}
}
// Execute a single expression parsed from string in the provided module
// scope and returns the resulting value.
//
public void ExecuteExpr(string expr_str,
IDynamicMetaObjectProvider moduleEO) {
var moduleFun = ParseExprToLambda(new StringReader(expr_str));
var d = moduleFun;
d(this, moduleEO);
}
internal AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider>
ParseExprToLambda(TextReader reader) {
var scanner = new VB.Scanner(reader);
var errorTable = new List<VB.SyntaxError>();
var ast = new VB.Parser().ParseScriptFile(scanner, errorTable);
VBScriptSourceCodeReader sourceReader = reader as VBScriptSourceCodeReader;
ISourceMapper mapper = null;
if (sourceReader != null)
{
mapper = sourceReader.SourceMapper;
}
var scope = new AnalysisScope(
null,
"__snippet__",
this,
Expression.Parameter(typeof(VBScript), "vbscriptRuntime"),
Expression.Parameter(typeof(IDynamicMetaObjectProvider), "fileModule"),
mapper
);
List<Expression> body = new List<Expression>();
body.Add(Expression.Convert(VBScriptGenerator.GenerateExpr(ast, scope), typeof(object)));
if (scope.Errors.Count > 0)
{
throw new VBScriptCompilerException(scope.Errors);
}
var moduleFun = Expression.Lambda<AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider>>(
Expression.Block(body),
scope.RuntimeExpr,
scope.ModuleExpr
);
return moduleFun.Compile();
}
public IDynamicMetaObjectProvider Globals { get { return _globals; } }
public IDynamicMetaObjectProvider DlrGlobals { get { return _dlrGlobals; } }
public bool Trace { get; set; }
public static ExpandoObject CreateScope() {
return new ExpandoObject();
}
/////////////////////////
// Canonicalizing Binders
/////////////////////////
// We need to canonicalize binders so that we can share L2 dynamic
// dispatch caching across common call sites. Every call site with the
// same operation and same metadata on their binders should return the
// same rules whenever presented with the same kinds of inputs. The
// DLR saves the L2 cache on the binder instance. If one site somewhere
// produces a rule, another call site performing the same operation with
// the same metadata could get the L2 cached rule rather than computing
// it again. For this to work, we need to place the same binder instance
// on those functionally equivalent call sites.
private Dictionary<string, VBScriptGetMemberBinder> _getMemberBinders =
new Dictionary<string, VBScriptGetMemberBinder>();
public VBScriptGetMemberBinder GetGetMemberBinder (string name) {
lock (_getMemberBinders) {
// Don't lower the name. Sympl is case-preserving in the metadata
// in case some DynamicMetaObject ignores ignoreCase. This makes
// some interop cases work, but the cost is that if a Sympl program
// spells ".foo" and ".Foo" at different sites, they won't share rules.
if (_getMemberBinders.ContainsKey(name))
return _getMemberBinders[name];
var b = new VBScriptGetMemberBinder(name);
_getMemberBinders[name] = b;
return b;
}
}
private Dictionary<string, VBScriptSetMemberBinder> _setMemberBinders =
new Dictionary<string, VBScriptSetMemberBinder>();
public VBScriptSetMemberBinder GetSetMemberBinder (string name) {
lock (_setMemberBinders) {
// Don't lower the name. Sympl is case-preserving in the metadata
// in case some DynamicMetaObject ignores ignoreCase. This makes
// some interop cases work, but the cost is that if a Sympl program
// spells ".foo" and ".Foo" at different sites, they won't share rules.
if (_setMemberBinders.ContainsKey(name))
return _setMemberBinders[name];
var b = new VBScriptSetMemberBinder(name);
_setMemberBinders[name] = b;
return b;
}
}
private Dictionary<CallInfo, VBScriptInvokeBinder> _invokeBinders =
new Dictionary<CallInfo, VBScriptInvokeBinder>();
public VBScriptInvokeBinder GetInvokeBinder (CallInfo info) {
lock (_invokeBinders) {
if (_invokeBinders.ContainsKey(info))
return _invokeBinders[info];
var b = new VBScriptInvokeBinder(info);
_invokeBinders[info] = b;
return b;
}
}
private Dictionary<InvokeMemberBinderKey, VBScriptInvokeMemberBinder>
_invokeMemberBinders =
new Dictionary<InvokeMemberBinderKey, VBScriptInvokeMemberBinder>();
public VBScriptInvokeMemberBinder GetInvokeMemberBinder
(InvokeMemberBinderKey info) {
lock (_invokeMemberBinders) {
if (_invokeMemberBinders.ContainsKey(info))
return _invokeMemberBinders[info];
var b = new VBScriptInvokeMemberBinder(info.Name, info.Info);
_invokeMemberBinders[info] = b;
return b;
}
}
private Dictionary<CallInfo, VBScriptCreateInstanceBinder>
_createInstanceBinders =
new Dictionary<CallInfo, VBScriptCreateInstanceBinder>();
public VBScriptCreateInstanceBinder GetCreateInstanceBinder(CallInfo info) {
lock (_createInstanceBinders) {
if (_createInstanceBinders.ContainsKey(info))
return _createInstanceBinders[info];
var b = new VBScriptCreateInstanceBinder(info);
_createInstanceBinders[info] = b;
return b;
}
}
private Dictionary<CallInfo, VBScriptGetIndexBinder> _getIndexBinders =
new Dictionary<CallInfo, VBScriptGetIndexBinder>();
public VBScriptGetIndexBinder GetGetIndexBinder(CallInfo info) {
lock (_getIndexBinders) {
if (_getIndexBinders.ContainsKey(info))
return _getIndexBinders[info];
var b = new VBScriptGetIndexBinder(info);
_getIndexBinders[info] = b;
return b;
}
}
private Dictionary<CallInfo, VBScriptSetIndexBinder> _setIndexBinders =
new Dictionary<CallInfo, VBScriptSetIndexBinder>();
public VBScriptSetIndexBinder GetSetIndexBinder(CallInfo info) {
lock (_setIndexBinders) {
if (_setIndexBinders.ContainsKey(info))
return _setIndexBinders[info];
var b = new VBScriptSetIndexBinder(info);
_setIndexBinders[info] = b;
return b;
}
}
private Dictionary<ExpressionType, VBScriptBinaryOperationBinder>
_binaryOperationBinders =
new Dictionary<ExpressionType, VBScriptBinaryOperationBinder>();
public VBScriptBinaryOperationBinder GetBinaryOperationBinder
(ExpressionType op) {
lock (_binaryOperationBinders) {
if (_binaryOperationBinders.ContainsKey(op))
return _binaryOperationBinders[op];
var b = new VBScriptBinaryOperationBinder(op);
_binaryOperationBinders[op] = b;
return b;
}
}
private Dictionary<ExpressionType, VBScriptUnaryOperationBinder>
_unaryOperationBinders =
new Dictionary<ExpressionType, VBScriptUnaryOperationBinder>();
public VBScriptUnaryOperationBinder GetUnaryOperationBinder
(ExpressionType op) {
lock (_unaryOperationBinders) {
if (_unaryOperationBinders.ContainsKey(op))
return _unaryOperationBinders[op];
var b = new VBScriptUnaryOperationBinder(op);
_unaryOperationBinders[op] = b;
return b;
}
}
//private DebugContext _debugContext;
//public DebugContext DebugContext
//{
// get
// {
// if (_debugContext == null)
// {
// _debugContext = DebugContext.CreateInstance();
// ITracePipeline pipeLine = TracePipeline.CreateInstance(_debugContext);
// pipeLine.TraceCallback = new VBScriptTraceCallbackListener();
// }
// return _debugContext;
// }
//}
}
}

View file

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using AspClassic.Scripting.Runtime;
using System.Dynamic;
#if USE35
// Needed for type language implementers need to support DLR Hosting, such as
// ScriptCode.
using AspClassic.Scripting.Ast;
using AspClassic.Scripting.Utils;
#else
using System.Linq.Expressions;
#endif
using AspClassic.Scripting;
using Dlrsoft.VBScript.Runtime;
namespace Dlrsoft.VBScript.Hosting
{
class VBScriptCode : ScriptCode
{
//private readonly Expression<Action<VBScript, IDynamicMetaObjectProvider>> _lambda;
private readonly VBScript _vbscript;
private AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider> _compiledLambda;
public VBScriptCode(
VBScript vbscript,
AspClassic.Scripting.Utils.Action<VBScript, IDynamicMetaObjectProvider> lambda,
SourceUnit sourceUnit)
: base(sourceUnit) {
_compiledLambda = lambda;
_vbscript = vbscript;
}
public override object Run() {
return Run(new Scope());
}
public override object Run(Scope scope) {
//if (_compiledLambda == null) {
// _compiledLambda = _lambda.Compile();
//}
//LC Load the system by default
//RuntimeHelpers.VBScriptImport(_vbscript, module, new string[] { "System" }, new string[] { }, new string[] { });
//RuntimeHelpers.VBScriptImport(_vbscript, module, new string[] { "VBScript", "Runtime" }, new string[] { "BuiltInFunctions" }, new string[] { "BuiltIn" });
//if (this.SourceUnit.Kind == SourceCodeKind.File)
//{
// // Simple way to convey script rundir for RuntimeHelpers.SymplImport
// // to load .sympl files relative to the current script file.
// DynamicObjectHelpers.SetMember(module, "__file__",
// Path.GetFullPath(this.SourceUnit.Path));
//}
_compiledLambda(_vbscript, scope);
return null;
}
}
}

View file

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Text;
using AspClassic.Scripting.Runtime;
using System.Dynamic;
#if USE35
// Needed for type language implementers need to support DLR Hosting, such as
// ScriptCode.
using AspClassic.Scripting.Ast;
#else
using System.Linq.Expressions;
#endif
using AspClassic.Scripting;
using Dlrsoft.VBScript.Runtime;
using Dlrsoft.VBScript.Compiler;
using AspClassic.Scripting.Utils;
namespace Dlrsoft.VBScript.Hosting
{
public class VBScriptContext : LanguageContext
{
private readonly VBScript _vbscript;
public VBScriptContext(ScriptDomainManager manager,
IDictionary<string, object> options)
: base(manager) {
// TODO: parse options
// TODO: register event manager.AssemblyLoaded
_vbscript = new VBScript(manager.GetLoadedAssemblyList(), manager.Globals);
if (options.ContainsKey("Trace") && options["Trace"].Equals(true))
{
_vbscript.Trace = true;
}
}
public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
{
using (var reader = sourceUnit.GetReader()) {
try
{
switch (sourceUnit.Kind)
{
case SourceCodeKind.SingleStatement:
case SourceCodeKind.Expression:
case SourceCodeKind.AutoDetect:
case SourceCodeKind.InteractiveCode:
return new VBScriptCode(
_vbscript, _vbscript.ParseExprToLambda(reader),
sourceUnit);
case SourceCodeKind.Statements:
case SourceCodeKind.File:
return new VBScriptCode(
_vbscript,
_vbscript.ParseFileToLambda(sourceUnit.Path, reader),
sourceUnit);
default:
throw Assert.Unreachable;
}
}
catch (VBScriptCompilerException ex)
{
VBScriptSourceCodeReader vbscriptReader = reader as VBScriptSourceCodeReader;
if (vbscriptReader != null)
{
ISourceMapper mapper = vbscriptReader.SourceMapper;
if (mapper != null)
{
foreach (VBScriptSyntaxError error in ex.SyntaxErrors)
{
DocSpan docSpan = mapper.Map(error.Span);
error.FileName = docSpan.Uri;
error.Span = docSpan.Span;
}
}
}
throw ex;
}
catch (Exception e)
{
// Real language implementation would have a specific type
// of exception. Also, they would pass errorSink down into
// the parser and add messages while doing tighter error
// recovery and continuing to parse.
errorSink.Add(sourceUnit, e.Message, SourceSpan.None, 0,
Severity.FatalError);
return null;
}
}
}
}
}

View file

@ -0,0 +1,199 @@
{
"format": 1,
"restore": {
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj": {}
},
"projects": {
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj",
"projectName": "AspClassic.Parser",
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj",
"packagesPath": "C:\\Users\\jelle\\.nuget\\packages\\",
"outputPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\jelle\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.201\\RuntimeIdentifierGraph.json"
}
}
},
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj",
"projectName": "AspClassic.Scripting",
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj",
"packagesPath": "C:\\Users\\jelle\\.nuget\\packages\\",
"outputPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\jelle\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"System.CodeDom": {
"target": "Package",
"version": "[6.0.0, )"
},
"System.Configuration.ConfigurationManager": {
"target": "Package",
"version": "[6.0.0, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.201\\RuntimeIdentifierGraph.json"
}
}
},
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj",
"projectName": "AspClassic.VBScript",
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj",
"packagesPath": "C:\\Users\\jelle\\.nuget\\packages\\",
"outputPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\jelle\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj": {
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj"
},
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj": {
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.201\\RuntimeIdentifierGraph.json"
}
}
}
}
}

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\jelle\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.1.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\jelle\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View file

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

View file

@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("AspClassic.VBScript")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("AspClassic.VBScript")]
[assembly: System.Reflection.AssemblyTitleAttribute("AspClassic.VBScript")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View file

@ -0,0 +1 @@
7e641505bfce80bddc57274cc8b116b933cbe7bf

View file

@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = AspClassic.VBScript
build_property.ProjectDir = C:\Users\jelle\Documents\GitHub\aspclassic-core\AspClassic.VBScript\

View file

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View file

@ -0,0 +1 @@
ce950eb53134231f6b0ca93d8458b7d6b26b45d5

View file

@ -0,0 +1,5 @@
C:\Users\jelle\Documents\GitHub\aspclassic-core\AspClassic.VBScript\obj\Debug\net6.0\AspClassic.VBScript.csproj.AssemblyReference.cache
C:\Users\jelle\Documents\GitHub\aspclassic-core\AspClassic.VBScript\obj\Debug\net6.0\AspClassic.VBScript.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\jelle\Documents\GitHub\aspclassic-core\AspClassic.VBScript\obj\Debug\net6.0\AspClassic.VBScript.AssemblyInfoInputs.cache
C:\Users\jelle\Documents\GitHub\aspclassic-core\AspClassic.VBScript\obj\Debug\net6.0\AspClassic.VBScript.AssemblyInfo.cs
C:\Users\jelle\Documents\GitHub\aspclassic-core\AspClassic.VBScript\obj\Debug\net6.0\AspClassic.VBScript.csproj.CoreCompileInputs.cache

View file

@ -0,0 +1,491 @@
{
"version": 3,
"targets": {
"net6.0": {
"Microsoft.Win32.SystemEvents/6.0.0": {
"type": "package",
"compile": {
"lib/net6.0/Microsoft.Win32.SystemEvents.dll": {}
},
"runtime": {
"lib/net6.0/Microsoft.Win32.SystemEvents.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"System.CodeDom/6.0.0": {
"type": "package",
"compile": {
"lib/net6.0/System.CodeDom.dll": {}
},
"runtime": {
"lib/net6.0/System.CodeDom.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
}
},
"System.Configuration.ConfigurationManager/6.0.0": {
"type": "package",
"dependencies": {
"System.Security.Cryptography.ProtectedData": "6.0.0",
"System.Security.Permissions": "6.0.0"
},
"compile": {
"lib/net6.0/System.Configuration.ConfigurationManager.dll": {}
},
"runtime": {
"lib/net6.0/System.Configuration.ConfigurationManager.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
}
},
"System.Drawing.Common/6.0.0": {
"type": "package",
"dependencies": {
"Microsoft.Win32.SystemEvents": "6.0.0"
},
"compile": {
"lib/net6.0/System.Drawing.Common.dll": {}
},
"runtime": {
"lib/net6.0/System.Drawing.Common.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/unix/lib/net6.0/System.Drawing.Common.dll": {
"assetType": "runtime",
"rid": "unix"
},
"runtimes/win/lib/net6.0/System.Drawing.Common.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"System.Security.AccessControl/6.0.0": {
"type": "package",
"compile": {
"lib/net6.0/System.Security.AccessControl.dll": {}
},
"runtime": {
"lib/net6.0/System.Security.AccessControl.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/win/lib/net6.0/System.Security.AccessControl.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"System.Security.Cryptography.ProtectedData/6.0.0": {
"type": "package",
"compile": {
"lib/net6.0/System.Security.Cryptography.ProtectedData.dll": {}
},
"runtime": {
"lib/net6.0/System.Security.Cryptography.ProtectedData.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
},
"runtimeTargets": {
"runtimes/win/lib/net6.0/System.Security.Cryptography.ProtectedData.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"System.Security.Permissions/6.0.0": {
"type": "package",
"dependencies": {
"System.Security.AccessControl": "6.0.0",
"System.Windows.Extensions": "6.0.0"
},
"compile": {
"lib/net6.0/System.Security.Permissions.dll": {}
},
"runtime": {
"lib/net6.0/System.Security.Permissions.dll": {}
},
"build": {
"buildTransitive/netcoreapp3.1/_._": {}
}
},
"System.Windows.Extensions/6.0.0": {
"type": "package",
"dependencies": {
"System.Drawing.Common": "6.0.0"
},
"compile": {
"lib/net6.0/System.Windows.Extensions.dll": {}
},
"runtime": {
"lib/net6.0/System.Windows.Extensions.dll": {}
},
"runtimeTargets": {
"runtimes/win/lib/net6.0/System.Windows.Extensions.dll": {
"assetType": "runtime",
"rid": "win"
}
}
},
"AspClassic.Parser/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v6.0",
"compile": {
"bin/placeholder/AspClassic.Parser.dll": {}
},
"runtime": {
"bin/placeholder/AspClassic.Parser.dll": {}
}
},
"AspClassic.Scripting/1.0.0": {
"type": "project",
"framework": ".NETCoreApp,Version=v6.0",
"dependencies": {
"System.CodeDom": "6.0.0",
"System.Configuration.ConfigurationManager": "6.0.0"
},
"compile": {
"bin/placeholder/AspClassic.Scripting.dll": {}
},
"runtime": {
"bin/placeholder/AspClassic.Scripting.dll": {}
}
}
}
},
"libraries": {
"Microsoft.Win32.SystemEvents/6.0.0": {
"sha512": "hqTM5628jSsQiv+HGpiq3WKBl2c8v1KZfby2J6Pr7pEPlK9waPdgEO6b8A/+/xn/yZ9ulv8HuqK71ONy2tg67A==",
"type": "package",
"path": "microsoft.win32.systemevents/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/Microsoft.Win32.SystemEvents.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/Microsoft.Win32.SystemEvents.dll",
"lib/net461/Microsoft.Win32.SystemEvents.xml",
"lib/net6.0/Microsoft.Win32.SystemEvents.dll",
"lib/net6.0/Microsoft.Win32.SystemEvents.xml",
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll",
"lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.xml",
"lib/netstandard2.0/Microsoft.Win32.SystemEvents.dll",
"lib/netstandard2.0/Microsoft.Win32.SystemEvents.xml",
"microsoft.win32.systemevents.6.0.0.nupkg.sha512",
"microsoft.win32.systemevents.nuspec",
"runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.dll",
"runtimes/win/lib/net6.0/Microsoft.Win32.SystemEvents.xml",
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.dll",
"runtimes/win/lib/netcoreapp3.1/Microsoft.Win32.SystemEvents.xml",
"useSharedDesignerContext.txt"
]
},
"System.CodeDom/6.0.0": {
"sha512": "CPc6tWO1LAer3IzfZufDBRL+UZQcj5uS207NHALQzP84Vp/z6wF0Aa0YZImOQY8iStY0A2zI/e3ihKNPfUm8XA==",
"type": "package",
"path": "system.codedom/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.CodeDom.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/System.CodeDom.dll",
"lib/net461/System.CodeDom.xml",
"lib/net6.0/System.CodeDom.dll",
"lib/net6.0/System.CodeDom.xml",
"lib/netstandard2.0/System.CodeDom.dll",
"lib/netstandard2.0/System.CodeDom.xml",
"system.codedom.6.0.0.nupkg.sha512",
"system.codedom.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Configuration.ConfigurationManager/6.0.0": {
"sha512": "7T+m0kDSlIPTHIkPMIu6m6tV6qsMqJpvQWW2jIc2qi7sn40qxFo0q+7mEQAhMPXZHMKnWrnv47ntGlM/ejvw3g==",
"type": "package",
"path": "system.configuration.configurationmanager/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Configuration.ConfigurationManager.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/System.Configuration.ConfigurationManager.dll",
"lib/net461/System.Configuration.ConfigurationManager.xml",
"lib/net6.0/System.Configuration.ConfigurationManager.dll",
"lib/net6.0/System.Configuration.ConfigurationManager.xml",
"lib/netstandard2.0/System.Configuration.ConfigurationManager.dll",
"lib/netstandard2.0/System.Configuration.ConfigurationManager.xml",
"runtimes/win/lib/net461/System.Configuration.ConfigurationManager.dll",
"runtimes/win/lib/net461/System.Configuration.ConfigurationManager.xml",
"system.configuration.configurationmanager.6.0.0.nupkg.sha512",
"system.configuration.configurationmanager.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Drawing.Common/6.0.0": {
"sha512": "NfuoKUiP2nUWwKZN6twGqXioIe1zVD0RIj2t976A+czLHr2nY454RwwXs6JU9Htc6mwqL6Dn/nEL3dpVf2jOhg==",
"type": "package",
"path": "system.drawing.common/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Drawing.Common.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net461/System.Drawing.Common.dll",
"lib/net461/System.Drawing.Common.xml",
"lib/net6.0/System.Drawing.Common.dll",
"lib/net6.0/System.Drawing.Common.xml",
"lib/netcoreapp3.1/System.Drawing.Common.dll",
"lib/netcoreapp3.1/System.Drawing.Common.xml",
"lib/netstandard2.0/System.Drawing.Common.dll",
"lib/netstandard2.0/System.Drawing.Common.xml",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"runtimes/unix/lib/net6.0/System.Drawing.Common.dll",
"runtimes/unix/lib/net6.0/System.Drawing.Common.xml",
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.dll",
"runtimes/unix/lib/netcoreapp3.1/System.Drawing.Common.xml",
"runtimes/win/lib/net6.0/System.Drawing.Common.dll",
"runtimes/win/lib/net6.0/System.Drawing.Common.xml",
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.dll",
"runtimes/win/lib/netcoreapp3.1/System.Drawing.Common.xml",
"system.drawing.common.6.0.0.nupkg.sha512",
"system.drawing.common.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Security.AccessControl/6.0.0": {
"sha512": "AUADIc0LIEQe7MzC+I0cl0rAT8RrTAKFHl53yHjEUzNVIaUlhFY11vc2ebiVJzVBuOzun6F7FBA+8KAbGTTedQ==",
"type": "package",
"path": "system.security.accesscontrol/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Security.AccessControl.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/System.Security.AccessControl.dll",
"lib/net461/System.Security.AccessControl.xml",
"lib/net6.0/System.Security.AccessControl.dll",
"lib/net6.0/System.Security.AccessControl.xml",
"lib/netstandard2.0/System.Security.AccessControl.dll",
"lib/netstandard2.0/System.Security.AccessControl.xml",
"runtimes/win/lib/net461/System.Security.AccessControl.dll",
"runtimes/win/lib/net461/System.Security.AccessControl.xml",
"runtimes/win/lib/net6.0/System.Security.AccessControl.dll",
"runtimes/win/lib/net6.0/System.Security.AccessControl.xml",
"runtimes/win/lib/netstandard2.0/System.Security.AccessControl.dll",
"runtimes/win/lib/netstandard2.0/System.Security.AccessControl.xml",
"system.security.accesscontrol.6.0.0.nupkg.sha512",
"system.security.accesscontrol.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Security.Cryptography.ProtectedData/6.0.0": {
"sha512": "rp1gMNEZpvx9vP0JW0oHLxlf8oSiQgtno77Y4PLUBjSiDYoD77Y8uXHr1Ea5XG4/pIKhqAdxZ8v8OTUtqo9PeQ==",
"type": "package",
"path": "system.security.cryptography.protecteddata/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Security.Cryptography.ProtectedData.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net461/System.Security.Cryptography.ProtectedData.dll",
"lib/net461/System.Security.Cryptography.ProtectedData.xml",
"lib/net6.0/System.Security.Cryptography.ProtectedData.dll",
"lib/net6.0/System.Security.Cryptography.ProtectedData.xml",
"lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll",
"lib/netstandard2.0/System.Security.Cryptography.ProtectedData.xml",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"runtimes/win/lib/net461/System.Security.Cryptography.ProtectedData.dll",
"runtimes/win/lib/net461/System.Security.Cryptography.ProtectedData.xml",
"runtimes/win/lib/net6.0/System.Security.Cryptography.ProtectedData.dll",
"runtimes/win/lib/net6.0/System.Security.Cryptography.ProtectedData.xml",
"runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll",
"runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.xml",
"system.security.cryptography.protecteddata.6.0.0.nupkg.sha512",
"system.security.cryptography.protecteddata.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Security.Permissions/6.0.0": {
"sha512": "T/uuc7AklkDoxmcJ7LGkyX1CcSviZuLCa4jg3PekfJ7SU0niF0IVTXwUiNVP9DSpzou2PpxJ+eNY2IfDM90ZCg==",
"type": "package",
"path": "system.security.permissions/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/netcoreapp2.0/System.Security.Permissions.targets",
"buildTransitive/netcoreapp3.1/_._",
"lib/net461/System.Security.Permissions.dll",
"lib/net461/System.Security.Permissions.xml",
"lib/net5.0/System.Security.Permissions.dll",
"lib/net5.0/System.Security.Permissions.xml",
"lib/net6.0/System.Security.Permissions.dll",
"lib/net6.0/System.Security.Permissions.xml",
"lib/netcoreapp3.1/System.Security.Permissions.dll",
"lib/netcoreapp3.1/System.Security.Permissions.xml",
"lib/netstandard2.0/System.Security.Permissions.dll",
"lib/netstandard2.0/System.Security.Permissions.xml",
"runtimes/win/lib/net461/System.Security.Permissions.dll",
"runtimes/win/lib/net461/System.Security.Permissions.xml",
"system.security.permissions.6.0.0.nupkg.sha512",
"system.security.permissions.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Windows.Extensions/6.0.0": {
"sha512": "IXoJOXIqc39AIe+CIR7koBtRGMiCt/LPM3lI+PELtDIy9XdyeSrwXFdWV9dzJ2Awl0paLWUaknLxFQ5HpHZUog==",
"type": "package",
"path": "system.windows.extensions/6.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"THIRD-PARTY-NOTICES.TXT",
"lib/net6.0/System.Windows.Extensions.dll",
"lib/net6.0/System.Windows.Extensions.xml",
"lib/netcoreapp3.1/System.Windows.Extensions.dll",
"lib/netcoreapp3.1/System.Windows.Extensions.xml",
"runtimes/win/lib/net6.0/System.Windows.Extensions.dll",
"runtimes/win/lib/net6.0/System.Windows.Extensions.xml",
"runtimes/win/lib/netcoreapp3.1/System.Windows.Extensions.dll",
"runtimes/win/lib/netcoreapp3.1/System.Windows.Extensions.xml",
"system.windows.extensions.6.0.0.nupkg.sha512",
"system.windows.extensions.nuspec",
"useSharedDesignerContext.txt"
]
},
"AspClassic.Parser/1.0.0": {
"type": "project",
"path": "../AspClassic.Parser/AspClassic.Parser.csproj",
"msbuildProject": "../AspClassic.Parser/AspClassic.Parser.csproj"
},
"AspClassic.Scripting/1.0.0": {
"type": "project",
"path": "../AspClassic.Scripting/AspClassic.Scripting.csproj",
"msbuildProject": "../AspClassic.Scripting/AspClassic.Scripting.csproj"
}
},
"projectFileDependencyGroups": {
"net6.0": [
"AspClassic.Parser >= 1.0.0",
"AspClassic.Scripting >= 1.0.0"
]
},
"packageFolders": {
"C:\\Users\\jelle\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj",
"projectName": "AspClassic.VBScript",
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj",
"packagesPath": "C:\\Users\\jelle\\.nuget\\packages\\",
"outputPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\jelle\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj": {
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Parser\\AspClassic.Parser.csproj"
},
"C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj": {
"projectPath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.Scripting\\AspClassic.Scripting.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.201\\RuntimeIdentifierGraph.json"
}
}
}
}

View file

@ -0,0 +1,17 @@
{
"version": 2,
"dgSpecHash": "WmUHUlamA0N13rIdwI3Gz3wIzU4OxYIKMTYanCQgzEpbz6mAE9Ngz0bbl6sUavJDPqNCPUXAnMqgyxtQjRKzuA==",
"success": true,
"projectFilePath": "C:\\Users\\jelle\\Documents\\GitHub\\aspclassic-core\\AspClassic.VBScript\\AspClassic.VBScript.csproj",
"expectedPackageFiles": [
"C:\\Users\\jelle\\.nuget\\packages\\microsoft.win32.systemevents\\6.0.0\\microsoft.win32.systemevents.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.codedom\\6.0.0\\system.codedom.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.configuration.configurationmanager\\6.0.0\\system.configuration.configurationmanager.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.drawing.common\\6.0.0\\system.drawing.common.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.security.accesscontrol\\6.0.0\\system.security.accesscontrol.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.security.cryptography.protecteddata\\6.0.0\\system.security.cryptography.protecteddata.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.security.permissions\\6.0.0\\system.security.permissions.6.0.0.nupkg.sha512",
"C:\\Users\\jelle\\.nuget\\packages\\system.windows.extensions\\6.0.0\\system.windows.extensions.6.0.0.nupkg.sha512"
],
"logs": []
}