本文整理汇总了C#中Mono.CSharp.Conditional类的典型用法代码示例。如果您正苦于以下问题:C# Conditional类的具体用法?C# Conditional怎么用?C# Conditional使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Conditional类属于Mono.CSharp命名空间,在下文中一共展示了Conditional类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoDefineMembers
protected override bool DoDefineMembers ()
{
if (!base.DoDefineMembers ())
return false;
Location loc = Location;
var equals_parameters = ParametersCompiled.CreateFullyResolved (
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), Compiler.BuiltinTypes.Object);
Method equals = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
equals_parameters, null);
equals_parameters[0].Resolve (equals, 0);
Method tostring = new Method (this, new TypeExpression (Compiler.BuiltinTypes.String, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc);
TypeExpr current_type;
if (CurrentTypeParameters != null) {
var targs = new TypeArguments ();
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location));
}
current_type = new GenericTypeExpr (Definition, targs, loc);
} else {
current_type = new TypeExpression (Definition, loc);
}
var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc);
equals_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_other.Type, loc), li_other));
var other_variable = new LocalVariableReference (li_other, loc);
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc);
Expression rs_equals = null;
Expression string_concat = new StringConstant (Compiler.BuiltinTypes, "{", loc);
Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc);
for (int i = 0; i < parameters.Count; ++i) {
var p = parameters [i];
var f = (Field) Members [i * 2];
MemberAccess equality_comparer = new MemberAccess (new MemberAccess (
system_collections_generic, "EqualityComparer",
new TypeArguments (new SimpleName (CurrentTypeParameters [i].Name, loc)), loc),
"Default", loc);
Arguments arguments_equal = new Arguments (2);
arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name)));
Expression field_equal = new Invocation (new MemberAccess (equality_comparer,
"Equals", loc), arguments_equal);
Arguments arguments_hashcode = new Arguments (1);
arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer,
"GetHashCode", loc), arguments_hashcode);
IntConstant FNV_prime = new IntConstant (Compiler.BuiltinTypes, 16777619, loc);
rs_hashcode = new Binary (Binary.Operator.Multiply,
new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode),
FNV_prime);
Expression field_to_string = new Conditional (new BooleanExpression (new Binary (Binary.Operator.Inequality,
new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc))),
new Invocation (new MemberAccess (
new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
new StringConstant (Compiler.BuiltinTypes, string.Empty, loc), loc);
if (rs_equals == null) {
rs_equals = field_equal;
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new Binary (Binary.Operator.Addition,
new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc),
field_to_string));
continue;
}
//
// Implementation of ToString () body using string concatenation
//
string_concat = new Binary (Binary.Operator.Addition,
new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc)),
field_to_string);
rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
}
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
//.........这里部分代码省略.........
示例2: Emit
public override void Emit (EmitContext ec)
{
var rc = new ResolveContext (ec.MemberContext);
var expr = new Conditional (new BooleanExpression (condition), invoke, assign, loc).Resolve (rc);
expr.Emit (ec);
}
示例3: Visit
public override object Visit (Conditional conditionalExpression)
{
var result = new ConditionalExpression ();
result.AddChild ((INode)conditionalExpression.Expr.Accept (this), ConditionalExpression.Roles.Condition);
var location = LocationsBag.GetLocations (conditionalExpression);
result.AddChild (new CSharpTokenNode (Convert (conditionalExpression.Location), 1), ConditionalExpression.Roles.QuestionMark);
result.AddChild ((INode)conditionalExpression.TrueExpr.Accept (this), ConditionalExpression.FalseExpressionRole);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ConditionalExpression.Roles.Colon);
result.AddChild ((INode)conditionalExpression.FalseExpr.Accept (this), ConditionalExpression.FalseExpressionRole);
return result;
}
示例4: case_634
void case_634()
#line 4468 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], null, GetLocation (yyVals[-3+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
示例5: case_635
void case_635()
#line 4475 "cs-parser.jay"
{
Error_SyntaxError (Token.CLOSE_BRACE);
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], null, GetLocation (yyVals[-3+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
lexer.putback ('}');
}
示例6: Visit
public virtual object Visit (Conditional conditionalExpression)
{
return null;
}
示例7: case_632
void case_632()
#line 4457 "cs-parser.jay"
{
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
示例8: 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);
//.........这里部分代码省略.........
示例9: 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);
}
示例10: case_589
void case_589()
#line 4121 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-3+yyTop]), (Expression) yyVals[-1+yyTop], null, GetLocation (yyVals[-2+yyTop]));
}
示例11: yyparse
//.........这里部分代码省略.........
case 588:
#line 3971 "cs-parser.jay"
{
yyVal = new Binary (Binary.Operator.BitwiseOr,
(Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 590:
#line 3980 "cs-parser.jay"
{
yyVal = new Binary (Binary.Operator.LogicalAnd,
(Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 592:
#line 3989 "cs-parser.jay"
{
yyVal = new Binary (Binary.Operator.LogicalOr,
(Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 594:
#line 3998 "cs-parser.jay"
{
if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation (yyVals[-1+yyTop]), "null coalescing operator");
yyVal = new Nullable.NullCoalescingOperator ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 596:
#line 4009 "cs-parser.jay"
{
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop]);
}
break;
case 597:
#line 4016 "cs-parser.jay"
{
yyVal = new SimpleAssign ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop]);
}
break;
case 598:
#line 4020 "cs-parser.jay"
{
yyVal = new CompoundAssign (
Binary.Operator.Multiply, (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop]);
}
break;
case 599:
#line 4025 "cs-parser.jay"
{
yyVal = new CompoundAssign (
Binary.Operator.Division, (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop]);
}
break;
case 600:
#line 4030 "cs-parser.jay"
{
yyVal = new CompoundAssign (
Binary.Operator.Modulus, (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop]);
}
break;
case 601:
#line 4035 "cs-parser.jay"
{
示例12: DefineOverrides
void DefineOverrides ()
{
Location loc = Location;
Method equals = new Method (this, null, TypeManager.system_boolean_expr,
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
Mono.CSharp.ParametersCompiled.CreateFullyResolved (new Parameter (null, "obj", 0, null, loc), TypeManager.object_type), null);
Method tostring = new Method (this, null, TypeManager.system_string_expr,
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.Parameters, loc);
TypeExpr current_type;
if (IsGeneric)
current_type = new GenericTypeExpr (this, loc);
else
current_type = new TypeExpression (TypeBuilder, loc);
equals_block.AddVariable (current_type, "other", loc);
LocalVariableReference other_variable = new LocalVariableReference (equals_block, "other", loc);
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc);
Expression rs_equals = null;
Expression string_concat = new StringConstant ("{", loc);
Expression rs_hashcode = new IntConstant (-2128831035, loc);
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
Field f = (Field) Fields [i];
MemberAccess equality_comparer = new MemberAccess (new MemberAccess (
system_collections_generic, "EqualityComparer",
new TypeArguments (new SimpleName (TypeParameters [i].Name, loc)), loc),
"Default", loc);
Arguments arguments_equal = new Arguments (2);
arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name)));
Expression field_equal = new Invocation (new MemberAccess (equality_comparer,
"Equals", loc), arguments_equal);
Arguments arguments_hashcode = new Arguments (1);
arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer,
"GetHashCode", loc), arguments_hashcode);
IntConstant FNV_prime = new IntConstant (16777619, loc);
rs_hashcode = new Binary (Binary.Operator.Multiply,
new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode),
FNV_prime);
Expression field_to_string = new Conditional (new Binary (Binary.Operator.Inequality,
new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc)),
new Invocation (new MemberAccess (
new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
new StringConstant (string.Empty, loc));
if (rs_equals == null) {
rs_equals = field_equal;
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new Binary (Binary.Operator.Addition,
new StringConstant (" " + p.Name + " = ", loc),
field_to_string));
continue;
}
//
// Implementation of ToString () body using string concatenation
//
string_concat = new Binary (Binary.Operator.Addition,
new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (", " + p.Name + " = ", loc)),
field_to_string);
rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
}
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (" }", loc));
//
// Equals (object obj) override
//
LocalVariableReference other_variable_assign = new LocalVariableReference (equals_block, "other", loc);
equals_block.AddStatement (new StatementExpression (
new SimpleAssign (other_variable_assign,
new As (equals_block.GetParameterReference ("obj", loc),
current_type, loc), loc)));
Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc));
if (rs_equals != null)
equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals);
equals_block.AddStatement (new Return (equals_test, loc));
//.........这里部分代码省略.........
示例13: case_592
void case_592()
{
Error_SyntaxError (yyToken);
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-3+yyTop]), (Expression) yyVals[-1+yyTop], null, GetLocation (yyVals[-2+yyTop]));
}
示例14: case_591
void case_591()
{
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
示例15: yyparse
//.........这里部分代码省略.........
case 606:
#line 4325 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
yyVal = new Binary (Binary.Operator.BitwiseOr,
(Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 608:
#line 4334 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
yyVal = new Binary (Binary.Operator.LogicalAnd,
(Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 610:
#line 4343 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
yyVal = new Binary (Binary.Operator.LogicalOr,
(Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 612:
#line 4352 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
if (lang_version < LanguageVersion.ISO_2)
FeatureIsNotAvailable (GetLocation (yyVals[-1+yyTop]), "null coalescing operator");
yyVal = new Nullable.NullCoalescingOperator ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;
case 614:
#line 4363 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
yyVal = new Conditional (new BooleanExpression ((Expression) yyVals[-4+yyTop]), (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
break;
case 615:
#line 4371 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
var potentialRolePlayer = yyVals[0+yyTop] as Expression;
var memberExpression = yyVals[-2+yyTop] as MemberAccess;
var simpleNameForRole = memberExpression != null ? memberExpression.LeftExpression as SimpleName : yyVals[-2+yyTop] as SimpleName;
if(simpleNameForRole != null){
var role = FindField(simpleNameForRole.Name, GetLocation(yyVals[-2+yyTop]));
var isRole = role != null && role.IsRole;
if(current_method as Constructor != null){
/*might be assigning to a role*/
yyVal = new RoleAssign ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
} else if(isRole) {
report.Error (10000, GetLocation(potentialRolePlayer), "Roles can only be assigned to players in constructor");
} else{
yyVal = new SimpleAssign ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
} else {
yyVal = new SimpleAssign ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
}
break;
case 616:
#line 4391 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
yyVal = new CompoundAssign (
Binary.Operator.Multiply, (Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
}
break;