本文整理汇总了C#中Mono.CSharp.Invocation类的典型用法代码示例。如果您正苦于以下问题:C# Invocation类的具体用法?C# Invocation怎么用?C# Invocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Invocation类属于Mono.CSharp命名空间,在下文中一共展示了Invocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FallbackInvoke
public override DynamicMetaObject FallbackInvoke (DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
{
var expr = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target);
var c_args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), args);
expr = new Compiler.Invocation (expr, c_args);
if ((flags & CSharpBinderFlags.ResultDiscarded) == 0)
expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
else
expr = new Compiler.DynamicResultCast (TypeImporter.Import (ReturnType), expr);
var binder = new CSharpBinder (this, expr, errorSuggestion);
binder.AddRestrictions (target);
binder.AddRestrictions (args);
return binder.Bind (callingContext, target);
}
开发者ID:afaerber,项目名称:mono,代码行数:17,代码来源:CSharpInvokeBinder.cs
示例2: FallbackInvokeMember
public override DynamicMetaObject FallbackInvokeMember (DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
{
var c_args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), args);
var t_args = typeArguments == null ?
null :
new Compiler.TypeArguments (typeArguments.Select (l => new Compiler.TypeExpression (TypeImporter.Import (l), Compiler.Location.Null)).ToArray ());
var expr = CSharpBinder.CreateCompilerExpression (argumentInfo[0], target);
//
// Simple name invocation is actually member access invocation
// to capture original this argument. This brings problem when
// simple name is resolved as a static invocation and member access
// has to be reduced back to simple name without reporting an error
//
if ((flags & CSharpBinderFlags.InvokeSimpleName) != 0) {
var value = expr as Compiler.RuntimeValueExpression;
if (value != null)
value.IsSuggestionOnly = true;
}
expr = new Compiler.MemberAccess (expr, Name, t_args, Compiler.Location.Null);
expr = new Compiler.Invocation (expr, c_args);
if ((flags & CSharpBinderFlags.ResultDiscarded) == 0)
expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
else
expr = new Compiler.DynamicResultCast (TypeImporter.Import (ReturnType), expr);
var binder = new CSharpBinder (this, expr, errorSuggestion);
binder.AddRestrictions (target);
binder.AddRestrictions (args);
if ((flags & CSharpBinderFlags.InvokeSpecialName) != 0)
binder.ResolveOptions |= Compiler.ResolveContext.Options.InvokeSpecialName;
return binder.Bind (callingContext, target);
}
开发者ID:afaerber,项目名称:mono,代码行数:38,代码来源:CSharpInvokeMemberBinder.cs
示例3: case_438
void case_438()
{
yyVal = new Invocation ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop]);
lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
}
开发者ID:animaonline,项目名称:Portable-Mono.CSharp,代码行数:5,代码来源:cs-parser.cs
示例4: CreateHoistedBaseCallProxy
//
// Creates a proxy base method call inside this container for hoisted base member calls
//
public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
{
Method proxy_method;
//
// One proxy per base method is enough
//
if (hoisted_base_call_proxies == null) {
hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
proxy_method = null;
} else {
hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
}
if (proxy_method == null) {
string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);
MemberName member_name;
TypeArguments targs = null;
TypeSpec return_type = method.ReturnType;
var local_param_types = method.Parameters.Types;
if (method.IsGeneric) {
//
// Copy all base generic method type parameters info
//
var hoisted_tparams = method.GenericDefinition.TypeParameters;
var tparams = new TypeParameters ();
targs = new TypeArguments ();
targs.Arguments = new TypeSpec[hoisted_tparams.Length];
for (int i = 0; i < hoisted_tparams.Length; ++i) {
var tp = hoisted_tparams[i];
var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null);
tparams.Add (local_tp);
targs.Add (new SimpleName (tp.Name, Location));
targs.Arguments[i] = local_tp.Type;
}
member_name = new MemberName (name, tparams, Location);
//
// Mutate any method type parameters from original
// to newly created hoisted version
//
var mutator = new TypeParameterMutator (hoisted_tparams, tparams);
return_type = mutator.Mutate (return_type);
local_param_types = mutator.Mutate (local_param_types);
} else {
member_name = new MemberName (name);
}
var base_parameters = new Parameter[method.Parameters.Count];
for (int i = 0; i < base_parameters.Length; ++i) {
var base_param = method.Parameters.FixedParameters[i];
base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location),
base_param.Name, base_param.ModFlags, null, Location);
base_parameters[i].Resolve (this, i);
}
var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
if (method.Parameters.HasArglist) {
cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
}
// Compiler generated proxy
proxy_method = new Method (this, new TypeExpression (return_type, Location),
Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
member_name, cloned_params, null);
var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) {
IsCompilerGenerated = true
};
var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
if (targs != null)
mg.SetTypeArguments (rc, targs);
// Get all the method parameters and pass them as arguments
var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
Statement statement;
if (method.ReturnType.Kind == MemberKind.Void)
statement = new StatementExpression (real_base_call);
else
statement = new Return (real_base_call, Location);
block.AddStatement (statement);
proxy_method.Block = block;
members.Add (proxy_method);
proxy_method.Define ();
proxy_method.PrepareEmit ();
hoisted_base_call_proxies.Add (method, proxy_method);
//.........这里部分代码省略.........
开发者ID:fvalette,项目名称:mono,代码行数:101,代码来源:class.cs
示例5: CreateHoistedBaseCallProxy
//
// Creates a proxy base method call inside this container for hoisted base member calls
//
public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
{
Method proxy_method;
//
// One proxy per base method is enough
//
if (hoisted_base_call_proxies == null) {
hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
proxy_method = null;
} else {
hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
}
if (proxy_method == null) {
string name = CompilerGeneratedClass.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);
var base_parameters = new Parameter[method.Parameters.Count];
for (int i = 0; i < base_parameters.Length; ++i) {
var base_param = method.Parameters.FixedParameters[i];
base_parameters[i] = new Parameter (new TypeExpression (method.Parameters.Types[i], Location),
base_param.Name, base_param.ModFlags, null, Location);
base_parameters[i].Resolve (this, i);
}
var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
if (method.Parameters.HasArglist) {
cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve (Location);
}
GenericMethod generic_method;
MemberName member_name;
if (method.IsGeneric) {
//
// Copy all base generic method type parameters info
//
var hoisted_tparams = method.GenericDefinition.TypeParameters;
var targs = new TypeArguments ();
var type_params = new TypeParameter[hoisted_tparams.Length];
for (int i = 0; i < type_params.Length; ++i) {
var tp = hoisted_tparams[i];
targs.Add (new TypeParameterName (tp.Name, null, Location));
type_params[i] = new TypeParameter (tp, this, null, new MemberName (tp.Name), null);
}
member_name = new MemberName (name, targs, Location);
generic_method = new GenericMethod (NamespaceEntry, this, member_name, type_params,
new TypeExpression (method.ReturnType, Location), cloned_params);
} else {
member_name = new MemberName (name);
generic_method = null;
}
// Compiler generated proxy
proxy_method = new Method (this, generic_method, new TypeExpression (method.ReturnType, Location),
Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
member_name, cloned_params, null);
var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location);
var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
// Get all the method parameters and pass them as arguments
var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
Statement statement;
if (method.ReturnType == TypeManager.void_type)
statement = new StatementExpression (real_base_call);
else
statement = new Return (real_base_call, Location);
block.AddStatement (statement);
proxy_method.Block = block;
methods.Add (proxy_method);
proxy_method.Define ();
hoisted_base_call_proxies.Add (method, proxy_method);
}
return proxy_method.Spec;
}
开发者ID:famousthom,项目名称:monodevelop,代码行数:85,代码来源:class.cs
示例6: DoResolve
protected override Expression DoResolve (ResolveContext ec)
{
CloneContext cc = new CloneContext ();
Expression clone = source.Clone (cc);
//
// A useful feature for the REPL: if we can resolve the expression
// as a type, Describe the type;
//
if (Evaluator.DescribeTypeExpressions){
var old_printer = Evaluator.SetPrinter (new StreamReportPrinter (TextWriter.Null));
clone = clone.Resolve (ec);
if (clone == null){
clone = source.Clone (cc);
clone = clone.Resolve (ec, ResolveFlags.Type);
if (clone == null){
Evaluator.SetPrinter (old_printer);
clone = source.Clone (cc);
clone = clone.Resolve (ec);
return null;
}
Arguments args = new Arguments (1);
args.Add (new Argument (new TypeOf ((TypeExpr) clone, Location)));
source = new Invocation (new SimpleName ("Describe", Location), args).Resolve (ec);
}
Evaluator.SetPrinter (old_printer);
} else {
clone = clone.Resolve (ec);
if (clone == null)
return null;
}
// This means its really a statement.
if (clone.Type == TypeManager.void_type){
source = source.Resolve (ec);
target = null;
type = TypeManager.void_type;
eclass = ExprClass.Value;
return this;
}
return base.DoResolve (ec);
}
开发者ID:silk,项目名称:monodevelop,代码行数:44,代码来源:eval.cs
示例7: case_446
void case_446()
#line 3310 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
yyVal = new Invocation ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop]);
lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:8,代码来源:cs-parser.cs
示例8: RuntimeDynamicInvocation
public RuntimeDynamicInvocation (Invocation invoke, Compiler.Expression memberExpr)
: base (memberExpr)
{
this.invoke = invoke;
}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:CSharpInvokeMemberBinder.cs
示例9: Resolve
public override bool Resolve (BlockContext ec)
{
bool is_dynamic = expr.Type == InternalType.Dynamic;
if (is_dynamic) {
expr = Convert.ImplicitConversionRequired (ec, expr, TypeManager.ienumerable_type, loc);
} else if (TypeManager.IsNullableType (expr.Type)) {
expr = new Nullable.UnwrapCall (expr).Resolve (ec);
}
var get_enumerator_mg = ResolveGetEnumerator (ec);
if (get_enumerator_mg == null) {
return false;
}
var get_enumerator = get_enumerator_mg.BestCandidate;
enumerator_variable = TemporaryVariableReference.Create (get_enumerator.ReturnType, variable.Block, loc);
enumerator_variable.Resolve (ec);
// Prepare bool MoveNext ()
var move_next_mg = ResolveMoveNext (ec, get_enumerator);
if (move_next_mg == null) {
return false;
}
move_next_mg.InstanceExpression = enumerator_variable;
// Prepare ~T~ Current { get; }
var current_prop = ResolveCurrent (ec, get_enumerator);
if (current_prop == null) {
return false;
}
var current_pe = new PropertyExpr (current_prop, loc) { InstanceExpression = enumerator_variable }.Resolve (ec);
if (current_pe == null)
return false;
VarExpr ve = var_type as VarExpr;
if (ve != null) {
if (is_dynamic) {
// Source type is dynamic, set element type to dynamic too
var_type = new TypeExpression (InternalType.Dynamic, var_type.Location);
} else {
// Infer implicitly typed local variable from foreach enumerable type
var_type = new TypeExpression (current_pe.Type, var_type.Location);
}
} else if (is_dynamic) {
// Explicit cast of dynamic collection elements has to be done at runtime
current_pe = EmptyCast.Create (current_pe, InternalType.Dynamic);
}
var_type = var_type.ResolveAsTypeTerminal (ec, false);
if (var_type == null)
return false;
variable.Type = var_type.Type;
var init = new Invocation (get_enumerator_mg, null);
statement = new While (new BooleanExpression (new Invocation (move_next_mg, null)),
new Body (var_type.Type, variable, current_pe, statement, loc), loc);
var enum_type = enumerator_variable.Type;
//
// Add Dispose method call when enumerator can be IDisposable
//
if (!enum_type.ImplementsInterface (TypeManager.idisposable_type, false)) {
if (!enum_type.IsSealed && !TypeManager.IsValueType (enum_type)) {
//
// Runtime Dispose check
//
var vd = new RuntimeDispose (enumerator_variable.LocalInfo, loc);
vd.Initializer = init;
statement = new Using (vd, statement, loc);
} else {
//
// No Dispose call needed
//
this.init = new SimpleAssign (enumerator_variable, init);
this.init.Resolve (ec);
}
} else {
//
// Static Dispose check
//
var vd = new Using.VariableDeclaration (enumerator_variable.LocalInfo, loc);
vd.Initializer = init;
statement = new Using (vd, statement, loc);
}
return statement.Resolve (ec);
}
开发者ID:alisci01,项目名称:mono,代码行数:93,代码来源:statement.cs
示例10: CreateDynamicUnaryOperation
private Expression CreateDynamicUnaryOperation(ResolveContext rc)
{
this.Arguments.CastDynamicArgs(rc);
TypeSpec unary = rc.Module.PredefinedTypes.PsUnaryOperation.Resolve();
string type = GetDynamicUnaryTypeName(Arguments[0].Type);
// create unary method name
string unaryMethod = this.name + type;
var ret = new Invocation(new MemberAccess(new TypeExpression(unary, loc), unaryMethod, loc), this.Arguments).Resolve(rc);
if (ret.Type == rc.BuiltinTypes.Object) {
// cast object to dynamic for return types
ret = new Cast (new TypeExpression (rc.BuiltinTypes.Dynamic, loc), ret, loc).Resolve (rc);
}
return ret;
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:17,代码来源:dynamic.cs
示例11: 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
示例12: Emit
public override void Emit (EmitContext ec)
{
Expression concat = new Invocation (CreateConcatMemberExpression (), arguments, true);
concat = concat.Resolve (new ResolveContext (ec.MemberContext));
if (concat != null)
concat.Emit (ec);
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:expression.cs
示例13: Resolve
public override bool Resolve (EmitContext ec)
{
enumerator_type = TypeManager.ienumerator_type;
if (!ProbeCollectionType (ec, expr.Type)) {
Error_Enumerator ();
return false;
}
bool is_disposable = !enumerator_type.IsSealed ||
TypeManager.ImplementsInterface (enumerator_type, TypeManager.idisposable_type);
VarExpr ve = var_type as VarExpr;
if (ve != null) {
// Infer implicitly typed local variable from foreach enumerable type
var_type = new TypeExpression (get_current.PropertyInfo.PropertyType, var_type.Location);
}
var_type = var_type.ResolveAsTypeTerminal (ec, false);
if (var_type == null)
return false;
enumerator = new TemporaryVariable (enumerator_type, loc);
enumerator.Resolve (ec);
init = new Invocation (get_enumerator, null);
init = init.Resolve (ec);
if (init == null)
return false;
Expression move_next_expr;
{
MemberInfo[] mi = new MemberInfo[] { move_next };
MethodGroupExpr mg = new MethodGroupExpr (mi, var_type.Type, loc);
mg.InstanceExpression = enumerator;
move_next_expr = new Invocation (mg, null);
}
get_current.InstanceExpression = enumerator;
Statement block = new CollectionForeachStatement (
var_type.Type, variable, get_current, statement, loc);
loop = new While (move_next_expr, block, loc);
wrapper = is_disposable ?
(Statement) new DisposableWrapper (this) :
(Statement) new NonDisposableWrapper (this);
return wrapper.Resolve (ec);
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:51,代码来源:statement.cs
示例14: case_439
void case_439()
{
Error_SyntaxError (yyToken);
yyVal = new Invocation ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop]);
lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]));
}
开发者ID:animaonline,项目名称:Portable-Mono.CSharp,代码行数:7,代码来源:cs-parser.cs
示例15: DoEmitStringSwitch
void DoEmitStringSwitch (LocalTemporary value, EmitContext ec)
{
Label l_initialized = ec.DefineLabel ();
//
// Skip initialization when value is null
//
value.EmitBranchable (ec, null_target, false);
//
// Check if string dictionary is initialized and initialize
//
switch_cache_field.EmitBranchable (ec, l_initialized, true);
string_dictionary.EmitStatement (ec);
ec.MarkLabel (l_initialized);
LocalTemporary string_switch_variable = new LocalTemporary (TypeManager.int32_type);
ResolveContext rc = new ResolveContext (ec.MemberContext);
if (TypeManager.generic_ienumerable_type != null) {
Arguments get_value_args = new Arguments (2);
get_value_args.Add (new Argument (value));
get_value_args.Add (new Argument (string_switch_variable, Argument.AType.Out));
Expression get_item = new Invocation (new MemberAccess (switch_cache_field, "TryGetValue", loc), get_value_args).Resolve (rc);
if (get_item == null)
return;
//
// A value was not found, go to default case
//
get_item.EmitBranchable (ec, default_target, false);
} else {
Arguments get_value_args = new Arguments (1);
get_value_args.Add (new Argument (value));
Expression get_item = new ElementAccess (switch_cache_field, get_value_args, loc).Resolve (rc);
if (get_item == null)
return;
LocalTemporary get_item_object = new LocalTemporary (TypeManager.object_type);
get_item_object.EmitAssign (ec, get_item, true, false);
ec.Emit (OpCodes.Brfalse, default_target);
ExpressionStatement get_item_int = (ExpressionStatement) new SimpleAssign (string_switch_variable,
new Cast (new TypeExpression (TypeManager.int32_type, loc), get_item_object, loc)).Resolve (rc);
get_item_int.EmitStatement (ec);
get_item_object.Release (ec);
}
TableSwitchEmit (ec, string_switch_variable);
string_switch_variable.Release (ec);
}
开发者ID:alisci01,项目名称:mono,代码行数:54,代码来源:statement.cs
示例16: CreateDynamicBinaryOperation
//.........这里部分代码省略.........
case Binary.Operator.Multiply:
binaryMethod = "Multiply";
break;
case Binary.Operator.Division:
binaryMethod = "Division";
break;
case Binary.Operator.Modulus:
binaryMethod = "Modulus";
break;
case Binary.Operator.Addition:
binaryMethod = "Addition";
break;
case Binary.Operator.Subtraction:
binaryMethod = "Subtraction";
break;
case Binary.Operator.LeftShift:
binaryMethod = "LeftShift";
break;
case Binary.Operator.RightShift:
binaryMethod = "RightShift";
break;
case Binary.Operator.AsURightShift:
binaryMethod = "AsURightShift";
break;
case Binary.Operator.LessThan:
binaryMethod = "LessThan";
break;
case Binary.Operator.GreaterThan:
binaryMethod = "GreaterThan";
break;
case Binary.Operator.LessThanOrEqual:
binaryMethod = "LessThanOrEqual";
break;
case Binary.Operator.GreaterThanOrEqual:
binaryMethod = "GreaterThanOrEqual";
break;
case Binary.Operator.Equality:
binaryMethod = "Equality";
break;
case Binary.Operator.Inequality:
binaryMethod = "Inequality";
break;
case Binary.Operator.AsStrictEquality:
binaryMethod = "AsStrictEquality";
break;
case Binary.Operator.AsStrictInequality:
binaryMethod = "AsStrictInequality";
break;
case Binary.Operator.BitwiseAnd:
binaryMethod = "BitwiseAnd";
break;
case Binary.Operator.ExclusiveOr:
binaryMethod = "ExclusiveOr";
break;
case Binary.Operator.BitwiseOr:
binaryMethod = "BitwiseOr";
break;
// we should never support these
// case Binary.Operator.LogicalAnd:
// binaryMethod = "LogicalAnd";
// break;
// case Binary.Operator.LogicalOr:
// binaryMethod = "LogicalOr";
// break;
case Binary.Operator.AsE4xChild:
binaryMethod = "AsE4xChild";
break;
case Binary.Operator.AsE4xDescendant:
binaryMethod = "AsE4xDescendant";
break;
case Binary.Operator.AsE4xChildAttribute:
binaryMethod = "AsE4xChildAttribute";
break;
case Binary.Operator.AsE4xDescendantAttribute:
binaryMethod = "AsE4xDescendantAttribute";
break;
default:
throw new InvalidOperationException("Unknown binary operation: " + oper);
}
string leftType = GetDynamicBinaryTypeName(Arguments[0].Type);
string rightType = GetDynamicBinaryTypeName(Arguments[1].Type);
// for strict equality checks, just use a single method and check
// types at runtime
if (oper == Binary.Operator.AsStrictEquality ||
oper == Binary.Operator.AsStrictInequality) {
leftType = rightType = "Obj";
}
// append to binary method instead of using overloads
binaryMethod += leftType + rightType;
var ret = new Invocation(new MemberAccess(new TypeExpression(binary, loc), binaryMethod, loc), Arguments).Resolve(rc);
if (ret.Type == rc.BuiltinTypes.Object) {
// cast object to dynamic for return types
ret = new Cast (new TypeExpression (rc.BuiltinTypes.Dynamic, loc), ret, loc).Resolve (rc);
}
return ret;
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:101,代码来源:dynamic.cs
示例17: DoImplicitConversionStandard
static Expression DoImplicitConversionStandard (ResolveContext ec, Expression expr, TypeSpec target_type, Location loc, bool explicit_cast, bool upconvert_only)
{
if (expr.eclass == ExprClass.MethodGroup){
if (!target_type.IsDelegate){
if (ec.FileType == SourceFileType.PlayScript &&
(target_type == ec.BuiltinTypes.Dynamic || target_type == ec.BuiltinTypes.Delegate)) {
MethodGroupExpr mg = expr as MethodGroupExpr;
if (mg != null) {
if (mg.Candidates.Count != 1) {
ec.Report.Error (7021, loc, "Ambiguous overloaded methods `{0}' when assigning to Function or Object type", mg.Name);
return null;
}
var ms = (MethodSpec)mg.Candidates[0];
var del_type = Delegate.CreateDelegateTypeFromMethodSpec(ec, ms, loc);
// If return is "Delegate", we create a var args anonymous method which calls the target method..
if (del_type == ec.BuiltinTypes.Delegate) {
var objArrayType = new ComposedCast (
new TypeExpression(ec.BuiltinTypes.Object, loc),
ComposedTypeSpecifier.CreateArrayDimension (1, loc));
var parameters = new ParametersCompiled(new Parameter[] {
new ParamsParameter(objArrayType, "args", null, loc) }, false);
var dynCall = new AnonymousMethodExpression(expr.Location, parameters, new TypeExpression(ms.ReturnType, loc));
var block = new ParametersBlock (ec.CurrentBlock, parameters, expr.Location);
dynCall.Block = block;
var args = new Arguments (3);
args.Add (new Argument(new TypeOf(new TypeExpression(ms.DeclaringType, loc), loc)));
args.Add (new Argument(new StringLiteral(ec.BuiltinTypes, ms.Name, loc)));
args.Add (new Argument(new SimpleName("args", loc)));
var call = new Invocation (new MemberAccess(new MemberAccess(new SimpleName("PlayScript", loc), "Support", loc), "VarArgCall", loc), args);
if (ms.ReturnType == ec.BuiltinTypes.Void) {
block.AddStatement (new StatementExpression(call));
} else {
block.AddStatement (new Return(call, loc));
}
return dynCall.Resolve (ec);
} else {
// Otherwise cast to the specific delegate type
return new ImplicitDelegateCreation (del_type, mg, loc).Resolve (ec);
}
}
}
return null;
}
//
// Only allow anonymous method conversions on post ISO_1
//
if (ec.Module.Compiler.Settings.Version != LanguageVersion.ISO_1){
MethodGroupExpr mg = expr as MethodGroupExpr;
if (mg != null)
return new ImplicitDelegateCreation (target_type, mg, loc).Resolve (ec);
}
}
TypeSpec expr_type = expr.Type;
Expression e;
if (expr_type == target_type) {
if (expr_type != InternalType.NullLiteral && expr_type != InternalType.AnonymousMethod)
return expr;
return null;
}
// Auto convert types to type objects..
if (ec.FileType == SourceFileType.PlayScript && target_type.BuiltinType == BuiltinTypeSpec.Type.Type && expr is FullNamedExpression) {
FullNamedExpression type_expr = (FullNamedExpression)expr;
if (expr_type != null) {
if (expr_type.MemberDefinition.Namespace == PsConsts.PsRootNamespace) {
switch (expr_type.Name) {
case "String":
type_expr = new TypeExpression (ec.BuiltinTypes.String, type_expr.Location);
break;
case "Number":
type_expr = new TypeExpression (ec.BuiltinTypes.Double, type_expr.Location);
break;
case "Boolean":
type_expr = new TypeExpression (ec.BuiltinTypes.Double, type_expr.Location);
break;
}
} else if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
type_expr = new TypeExpression (ec.Module.PredefinedTypes.AsObject.Resolve(), type_expr.Location);
}
}
return new TypeOf (type_expr, expr.Location).Resolve (ec);
}
if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
// Implicitly cast references to bools in PlayScript
if (ec.FileType == SourceFileType.PlayScript &&
target_type.BuiltinType == BuiltinTypeSpec.Type.Bool &&
ec.Target != Target.JavaScript) {
var cast_args = new Arguments(1);
cast_args.Add (new Argument(EmptyCast.Create(expr, ec.BuiltinTypes.Object)));
// ec.Report.Warning (7164, 1, expr.Location, "Expensive reference conversion to bool");
return new Invocation(new MemberAccess(new MemberAccess(new SimpleName(
//.........这里部分代码省略.........
开发者ID:johnv315,项目名称:playscript-mono,代码行数:101,代码来源:convert.cs
示例18: Visit
public virtual object Visit (Invocation invocationExpression)
{
return null;
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:4,代码来源:visit.cs
示例19: TryInline
public Expression TryInline(ResolveContext rc) {
if (!(Expr is Invocation)) {
return Expr;
}
invocation = (Expr as Invocation);
if (invocation.MethodGroup.BestCandidate == null) {
return Expr;
}
methodSpec = invocation.MethodGroup.BestCandidate;
if (!(methodSpec.MemberDefinition is MethodCore)) {
return Expr;
}
method = methodSpec.MemberDefinition as MemberCore;
methodData = method as IMethodData;
if (methodData.IsInlinable) {
return Expr;
}
TypeSpec returnType = methodData.ReturnType;
ToplevelBlock block = methodData.Block;
if (block.Parameters.Count > 0 || block.TopBlock.NamesCount > 0 && block.TopBlock.LabelsCount > 0) {
return Expr;
}
if (returnType != rc.BuiltinTypes.Void &&
block.Statements.Count == 1 && block.Statements [0] is Return) {
inlineExpr = ((Return)block.Statements [0]).Expr.Clone (new CloneContext());
} else if (returnType == rc.BuiltinTypes.Void) {
Block newBlock = new Block (rc.CurrentBlock, block.StartLocation, block.EndLocation);
foreach (var st in block.Statements) {
newBlock.AddStatement (st.Clone (new CloneContext()));
}
// inlineExpr = newBlock;
}
this.rc = rc;
this.inlineFailed = false;
Expression ret;
inlineExpr.Accept (this);
ret = inlineExpr;
if (inlineFailed) {
return Expr;
}
return ret;
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:54,代码来源:inliner.cs
示例20: case_445
void case_445()
#line 3305 "cs-parser.jay"
{
yyVal = new Invocation ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop]);
lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
}
开发者ID:segaman,项目名称:NRefactory,代码行数:6,代码来源:cs-parser.cs
注:本文中的Mono.CSharp.Invocation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论