本文整理匯總了C#中Mono.CSharp.Conditional.Resolve方法的典型用法代碼示例。如果您正苦於以下問題:C# Conditional.Resolve方法的具體用法?C# Conditional.Resolve怎麽用?C# Conditional.Resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mono.CSharp.Conditional
的用法示例。
在下文中一共展示了Conditional.Resolve方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ResolveInitializer
protected override Expression ResolveInitializer (BlockContext bc, LocalVariable li, Expression initializer)
{
if (!Variable.Type.IsPointer && li == Variable) {
bc.Report.Error (209, TypeExpression.Location,
"The type of locals declared in a fixed statement must be a pointer type");
return null;
}
//
// The rules for the possible declarators are pretty wise,
// but the production on the grammar is more concise.
//
// So we have to enforce these rules here.
//
// We do not resolve before doing the case 1 test,
// because the grammar is explicit in that the token &
// is present, so we need to test for this particular case.
//
if (initializer is Cast) {
bc.Report.Error (254, initializer.Location, "The right hand side of a fixed statement assignment may not be a cast expression");
return null;
}
initializer = initializer.Resolve (bc);
if (initializer == null)
return null;
//
// Case 1: Array
//
if (initializer.Type.IsArray) {
TypeSpec array_type = TypeManager.GetElementType (initializer.Type);
//
// Provided that array_type is unmanaged,
//
if (!TypeManager.VerifyUnmanaged (bc.Compiler, array_type, loc))
return null;
//
// and T* is implicitly convertible to the
// pointer type given in the fixed statement.
//
ArrayPtr array_ptr = new ArrayPtr (initializer, array_type, loc);
Expression converted = Convert.ImplicitConversionRequired (
bc, array_ptr, li.Type, loc);
if (converted == null)
return null;
//
// fixed (T* e_ptr = (e == null || e.Length == 0) ? null : converted [0])
//
converted = new Conditional (new BooleanExpression (new Binary (Binary.Operator.LogicalOr,
new Binary (Binary.Operator.Equality, initializer, new NullLiteral (loc), loc),
new Binary (Binary.Operator.Equality, new MemberAccess (initializer, "Length"), new IntConstant (0, loc), loc), loc)),
new NullPointer (loc),
converted, loc);
converted = converted.Resolve (bc);
return new ExpressionEmitter (converted, li);
}
//
// Case 2: string
//
if (initializer.Type == TypeManager.string_type) {
return new StringEmitter (initializer, li, loc).Resolve (bc);
}
// Case 3: fixed buffer
if (initializer is FixedBufferPtr) {
return new ExpressionEmitter (initializer, li);
}
//
// Case 4: & object.
//
bool already_fixed = true;
Unary u = initializer as Unary;
if (u != null && u.Oper == Unary.Operator.AddressOf) {
IVariableReference vr = u.Expr as IVariableReference;
if (vr == null || !vr.IsFixed) {
already_fixed = false;
}
}
if (already_fixed) {
bc.Report.Error (213, loc, "You cannot use the fixed statement to take the address of an already fixed expression");
}
initializer = Convert.ImplicitConversionRequired (bc, initializer, li.Type, loc);
return new ExpressionEmitter (initializer, li);
}
示例2: Resolve
public override bool Resolve (BlockContext ec)
{
if (!ec.IsUnsafe){
Expression.UnsafeError (ec, loc);
return false;
}
TypeExpr texpr = type.ResolveAsContextualType (ec, false);
if (texpr == null) {
if (type is VarExpr)
ec.Report.Error (821, type.Location, "A fixed statement cannot use an implicitly typed local variable");
return false;
}
expr_type = texpr.Type;
data = new Emitter [declarators.Count];
if (!expr_type.IsPointer){
ec.Report.Error (209, loc, "The type of locals declared in a fixed statement must be a pointer type");
return false;
}
int i = 0;
foreach (var p in declarators){
LocalInfo vi = p.Key;
Expression e = p.Value;
vi.VariableInfo.SetAssigned (ec);
vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
//
// The rules for the possible declarators are pretty wise,
// but the production on the grammar is more concise.
//
// So we have to enforce these rules here.
//
// We do not resolve before doing the case 1 test,
// because the grammar is explicit in that the token &
// is present, so we need to test for this particular case.
//
if (e is Cast){
ec.Report.Error (254, loc, "The right hand side of a fixed statement assignment may not be a cast expression");
return false;
}
using (ec.Set (ResolveContext.Options.FixedInitializerScope)) {
e = e.Resolve (ec);
}
if (e == null)
return false;
//
// Case 2: Array
//
if (e.Type.IsArray){
TypeSpec array_type = TypeManager.GetElementType (e.Type);
//
// Provided that array_type is unmanaged,
//
if (!TypeManager.VerifyUnmanaged (ec.Compiler, array_type, loc))
return false;
//
// and T* is implicitly convertible to the
// pointer type given in the fixed statement.
//
ArrayPtr array_ptr = new ArrayPtr (e, array_type, loc);
Expression converted = Convert.ImplicitConversionRequired (
ec, array_ptr, vi.VariableType, loc);
if (converted == null)
return false;
//
// fixed (T* e_ptr = (e == null || e.Length == 0) ? null : converted [0])
//
converted = new Conditional (new BooleanExpression (new Binary (Binary.Operator.LogicalOr,
new Binary (Binary.Operator.Equality, e, new NullLiteral (loc), loc),
new Binary (Binary.Operator.Equality, new MemberAccess (e, "Length"), new IntConstant (0, loc), loc), loc)),
new NullPointer (loc),
converted, loc);
converted = converted.Resolve (ec);
data [i] = new ExpressionEmitter (converted, vi);
i++;
continue;
}
//
// Case 3: string
//
if (e.Type == TypeManager.string_type){
data [i] = new StringEmitter (e, vi, loc).Resolve (ec);
//.........這裏部分代碼省略.........