本文整理汇总了C#中Mono.CSharp.IntConstant类的典型用法代码示例。如果您正苦于以下问题:C# IntConstant类的具体用法?C# IntConstant怎么用?C# IntConstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntConstant类属于Mono.CSharp命名空间,在下文中一共展示了IntConstant类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
//.........这里部分代码省略.........
开发者ID:rabink,项目名称:mono,代码行数:101,代码来源:anonymous.cs
示例2: DoResolve
protected override Expression DoResolve (ResolveContext ec)
{
Child = new IntConstant (ec.BuiltinTypes, (int) (flags | statement.flags), statement.loc);
type = ec.Module.PredefinedTypes.BinderFlags.Resolve ();
eclass = Child.eclass;
return this;
}
开发者ID:caomw,项目名称:mono,代码行数:8,代码来源:dynamic.cs
示例3: DoResolve
protected override Expression DoResolve(ResolveContext ec)
{
Child = new IntConstant ((int) (flags | statement.flags), statement.loc).Resolve (ec);
type = TypeManager.binder_flags;
eclass = Child.eclass;
return this;
}
开发者ID:speier,项目名称:shake,代码行数:8,代码来源:dynamic.cs
示例4: DoEmit
protected override void DoEmit (EmitContext ec)
{
copy.EmitAssign (ec, for_each.expr);
int rank = length_exprs.Length;
Label[] test = new Label [rank];
Label[] loop = new Label [rank];
for (int i = 0; i < rank; i++) {
test [i] = ec.DefineLabel ();
loop [i] = ec.DefineLabel ();
if (lengths != null)
lengths [i].EmitAssign (ec, length_exprs [i]);
}
IntConstant zero = new IntConstant (0, loc);
for (int i = 0; i < rank; i++) {
variables [i].EmitAssign (ec, zero);
ec.Emit (OpCodes.Br, test [i]);
ec.MarkLabel (loop [i]);
}
variable.local_info.CreateBuilder (ec);
variable.EmitAssign (ec, conv, false, false);
statement.Emit (ec);
ec.MarkLabel (ec.LoopBegin);
for (int i = rank - 1; i >= 0; i--){
counter [i].Emit (ec);
ec.MarkLabel (test [i]);
variables [i].Emit (ec);
if (lengths != null)
lengths [i].Emit (ec);
else
length_exprs [i].Emit (ec);
ec.Emit (OpCodes.Blt, loop [i]);
}
ec.MarkLabel (ec.LoopEnd);
}
开发者ID:alisci01,项目名称:mono,代码行数:47,代码来源:statement.cs
示例5: BinaryFold
//.........这里部分代码省略.........
case Binary.Operator.Equality:
case Binary.Operator.Inequality:
case Binary.Operator.LessThan:
case Binary.Operator.GreaterThan:
case Binary.Operator.LessThanOrEqual:
case Binary.Operator.GreaterThanOrEqual:
return BinaryFold(ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
}
return null;
}
switch (oper){
case Binary.Operator.BitwiseOr:
//
// bool? operator &(bool? x, bool? y);
//
if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
(rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
var b = new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
// false | null => null
// null | false => null
if ((right is NullLiteral && left.IsDefaultValue) || (left is NullLiteral && right.IsDefaultValue))
return Nullable.LiftedNull.CreateFromExpression (ec, b);
// true | null => true
// null | true => true
return ReducedExpression.Create (new BoolConstant (ec.BuiltinTypes, true, loc), b);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null;
if (left is IntConstant){
int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
return new IntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is UIntConstant){
uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
return new UIntConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is LongConstant){
long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
return new LongConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is ULongConstant){
ulong res = ((ULongConstant)left).Value |
((ULongConstant)right).Value;
return new ULongConstant (ec.BuiltinTypes, res, left.Location);
}
break;
case Binary.Operator.BitwiseAnd:
//
// bool? operator &(bool? x, bool? y);
//
if ((lt.BuiltinType == BuiltinTypeSpec.Type.Bool && right is NullLiteral) ||
(rt.BuiltinType == BuiltinTypeSpec.Type.Bool && left is NullLiteral)) {
var b = new Nullable.LiftedBinaryOperator (oper, left, right).Resolve (ec);
// false & null => false
// null & false => false
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:67,代码来源:cfold.cs
示例6: UpdateIndices
public void UpdateIndices ()
{
int i = 0;
for (ArrayList probe = initializers; probe != null;) {
if (probe.Count > 0 && probe [0] is ArrayList) {
Expression e = new IntConstant (probe.Count, Location.Null);
arguments.Add (e);
bounds [i++] = probe.Count;
probe = (ArrayList) probe [0];
} else {
Expression e = new IntConstant (probe.Count, Location.Null);
arguments.Add (e);
bounds [i++] = probe.Count;
return;
}
}
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:22,代码来源:expression.cs
示例7: 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));
//.........这里部分代码省略.........
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:anonymous.cs
示例8: DoEmit
protected override void DoEmit (EmitContext ec)
{
ILGenerator ig = ec.ig;
copy.EmitAssign (ec, for_each.expr);
int rank = length_exprs.Length;
Label[] test = new Label [rank];
Label[] loop = new Label [rank];
for (int i = 0; i < rank; i++) {
test [i] = ig.DefineLabel ();
loop [i] = ig.DefineLabel ();
if (lengths != null)
lengths [i].EmitAssign (ec, length_exprs [i]);
}
IntConstant zero = new IntConstant (0, loc);
for (int i = 0; i < rank; i++) {
counter [i].EmitAssign (ec, zero);
ig.Emit (OpCodes.Br, test [i]);
ig.MarkLabel (loop [i]);
}
((IAssignMethod) for_each.variable).EmitAssign (ec, conv, false, false);
statement.Emit (ec);
ig.MarkLabel (ec.LoopBegin);
for (int i = rank - 1; i >= 0; i--){
counter [i].EmitIncrement (ec);
ig.MarkLabel (test [i]);
counter [i].Emit (ec);
if (lengths != null)
lengths [i].Emit (ec);
else
length_exprs [i].Emit (ec);
ig.Emit (OpCodes.Blt, loop [i]);
}
ig.MarkLabel (ec.LoopEnd);
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:48,代码来源:statement.cs
示例9: UpdateIndices
public void UpdateIndices (EmitContext ec)
{
int i = 0;
for (ArrayList probe = initializers; probe != null;) {
if (probe.Count > 0 && probe [0] is ArrayList) {
Expression e = new IntConstant (probe.Count);
arguments.Add (new Argument (e, Argument.AType.Expression));
bounds [i++] = probe.Count;
probe = (ArrayList) probe [0];
} else {
Expression e = new IntConstant (probe.Count);
arguments.Add (new Argument (e, Argument.AType.Expression));
bounds [i++] = probe.Count;
probe = null;
}
}
}
开发者ID:emtees,项目名称:old-code,代码行数:22,代码来源:expression.cs
示例10: 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());
}
开发者ID:emtees,项目名称:old-code,代码行数:100,代码来源:expression.cs
示例11: TryReduceNegative
/// <remarks>
/// The result has been already resolved:
///
/// FIXME: a minus constant -128 sbyte cant be turned into a
/// constant byte.
/// </remarks>
static Expression TryReduceNegative (Constant expr)
{
Expression e = null;
if (expr is IntConstant)
e = new IntConstant (-((IntConstant) expr).Value);
else if (expr is UIntConstant){
uint value = ((UIntConstant) expr).Value;
if (value < 2147483649)
return new IntConstant (-(int)value);
else
e = new LongConstant (value);
}
else if (expr is LongConstant)
e = new LongConstant (-((LongConstant) expr).Value);
else if (expr is ULongConstant){
ulong value = ((ULongConstant) expr).Value;
if (value < 9223372036854775809)
return new LongConstant(-(long)value);
}
else if (expr is FloatConstant)
e = new FloatConstant (-((FloatConstant) expr).Value);
else if (expr is DoubleConstant)
e = new DoubleConstant (-((DoubleConstant) expr).Value);
else if (expr is DecimalConstant)
e = new DecimalConstant (-((DecimalConstant) expr).Value);
else if (expr is ShortConstant)
e = new IntConstant (-((ShortConstant) expr).Value);
else if (expr is UShortConstant)
e = new IntConstant (-((UShortConstant) expr).Value);
return e;
}
开发者ID:emtees,项目名称:old-code,代码行数:40,代码来源:expression.cs
示例12: BinaryFold
//.........这里部分代码省略.........
((EnumConstant)right).Child, loc).TryReduce (ec, lt, loc);
///
/// U operator -(E x, E y);
///
case Binary.Operator.Subtraction:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
return result.TryReduce (ec, ((EnumConstant)left).Child.Type, loc);
///
/// bool operator ==(E x, E y);
/// bool operator !=(E x, E y);
/// bool operator <(E x, E y);
/// bool operator >(E x, E y);
/// bool operator <=(E x, E y);
/// bool operator >=(E x, E y);
///
case Binary.Operator.Equality:
case Binary.Operator.Inequality:
case Binary.Operator.LessThan:
case Binary.Operator.GreaterThan:
case Binary.Operator.LessThanOrEqual:
case Binary.Operator.GreaterThanOrEqual:
return BinaryFold(ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
}
return null;
}
switch (oper){
case Binary.Operator.BitwiseOr:
if (!DoBinaryNumericPromotions (ref left, ref right))
return null;
if (left is IntConstant){
int res = ((IntConstant) left).Value | ((IntConstant) right).Value;
return new IntConstant (res, left.Location);
}
if (left is UIntConstant){
uint res = ((UIntConstant)left).Value | ((UIntConstant)right).Value;
return new UIntConstant (res, left.Location);
}
if (left is LongConstant){
long res = ((LongConstant)left).Value | ((LongConstant)right).Value;
return new LongConstant (res, left.Location);
}
if (left is ULongConstant){
ulong res = ((ULongConstant)left).Value |
((ULongConstant)right).Value;
return new ULongConstant (res, left.Location);
}
break;
case Binary.Operator.BitwiseAnd:
if (!DoBinaryNumericPromotions (ref left, ref right))
return null;
///
/// int operator &(int x, int y);
/// uint operator &(uint x, uint y);
/// long operator &(long x, long y);
/// ulong operator &(ulong x, ulong y);
///
开发者ID:lewurm,项目名称:benchmarker,代码行数:67,代码来源:cfold.cs
注:本文中的Mono.CSharp.IntConstant类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论