本文整理汇总了C#中NodeBase.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# NodeBase.Resolve方法的具体用法?C# NodeBase.Resolve怎么用?C# NodeBase.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeBase
的用法示例。
在下文中一共展示了NodeBase.Resolve方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: resolveGetMember
/// <summary>
/// Resolves the method if the expression was a member getter (obj.field or type::field).
/// </summary>
private void resolveGetMember(Context ctx, GetMemberNode node)
{
_InvocationSource = node.Expression;
var type = _InvocationSource != null
? _InvocationSource.Resolve(ctx)
: ctx.ResolveType(node.StaticType);
checkTypeInSafeMode(ctx, type);
if (node.TypeHints != null && node.TypeHints.Count > 0)
_TypeHints = node.TypeHints.Select(x => ctx.ResolveType(x, true)).ToArray();
try
{
// resolve a normal method
try
{
_Method = ctx.ResolveMethod(
type,
node.MemberName,
_ArgTypes,
_TypeHints,
(idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
);
if (_Method.IsStatic)
_InvocationSource = null;
return;
}
catch (KeyNotFoundException)
{
if (_InvocationSource == null)
throw;
}
// resolve a callable field
try
{
ctx.ResolveField(type, node.MemberName);
resolveExpression(ctx, node);
return;
}
catch (KeyNotFoundException) { }
// resolve a callable property
try
{
ctx.ResolveProperty(type, node.MemberName);
resolveExpression(ctx, node);
return;
}
catch (KeyNotFoundException) { }
Arguments = (Arguments[0] is UnitNode)
? new List<NodeBase> {_InvocationSource}
: new[] {_InvocationSource}.Union(Arguments).ToList();
var oldArgTypes = _ArgTypes;
_ArgTypes = Arguments.Select(a => a.Resolve(ctx)).ToArray();
_InvocationSource = null;
try
{
// resolve a local function that is implicitly used as an extension method
_Method = ctx.ResolveMethod(
ctx.MainType.TypeInfo,
node.MemberName,
_ArgTypes,
resolver: (idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
);
return;
}
catch (KeyNotFoundException) { }
// resolve a declared extension method
// most time-consuming operation, therefore is last checked
try
{
if(!ctx.Options.AllowExtensionMethods)
throw new KeyNotFoundException();
_Method = ctx.ResolveExtensionMethod(
type,
node.MemberName,
oldArgTypes,
_TypeHints,
(idx, types) => ctx.ResolveLambda(Arguments[idx] as LambdaNode, types)
);
}
catch (KeyNotFoundException)
{
var msg = node.StaticType != null
? CompilerMessages.TypeStaticMethodNotFound
: CompilerMessages.TypeMethodNotFound;
//.........这里部分代码省略.........
示例2: resolveExpression
/// <summary>
/// Resolves a method from the expression, considering it an instance of a delegate type.
/// </summary>
private void resolveExpression(Context ctx, NodeBase node)
{
var exprType = node.Resolve(ctx);
if (!exprType.IsCallableType())
error(CompilerMessages.TypeNotCallable, exprType);
try
{
// argtypes are required for partial application
_Method = ctx.ResolveMethod(exprType, "Invoke", _ArgTypes);
}
catch (KeyNotFoundException)
{
// delegate argument types are mismatched:
// infer whatever method there is and detect actual error
_Method = ctx.ResolveMethod(exprType, "Invoke");
var argTypes = _Method.ArgumentTypes;
if (argTypes.Length != _ArgTypes.Length)
error(CompilerMessages.DelegateArgumentsCountMismatch, exprType, argTypes.Length, _ArgTypes.Length);
for (var idx = 0; idx < argTypes.Length; idx++)
{
var fromType = _ArgTypes[idx];
var toType = argTypes[idx];
if (!toType.IsExtendablyAssignableFrom(fromType))
error(Arguments[idx], CompilerMessages.ArgumentTypeMismatch, fromType, toType);
}
}
_InvocationSource = node;
}
示例3: emitNullableComparison
/// <summary>
/// Emits code for comparing a nullable
/// </summary>
private void emitNullableComparison(Context ctx, NodeBase nullValue, NodeBase otherValue)
{
var gen = ctx.CurrentMethod.Generator;
var nullType = nullValue.Resolve(ctx);
var otherType = otherValue.Resolve(ctx);
var otherNull = otherType.IsNullableType();
var getValOrDefault = nullType.GetMethod("GetValueOrDefault", Type.EmptyTypes);
var hasValueGetter = nullType.GetProperty("HasValue").GetGetMethod();
var falseLabel = gen.DefineLabel();
var endLabel = gen.DefineLabel();
Local nullVar, otherVar = null;
nullVar = ctx.Scope.DeclareImplicit(ctx, nullType, true);
if (otherNull)
otherVar = ctx.Scope.DeclareImplicit(ctx, otherType, true);
// $tmp = nullValue
nullValue.Emit(ctx, true);
gen.EmitSaveLocal(nullVar.LocalBuilder);
if (otherNull)
{
// $tmp2 = otherValue
otherValue.Emit(ctx, true);
gen.EmitSaveLocal(otherVar.LocalBuilder);
}
// $tmp == $tmp2
gen.EmitLoadLocal(nullVar.LocalBuilder, true);
gen.EmitCall(getValOrDefault);
if (otherNull)
{
gen.EmitLoadLocal(otherVar.LocalBuilder, true);
gen.EmitCall(getValOrDefault);
}
else
{
otherValue.Emit(ctx, true);
}
gen.EmitBranchNotEquals(falseLabel);
// otherwise, compare HasValues
gen.EmitLoadLocal(nullVar.LocalBuilder, true);
gen.EmitCall(hasValueGetter);
if (otherNull)
{
gen.EmitLoadLocal(otherVar.LocalBuilder, true);
gen.EmitCall(hasValueGetter);
gen.EmitCompareEqual();
}
if(Kind == ComparisonOperatorKind.NotEquals)
emitInversion(gen);
gen.EmitJump(endLabel);
gen.MarkLabel(falseLabel);
gen.EmitConstant(false);
gen.MarkLabel(endLabel);
}
示例4: emitBranch
private void emitBranch(Context ctx, NodeBase branch, bool mustReturn)
{
var desiredType = Resolve(ctx);
mustReturn &= !desiredType.IsVoid();
var branchType = branch.Resolve(ctx, mustReturn);
if (!branchType.IsVoid() && !desiredType.IsVoid())
branch = Expr.Cast(branch, desiredType);
branch.Emit(ctx, mustReturn);
}
示例5: emitHasValueCheck
/// <summary>
/// Checks if the nullable expression is null.
/// </summary>
private void emitHasValueCheck(Context ctx, NodeBase nullValue)
{
var gen = ctx.CurrentMethod.Generator;
var nullType = nullValue.Resolve(ctx);
var nullVar = ctx.Scope.DeclareImplicit(ctx, nullType, true);
var hasValueGetter = nullType.GetProperty("HasValue").GetGetMethod();
nullValue.Emit(ctx, true);
gen.EmitSaveLocal(nullVar.LocalBuilder);
gen.EmitLoadLocal(nullVar.LocalBuilder, true);
gen.EmitCall(hasValueGetter);
// sic! get_HasValue == true when value != null
if(Kind == ComparisonOperatorKind.Equals)
emitInversion(gen);
}