本文整理汇总了C#中Mono.CSharp.Cast.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# Cast.Resolve方法的具体用法?C# Cast.Resolve怎么用?C# Cast.Resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.Cast
的用法示例。
在下文中一共展示了Cast.Resolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckComImport
//
// Checks whether the type is an interface that has the
// [ComImport, CoClass] attributes and must be treated
// specially
//
public Expression CheckComImport (ResolveContext ec)
{
if (!type.IsInterface)
return null;
//
// Turn the call into:
// (the-interface-stated) (new class-referenced-in-coclassattribute ())
//
Type real_class = AttributeTester.GetCoClassAttribute (type);
if (real_class == null)
return null;
New proxy = new New (new TypeExpression (real_class, loc), Arguments, loc);
Cast cast = new Cast (new TypeExpression (type, loc), proxy, loc);
return cast.Resolve (ec);
}
示例2: Reduce
// <summary>
// This routine will attempt to simplify the unary expression when the
// argument is a constant. The result is returned in `result' and the
// function returns true or false depending on whether a reduction
// was performed or not
// </summary>
bool Reduce (EmitContext ec, Constant e, out Expression result)
{
Type expr_type = e.Type;
switch (Oper){
case Operator.UnaryPlus:
result = e;
return true;
case Operator.UnaryNegation:
result = TryReduceNegative (e);
return true;
case Operator.LogicalNot:
if (expr_type != TypeManager.bool_type) {
result = null;
Error23 (expr_type);
return false;
}
BoolConstant b = (BoolConstant) e;
result = new BoolConstant (!(b.Value));
return true;
case Operator.OnesComplement:
if (!((expr_type == TypeManager.int32_type) ||
(expr_type == TypeManager.uint32_type) ||
(expr_type == TypeManager.int64_type) ||
(expr_type == TypeManager.uint64_type) ||
(expr_type.IsSubclassOf (TypeManager.enum_type)))){
result = null;
if (ImplicitConversionExists (ec, e, TypeManager.int32_type)){
result = new Cast (new TypeExpr (TypeManager.int32_type, loc), e, loc);
result = result.Resolve (ec);
} else if (ImplicitConversionExists (ec, e, TypeManager.uint32_type)){
result = new Cast (new TypeExpr (TypeManager.uint32_type, loc), e, loc);
result = result.Resolve (ec);
} else if (ImplicitConversionExists (ec, e, TypeManager.int64_type)){
result = new Cast (new TypeExpr (TypeManager.int64_type, loc), e, loc);
result = result.Resolve (ec);
} else if (ImplicitConversionExists (ec, e, TypeManager.uint64_type)){
result = new Cast (new TypeExpr (TypeManager.uint64_type, loc), e, loc);
result = result.Resolve (ec);
}
if (result == null || !(result is Constant)){
result = null;
Error23 (expr_type);
return false;
}
expr_type = result.Type;
e = (Constant) result;
}
if (e is EnumConstant){
EnumConstant enum_constant = (EnumConstant) e;
Expression reduced;
if (Reduce (ec, enum_constant.Child, out reduced)){
result = new EnumConstant ((Constant) reduced, enum_constant.Type);
return true;
} else {
result = null;
return false;
}
}
if (expr_type == TypeManager.int32_type){
result = new IntConstant (~ ((IntConstant) e).Value);
} else if (expr_type == TypeManager.uint32_type){
result = new UIntConstant (~ ((UIntConstant) e).Value);
} else if (expr_type == TypeManager.int64_type){
result = new LongConstant (~ ((LongConstant) e).Value);
} else if (expr_type == TypeManager.uint64_type){
result = new ULongConstant (~ ((ULongConstant) e).Value);
} else {
result = null;
Error23 (expr_type);
return false;
}
return true;
case Operator.AddressOf:
result = this;
return false;
case Operator.Indirection:
result = this;
return false;
}
throw new Exception ("Can not constant fold: " + Oper.ToString());
}