本文整理汇总了C#中Mono.CSharp.Argument类的典型用法代码示例。如果您正苦于以下问题:C# Argument类的具体用法?C# Argument怎么用?C# Argument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Argument类属于Mono.CSharp命名空间,在下文中一共展示了Argument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BetterConversion
/// <summary>
/// Determines "better conversion" as specified in 7.4.2.3
/// Returns : 1 if a->p is better
/// 0 if a->q or neither is better
/// </summary>
static int BetterConversion (EmitContext ec, Argument a, Type p, Type q, Location loc)
{
Type argument_type = a.Type;
Expression argument_expr = a.Expr;
if (argument_type == null)
throw new Exception ("Expression of type " + a.Expr + " does not resolve its type");
//
// This is a special case since csc behaves this way. I can't find
// it anywhere in the spec but oh well ...
//
if (argument_expr is NullLiteral && p == TypeManager.string_type && q == TypeManager.object_type)
return 1;
else if (argument_expr is NullLiteral && p == TypeManager.object_type && q == TypeManager.string_type)
return 0;
if (p == q)
return 0;
if (argument_type == p)
return 1;
if (argument_type == q)
return 0;
//
// Now probe whether an implicit constant expression conversion
// can be used.
//
// An implicit constant expression conversion permits the following
// conversions:
//
// * A constant-expression of type `int' can be converted to type
// sbyte, byute, short, ushort, uint, ulong provided the value of
// of the expression is withing the range of the destination type.
//
// * A constant-expression of type long can be converted to type
// ulong, provided the value of the constant expression is not negative
//
// FIXME: Note that this assumes that constant folding has
// taken place. We dont do constant folding yet.
//
if (argument_expr is IntConstant){
IntConstant ei = (IntConstant) argument_expr;
int value = ei.Value;
if (p == TypeManager.sbyte_type){
if (value >= SByte.MinValue && value <= SByte.MaxValue)
return 1;
} else if (p == TypeManager.byte_type){
if (q == TypeManager.sbyte_type &&
value >= SByte.MinValue && value <= SByte.MaxValue)
return 0;
else if (Byte.MinValue >= 0 && value <= Byte.MaxValue)
return 1;
} else if (p == TypeManager.short_type){
if (value >= Int16.MinValue && value <= Int16.MaxValue)
return 1;
} else if (p == TypeManager.ushort_type){
if (q == TypeManager.short_type &&
value >= Int16.MinValue && value <= Int16.MaxValue)
return 0;
else if (value >= UInt16.MinValue && value <= UInt16.MaxValue)
return 1;
} else if (p == TypeManager.int32_type){
if (value >= Int32.MinValue && value <= Int32.MaxValue)
return 1;
} else if (p == TypeManager.uint32_type){
//
// we can optimize this case: a positive int32
// always fits on a uint32
//
if (value >= 0)
return 1;
} else if (p == TypeManager.uint64_type){
//
// we can optimize this case: a positive int32
// always fits on a uint64
//
if (q == TypeManager.int64_type)
return 0;
else if (value >= 0)
return 1;
} else if (p == TypeManager.int64_type){
return 1;
}
} else if (argument_type == TypeManager.int64_type && argument_expr is LongConstant){
LongConstant lc = (LongConstant) argument_expr;
if (p == TypeManager.uint64_type){
if (lc.Value > 0)
return 1;
}
//.........这里部分代码省略.........
开发者ID:emtees,项目名称:old-code,代码行数:101,代码来源:expression.cs
示例2:
bool OverloadResolver.IErrorHandler.ArgumentMismatch (ResolveContext rc, MemberSpec best, Argument arg, int index)
{
Error_ConversionFailed (rc, best as MethodSpec, null);
return true;
}
开发者ID:psni,项目名称:mono,代码行数:5,代码来源:delegate.cs
示例3: Insert
public void Insert (int index, Argument arg)
{
args.Insert (index, arg);
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:4,代码来源:argument.cs
示例4: case_477
void case_477()
#line 3492 "cs-parser.jay"
{
yyVal = new Argument ((Expression) yyVals[0+yyTop], Argument.AType.Out);
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:6,代码来源:cs-parser.cs
示例5: case_479
void case_479()
#line 3502 "cs-parser.jay"
{
yyVal = new Argument (new Arglist (GetLocation (yyVals[-2+yyTop])));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:6,代码来源:cs-parser.cs
示例6: AsTryResolveDynamicArgs
// Resolve any dynamic params to the type of the target parameters list (for PlayScript only).
public bool AsTryResolveDynamicArgs (ResolveContext ec, System.Collections.IEnumerable candidates)
{
MethodSpec ms = null;
foreach (MethodSpec possibleMs in candidates) {
if (possibleMs.Parameters.FixedParameters.Length <= args.Count &&
possibleMs.Parameters.Count >= args.Count) {
if (ms != null) {
ms = null; // Can't be more than one - or we give up and do a dynamic call..
break;
}
ms = possibleMs;
}
}
if (ms != null) {
var parameters = ms.Parameters;
for (var i = 0; i < args.Count; i++) {
var arg = args [i];
var paramType = parameters.Types [i];
if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) {
var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType;
var new_arg = new Argument (new Cast (
new TypeExpression (parCastType, arg.Expr.Location),
arg.Expr, arg.Expr.Location), arg.ArgType);
new_arg.Resolve (ec);
args [i] = new_arg;
}
}
return true;
}
return false;
}
开发者ID:OpenFlex,项目名称:playscript-mono,代码行数:32,代码来源:argument.cs
示例7: AsTryResolveDynamicArgs
// Resolve any dynamic params to the type of the target parameters list (for PlayScript only).
public bool AsTryResolveDynamicArgs (ResolveContext ec, System.Collections.IEnumerable candidates)
{
AParametersCollection parameters = null;
foreach (MemberSpec memberSpec in candidates) {
AParametersCollection possibleParams = null;
int fixedArgsLen = 0;
if (memberSpec is MethodSpec) {
MethodSpec methodSpec = memberSpec as MethodSpec;
possibleParams = methodSpec.Parameters;
fixedArgsLen = possibleParams.FixedParameters.Length;
if (methodSpec.IsExtensionMethod)
fixedArgsLen--;
} else if (memberSpec is IndexerSpec) {
IndexerSpec indexerSpec = memberSpec as IndexerSpec;
possibleParams = indexerSpec.Parameters;
fixedArgsLen = possibleParams.FixedParameters.Length;
}
if (fixedArgsLen == args.Count) {
if (parameters != null) {
parameters = null; // Can't be more than one - or we give up and do a dynamic call..
break;
}
parameters = possibleParams;
}
}
if (parameters != null) {
for (var i = 0; i < args.Count; i++) {
var arg = args [i];
var paramType = parameters.Types [i];
if (arg.Expr.Type == ec.BuiltinTypes.Dynamic) {
var parCastType = paramType.BuiltinType == BuiltinTypeSpec.Type.Dynamic ? ec.BuiltinTypes.Object : paramType;
var new_arg = new Argument (new Cast (
new TypeExpression (parCastType, arg.Expr.Location),
arg.Expr, arg.Expr.Location), arg.ArgType);
new_arg.Resolve (ec);
args [i] = new_arg;
}
}
return true;
}
return false;
}
开发者ID:johnv315,项目名称:playscript-mono,代码行数:49,代码来源:argument.cs
示例8: ResolveUserOperator
//
// Performs user-operator overloading
//
protected virtual Expression ResolveUserOperator (ResolveContext ec, Type l, Type r)
{
Operator user_oper;
if (oper == Operator.LogicalAnd)
user_oper = Operator.BitwiseAnd;
else if (oper == Operator.LogicalOr)
user_oper = Operator.BitwiseOr;
else
user_oper = oper;
string op = GetOperatorMetadataName (user_oper);
MethodGroupExpr left_operators = MemberLookup (ec.Compiler, ec.CurrentType, l, op, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
MethodGroupExpr right_operators = null;
if (!TypeManager.IsEqual (r, l)) {
right_operators = MemberLookup (ec.Compiler, ec.CurrentType, r, op, MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
if (right_operators == null && left_operators == null)
return null;
} else if (left_operators == null) {
return null;
}
Arguments args = new Arguments (2);
Argument larg = new Argument (left);
args.Add (larg);
Argument rarg = new Argument (right);
args.Add (rarg);
MethodGroupExpr union;
//
// User-defined operator implementations always take precedence
// over predefined operator implementations
//
if (left_operators != null && right_operators != null) {
if (IsPredefinedUserOperator (l, user_oper)) {
union = right_operators.OverloadResolve (ec, ref args, true, loc);
if (union == null)
union = left_operators;
} else if (IsPredefinedUserOperator (r, user_oper)) {
union = left_operators.OverloadResolve (ec, ref args, true, loc);
if (union == null)
union = right_operators;
} else {
union = MethodGroupExpr.MakeUnionSet (left_operators, right_operators, loc);
}
} else if (left_operators != null) {
union = left_operators;
} else {
union = right_operators;
}
union = union.OverloadResolve (ec, ref args, true, loc);
if (union == null)
return null;
Expression oper_expr;
// TODO: CreateExpressionTree is allocated every time
if (user_oper != oper) {
oper_expr = new ConditionalLogicalOperator (union, args, CreateExpressionTree,
oper == Operator.LogicalAnd, loc).Resolve (ec);
} else {
oper_expr = new UserOperatorCall (union, args, CreateExpressionTree, loc);
//
// This is used to check if a test 'x == null' can be optimized to a reference equals,
// and not invoke user operator
//
if ((oper & Operator.EqualityMask) != 0) {
if ((left is NullLiteral && IsBuildInEqualityOperator (r)) ||
(right is NullLiteral && IsBuildInEqualityOperator (l))) {
type = TypeManager.bool_type;
if (left is NullLiteral || right is NullLiteral)
oper_expr = ReducedExpression.Create (this, oper_expr).Resolve (ec);
} else if (l != r) {
MethodInfo mi = (MethodInfo) union;
//
// Two System.Delegate(s) are never equal
//
if (mi.DeclaringType == TypeManager.multicast_delegate_type)
return null;
}
}
}
left = larg.Expr;
right = rarg.Expr;
return oper_expr;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:95,代码来源:expression.cs
示例9: CreateExpressionAddCall
//
// Creates nested calls tree from an array of arguments used for IL emit
//
Expression CreateExpressionAddCall (ResolveContext ec, Argument left, Expression left_etree, int pos)
{
Arguments concat_args = new Arguments (2);
Arguments add_args = new Arguments (3);
concat_args.Add (left);
add_args.Add (new Argument (left_etree));
concat_args.Add (arguments [pos]);
add_args.Add (new Argument (arguments [pos].CreateExpressionTree (ec)));
MethodGroupExpr method = CreateConcatMemberExpression ().Resolve (ec) as MethodGroupExpr;
if (method == null)
return null;
method = method.OverloadResolve (ec, ref concat_args, false, loc);
if (method == null)
return null;
add_args.Add (new Argument (method.CreateExpressionTree (ec)));
Expression expr = CreateExpressionFactoryCall (ec, "Add", add_args);
if (++pos == arguments.Count)
return expr;
left = new Argument (new EmptyExpression (((MethodInfo)method).ReturnType));
return CreateExpressionAddCall (ec, left, expr, pos);
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:31,代码来源:expression.cs
示例10: Add
public int Add (Argument arg)
{
return args.Add (arg);
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:4,代码来源:argument.cs
示例11: Arglist
public Arglist (Argument[] args, Location l)
{
Arguments = args;
loc = l;
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:5,代码来源:expression.cs
示例12: case_470
void case_470()
{
yyVal = new Argument (new Arglist (GetLocation (yyVals[-2+yyTop])));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop]));
}
开发者ID:animaonline,项目名称:Portable-Mono.CSharp,代码行数:5,代码来源:cs-parser.cs
示例13: case_469
void case_469()
{
yyVal = new Argument (new Arglist ((Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-3+yyTop])));
lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
}
开发者ID:animaonline,项目名称:Portable-Mono.CSharp,代码行数:5,代码来源:cs-parser.cs
示例14: case_468
void case_468()
{
yyVal = new Argument ((Expression) yyVals[0+yyTop], Argument.AType.Out);
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
开发者ID:animaonline,项目名称:Portable-Mono.CSharp,代码行数:5,代码来源:cs-parser.cs
示例15: yyparse
//.........这里部分代码省略.........
case 71:
#line 788 "cs-parser.jay"
{ /* reserved attribute name or identifier: 17.4 */ }
break;
case 72:
#line 792 "cs-parser.jay"
{ yyVal = null; }
break;
case 73:
#line 796 "cs-parser.jay"
{
yyVal = yyVals[-1+yyTop];
}
break;
case 74:
#line 801 "cs-parser.jay"
{ yyVal = null; }
break;
case 75:
case_75();
break;
case 76:
case_76();
break;
case 77:
case_77();
break;
case 78:
case_78();
break;
case 79:
#line 845 "cs-parser.jay"
{
yyVal = new Argument ((Expression) yyVals[0+yyTop]);
}
break;
case 81:
#line 853 "cs-parser.jay"
{
++lexer.parsing_block;
}
break;
case 82:
case_82();
break;
case 83:
case_83();
break;
case 84:
#line 877 "cs-parser.jay"
{ yyVal = null; }
break;
case 85:
#line 881 "cs-parser.jay"
{
yyVal = Argument.AType.Ref;
}
break;
case 86:
#line 885 "cs-parser.jay"
{
yyVal = Argument.AType.Out;
}
break;
case 101:
case_101();
开发者ID:Ein,项目名称:monodevelop,代码行数:67,代码来源:cs-parser.cs
示例16: BetterExpressionConversion
//
// 7.4.3.3 Better conversion from expression
// Returns : 1 if a->p is better,
// 2 if a->q is better,
// 0 if neither is better
//
static int BetterExpressionConversion (EmitContext ec, Argument a, Type p, Type q)
{
Type argument_type = TypeManager.TypeToCoreType (a.Type);
if (argument_type == TypeManager.anonymous_method_type && RootContext.Version > LanguageVersion.ISO_2) {
//
// Uwrap delegate from Expression<T>
//
if (TypeManager.DropGenericTypeArguments (p) == TypeManager.expression_type) {
p = TypeManager.GetTypeArguments (p) [0];
}
if (TypeManager.DropGenericTypeArguments (q) == TypeManager.expression_type) {
q = TypeManager.GetTypeArguments (q) [0];
}
p = Delegate.GetInvokeMethod (null, p).ReturnType;
q = Delegate.GetInvokeMethod (null, q).ReturnType;
if (p == TypeManager.void_type && q != TypeManager.void_type)
return 2;
if (q == TypeManager.void_type && p != TypeManager.void_type)
return 1;
} else {
if (argument_type == p)
return 1;
if (argument_type == q)
return 2;
}
return BetterTypeConversion (ec, p, q);
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:36,代码来源:ecore.cs
示例17:
bool OverloadResolver.IErrorHandler.ArgumentMismatch (ResolveContext rc, MemberSpec best, Argument arg, int index)
{
return false;
}
开发者ID:alisci01,项目名称:mono,代码行数:4,代码来源:statement.cs
示例18: EmitCall
protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
{
//
// This method generates all internal infrastructure for a dynamic call. The
// reason why it's quite complicated is the mixture of dynamic and anonymous
// methods. Dynamic itself requires a temporary class (ContainerX) and anonymous
// methods can generate temporary storey as well (AnonStorey). Handling MVAR
// type parameters rewrite is non-trivial in such case as there are various
// combinations possible therefore the mutator is not straightforward. Secondly
// we need to keep both MVAR(possibly VAR for anon storey) and type VAR to emit
// correct Site field type and its access from EmitContext.
//
int dyn_args_count = arguments == null ? 0 : arguments.Count;
int default_args = isStatement ? 1 : 2;
var module = ec.Module;
bool is_invoke = ((MemberAccess)((Invocation)binder).Exp).Name.StartsWith ("Invoke");
TypeSpec callSite;
TypeSpec callSiteGeneric;
if (isPlayScriptAotMode) {
callSite = module.PredefinedTypes.AsCallSite.TypeSpec;
callSiteGeneric = module.PredefinedTypes.AsCallSiteGeneric.TypeSpec;
} else {
callSite = module.PredefinedTypes.CallSite.TypeSpec;
callSiteGeneric = module.PredefinedTypes.CallSiteGeneric.TypeSpec;
}
bool has_ref_out_argument = false;
var targs = new TypeExpression[dyn_args_count + default_args];
targs[0] = new TypeExpression (callSite, loc);
TypeExpression[] targs_for_instance = null;
TypeParameterMutator mutator;
var site_container = ec.CreateDynamicSite ();
if (context_mvars != null) {
TypeParameters tparam;
TypeContainer sc = site_container;
do {
tparam = sc.CurrentTypeParameters;
sc = sc.Parent;
} while (tparam == null);
mutator = new TypeParameterMutator (context_mvars, tparam);
if (!ec.IsAnonymousStoreyMutateRequired) {
targs_for_instance = new TypeExpression[targs.Length];
targs_for_instance[0] = targs[0];
}
} else {
mutator = null;
}
for (int i = 0; i < dyn_args_count; ++i) {
Argument a = arguments[i];
if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
has_ref_out_argument = true;
var t = a.Type;
// Convert any internal type like dynamic or null to object
if (t.Kind == MemberKind.InternalCompilerType)
t = ec.BuiltinTypes.Object;
// PlayScript AOT mode - Convert all types to object if they are not basic AS types or this is an invocation.
if (isPlayScriptAotMode && !IsValidPlayScriptAotType (t, is_invoke)) { // Always box to Object for invoke argument lists
t = ec.BuiltinTypes.Object;
arguments[i] = new Argument(new BoxedCast(a.Expr, ec.BuiltinTypes.Object));
}
if (targs_for_instance != null)
targs_for_instance[i + 1] = new TypeExpression (t, loc);
if (mutator != null)
t = t.Mutate (mutator);
targs[i + 1] = new TypeExpression (t, loc);
}
// Always use "object" as return type in AOT mode.
var ret_type = type;
if (isPlayScriptAotMode && !isStatement && !IsValidPlayScriptAotType (ret_type, is_invoke)) {
ret_type = ec.BuiltinTypes.Object;
}
TypeExpr del_type = null;
TypeExpr del_type_instance_access = null;
if (!has_ref_out_argument) {
string d_name = isStatement ? "Action" : "Func";
TypeExpr te = null;
Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true);
if (type_ns != null) {
te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, LookupMode.Normal, loc);
}
//.........这里部分代码省略.........
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:101,代码来源:dynamic.cs
示例19: MovableArgument
public MovableArgument (Argument arg)
: this (arg.Expr, arg.ArgType)
{
}
开发者ID:johnv315,项目名称:playscript-mono,代码行数:4,代码来源:argument.cs
示例20: IsApplicable
///
/// Determines if the candidate method is applicable (section 14.4.2.1)
/// to the given set of arguments
/// A return value rates candidate method compatibility,
/// 0 = the best, int.MaxValue = the worst
///
public int IsApplicable(ResolveContext ec,
ref Arguments arguments, int arg_count, ref MethodSpec method, ref bool params_expanded_form)
{
var candidate = method;
AParametersCollection pd = candidate.Parameters;
int param_count = GetApplicableParametersCount (candidate, pd);
int optional_count = 0;
if (arg_count != param_count) {
for (int i = 0; i < pd.Count; ++i) {
if (pd.FixedParameters [i].HasDefaultValue) {
optional_count = pd.Count - i;
break;
}
}
int args_gap = System.Math.Abs (arg_count - param_count);
if (optional_count != 0) {
if (args_gap > optional_count)
return int.MaxValue - 10000 + args_gap - optional_count;
// Readjust expected number when params used
if (pd.HasParams) {
optional_count--;
if (arg_count < param_count)
param_count--;
} else if (arg_count > param_count) {
return int.MaxValue - 10000 + args_gap;
}
} else if (arg_count != param_count) {
if (!pd.HasParams)
return int.MaxValue - 10000 + args_gap;
if (arg_count < param_count - 1)
return int.MaxValue - 10000 + args_gap;
}
// Initialize expanded form of a method with 1 params parameter
params_expanded_form = param_count == 1 && pd.HasParams;
// Resize to fit optional arguments
if (optional_count != 0) {
Arguments resized;
if (arguments == null) {
resized = new Arguments (optional_count);
} else {
resized = new Arguments (param_count);
resized.AddRange (arguments);
}
for (int i = arg_count; i < param_count; ++i)
resized.Add (null);
arguments = resized;
}
}
if (arg_count > 0) {
//
// Shuffle named arguments to the right positions if there are any
//
if (arguments [arg_count - 1] is NamedArgument) {
arg_count = arguments.Count;
for (int i = 0; i < arg_count; ++i) {
bool arg_moved = false;
while (true) {
NamedArgument na = arguments[i] as NamedArgument;
if (na == null)
break;
int index = pd.GetParameterIndexByName (na.Name);
// Named parameter not found or already reordered
if (index <= i)
break;
// When using parameters which should not be available to the user
if (index >= param_count)
break;
if (!arg_moved) {
arguments.MarkReorderedArgument (na);
arg_moved = true;
}
Argument temp = arguments[index];
arguments[index] = arguments[i];
arguments[i] = temp;
if (temp == null)
break;
}
}
} else {
//.........这里部分代码省略.........
开发者ID:speier,项目名称:shake,代码行数:101,代码来源:ecore.cs
注:本文中的Mono.CSharp.Argument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论