本文整理汇总了C#中Mono.CSharp.LocalTemporary.Store方法的典型用法代码示例。如果您正苦于以下问题:C# LocalTemporary.Store方法的具体用法?C# LocalTemporary.Store怎么用?C# LocalTemporary.Store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.LocalTemporary
的用法示例。
在下文中一共展示了LocalTemporary.Store方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitAddressOf
protected virtual IMemoryLocation EmitAddressOf (EmitContext ec, AddressOp mode)
{
LocalTemporary value_target = new LocalTemporary (type);
if (is_type_parameter) {
DoEmitTypeParameter (ec);
value_target.Store (ec);
value_target.AddressOf (ec, mode);
return value_target;
}
if (!TypeManager.IsStruct (type)){
//
// We throw an exception. So far, I believe we only need to support
// value types:
// foreach (int j in new StructType ())
// see bug 42390
//
throw new Exception ("AddressOf should not be used for classes");
}
value_target.AddressOf (ec, AddressOp.Store);
if (method == null) {
ec.ig.Emit (OpCodes.Initobj, type);
} else {
if (Arguments != null)
Arguments.Emit (ec);
ec.ig.Emit (OpCodes.Call, (ConstructorInfo) method);
}
value_target.AddressOf (ec, mode);
return value_target;
}
示例2: Emit
//
// if `dup_args' is true or any of arguments contains await.
// A copy of all arguments will be returned to the caller
//
public virtual Arguments Emit (EmitContext ec, bool dup_args, bool prepareAwait)
{
List<Argument> dups;
if ((dup_args && Count != 0) || prepareAwait)
dups = new List<Argument> (Count);
else
dups = null;
LocalTemporary lt;
foreach (Argument a in args) {
if (prepareAwait) {
dups.Add (a.EmitToField (ec, true));
continue;
}
a.Emit (ec);
if (!dup_args) {
continue;
}
if (a.Expr.IsSideEffectFree) {
//
// No need to create a temporary variable for side effect free expressions. I assume
// all side-effect free expressions are cheap, this has to be tweaked when we become
// more aggressive on detection
//
dups.Add (a);
} else {
ec.Emit (OpCodes.Dup);
// TODO: Release local temporary on next Emit
// Need to add a flag to argument to indicate this
lt = new LocalTemporary (a.Type);
lt.Store (ec);
dups.Add (new Argument (lt, a.ArgType));
}
}
if (dups != null)
return new Arguments (dups);
return null;
}
示例3: EmitLoad
public void EmitLoad (EmitContext ec, bool boxInstance)
{
var instance_type = instance.Type;
//
// Push the instance expression
//
if (addressRequired) {
//
// If the expression implements IMemoryLocation, then
// we can optimize and use AddressOf on the
// return.
//
// If not we have to use some temporary storage for
// it.
var iml = instance as IMemoryLocation;
if (iml != null) {
iml.AddressOf (ec, AddressOp.Load);
} else {
LocalTemporary temp = new LocalTemporary (instance_type);
instance.Emit (ec);
temp.Store (ec);
temp.AddressOf (ec, AddressOp.Load);
}
return;
}
instance.Emit (ec);
// Only to make verifier happy
if (boxInstance && RequiresBoxing ()) {
ec.Emit (OpCodes.Box, instance_type);
}
}
示例4: EmitStoreyInstantiation
//
// Initializes all hoisted variables
//
public void EmitStoreyInstantiation (EmitContext ec)
{
// There can be only one instance variable for each storey type
if (Instance != null)
throw new InternalErrorException ();
SymbolWriter.OpenCompilerGeneratedBlock (ec);
//
// Create an instance of a storey
//
var storey_type_expr = CreateStoreyTypeExpression (ec);
ResolveContext rc = new ResolveContext (ec.MemberContext);
Expression e = new New (storey_type_expr, null, Location).Resolve (rc);
e.Emit (ec);
Instance = new LocalTemporary (storey_type_expr.Type);
Instance.Store (ec);
EmitHoistedFieldsInitialization (ec);
SymbolWriter.DefineScopeVariable (ID, Instance.Builder);
SymbolWriter.CloseCompilerGeneratedBlock (ec);
}
示例5: EmitPredefined
public void EmitPredefined (EmitContext ec, MethodSpec method, Arguments Arguments)
{
Expression instance_copy = null;
if (!HasAwaitArguments && ec.HasSet (BuilderContext.Options.AsyncBody)) {
HasAwaitArguments = Arguments != null && Arguments.ContainsEmitWithAwait ();
if (HasAwaitArguments && InstanceExpressionOnStack) {
throw new NotSupportedException ();
}
}
OpCode call_op;
LocalTemporary lt = null;
if (method.IsStatic) {
call_op = OpCodes.Call;
} else {
if (IsVirtualCallRequired (InstanceExpression, method)) {
call_op = OpCodes.Callvirt;
} else {
call_op = OpCodes.Call;
}
if (HasAwaitArguments) {
instance_copy = InstanceExpression.EmitToField (ec);
if (Arguments == null)
EmitCallInstance (ec, instance_copy, method.DeclaringType, call_op);
} else if (!InstanceExpressionOnStack) {
var instance_on_stack_type = EmitCallInstance (ec, InstanceExpression, method.DeclaringType, call_op);
if (DuplicateArguments) {
ec.Emit (OpCodes.Dup);
if (Arguments != null && Arguments.Count != 0) {
lt = new LocalTemporary (instance_on_stack_type);
lt.Store (ec);
instance_copy = lt;
}
}
}
}
if (Arguments != null && !InstanceExpressionOnStack) {
EmittedArguments = Arguments.Emit (ec, DuplicateArguments, HasAwaitArguments);
if (EmittedArguments != null) {
if (instance_copy != null) {
EmitCallInstance (ec, instance_copy, method.DeclaringType, call_op);
if (lt != null)
lt.Release (ec);
}
EmittedArguments.Emit (ec);
}
}
if (call_op == OpCodes.Callvirt && (InstanceExpression.Type.IsGenericParameter || InstanceExpression.Type.IsStruct)) {
ec.Emit (OpCodes.Constrained, InstanceExpression.Type);
}
//
// Set instance expression to actual result expression. When it contains await it can be
// picked up by caller
//
InstanceExpression = instance_copy;
if (method.Parameters.HasArglist) {
var varargs_types = GetVarargsTypes (method, Arguments);
ec.Emit (call_op, method, varargs_types);
return;
}
//
// If you have:
// this.DoFoo ();
// and DoFoo is not virtual, you can omit the callvirt,
// because you don't need the null checking behavior.
//
ec.Emit (call_op, method);
}
示例6: EmitAssign
//
// Implements the IAssignMethod interface for assignments
//
public void EmitAssign(EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
Expression my_source = source;
if (prepare_for_load) {
prepared = true;
source.Emit (ec);
if (leave_copy) {
ec.Emit (OpCodes.Dup);
if (!IsStatic) {
temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
} else if (leave_copy) {
source.Emit (ec);
temp = new LocalTemporary (this.Type);
temp.Store (ec);
my_source = temp;
}
Arguments args = new Arguments (1);
args.Add (new Argument (my_source));
Invocation.EmitCall (ec, IsBase, InstanceExpression, spec.Set, args, loc, false, prepared);
if (temp != null) {
temp.Emit (ec);
temp.Release (ec);
}
}
示例7: DoEmit
protected override void DoEmit (EmitContext ec)
{
//
// Needed to emit anonymous storey initialization
// Otherwise it does not contain any statements for now
//
block.Emit (ec);
default_target = ec.DefineLabel ();
null_target = ec.DefineLabel ();
// Store variable for comparission purposes
// TODO: Don't duplicate non-captured VariableReference
LocalTemporary value;
if (HaveUnwrap) {
value = new LocalTemporary (SwitchType);
unwrap.EmitCheck (ec);
ec.Emit (OpCodes.Brfalse, null_target);
new_expr.Emit (ec);
value.Store (ec);
} else if (!is_constant) {
value = new LocalTemporary (SwitchType);
new_expr.Emit (ec);
value.Store (ec);
} else
value = null;
//
// Setup the codegen context
//
Label old_end = ec.LoopEnd;
Switch old_switch = ec.Switch;
ec.LoopEnd = ec.DefineLabel ();
ec.Switch = this;
// Emit Code.
if (is_constant) {
if (constant_section != null)
constant_section.Block.Emit (ec);
} else if (string_dictionary != null) {
DoEmitStringSwitch (value, ec);
} else {
TableSwitchEmit (ec, value);
}
if (value != null)
value.Release (ec);
// Restore context state.
ec.MarkLabel (ec.LoopEnd);
//
// Restore the previous context
//
ec.LoopEnd = old_end;
ec.Switch = old_switch;
}
示例8: EmitAssign
//
// source is ignored, because we already have a copy of it from the
// LValue resolution and we have already constructed a pre-cached
// version of the arguments (ea.set_arguments);
//
public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
prepared = prepare_for_load;
Expression value = set_expr;
if (prepared) {
Invocation.EmitCall (ec, is_base_indexer, instance_expr, get,
arguments, loc, true, false);
prepared_value = new LocalTemporary (type);
prepared_value.Store (ec);
source.Emit (ec);
prepared_value.Release (ec);
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
temp = new LocalTemporary (Type);
temp.Store (ec);
}
} else if (leave_copy) {
temp = new LocalTemporary (Type);
source.Emit (ec);
temp.Store (ec);
value = temp;
}
if (!prepared)
arguments.Add (new Argument (value));
Invocation.EmitCall (ec, is_base_indexer, instance_expr, set, arguments, loc, false, prepared);
if (temp != null) {
temp.Emit (ec);
temp.Release (ec);
}
}
示例9: EmitStoreyInstantiation
//
// Initializes all hoisted variables
//
public void EmitStoreyInstantiation (EmitContext ec)
{
// There can be only one instance variable for each storey type
if (Instance != null)
throw new InternalErrorException ();
SymbolWriter.OpenCompilerGeneratedBlock (ec.ig);
//
// Create an instance of storey type
//
Expression storey_type_expr;
if (is_generic) {
//
// Use current method type parameter (MVAR) for top level storey only. All
// nested storeys use class type parameter (VAR)
//
TypeParameter[] tparams = ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.Storey != null ?
ec.CurrentAnonymousMethod.Storey.TypeParameters :
ec.CurrentTypeParameters;
TypeArguments targs = new TypeArguments ();
if (tparams.Length < CountTypeParameters) {
TypeParameter[] parent_tparams = ec.MemberContext.CurrentTypeDefinition.TypeParameters;
for (int i = 0; i < parent_tparams.Length; ++i)
targs.Add (new TypeParameterExpr (parent_tparams[i], Location));
}
for (int i = 0; i < tparams.Length; ++i)
targs.Add (new TypeParameterExpr (tparams[i], Location));
storey_type_expr = new GenericTypeExpr (TypeBuilder, targs, Location);
} else {
storey_type_expr = new TypeExpression (TypeBuilder, Location);
}
ResolveContext rc = new ResolveContext (this);
Expression e = new New (storey_type_expr, null, Location).Resolve (rc);
e.Emit (ec);
Instance = new LocalTemporary (storey_type_expr.Type);
Instance.Store (ec);
EmitHoistedFieldsInitialization (ec);
SymbolWriter.DefineScopeVariable (ID, Instance.Builder);
SymbolWriter.CloseCompilerGeneratedBlock (ec.ig);
}
示例10: Emit
public void Emit (EmitContext ec, bool leave_copy)
{
if (prepared) {
prepared_value.Emit (ec);
} else {
Invocation.EmitCall (ec, is_base_indexer, instance_expr, get,
arguments, loc, false, false);
}
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
temp = new LocalTemporary (Type);
temp.Store (ec);
}
}
示例11: EmitInstance
protected void EmitInstance(EmitContext ec, bool prepare_for_load)
{
if (IsStatic)
return;
if (InstanceExpression == EmptyExpression.Null) {
// FIXME: This should not be here at all
SimpleName.Error_ObjectRefRequired (new ResolveContext (ec.MemberContext), loc, GetSignatureForError ());
return;
}
if (TypeManager.IsValueType (InstanceExpression.Type)) {
if (InstanceExpression is IMemoryLocation) {
((IMemoryLocation) InstanceExpression).AddressOf (ec, AddressOp.LoadStore);
} else {
LocalTemporary t = new LocalTemporary (InstanceExpression.Type);
InstanceExpression.Emit (ec);
t.Store (ec);
t.AddressOf (ec, AddressOp.Store);
}
} else
InstanceExpression.Emit (ec);
if (prepare_for_load)
ec.Emit (OpCodes.Dup);
}
示例12: EmitLoad
public void EmitLoad (EmitContext ec)
{
var instance_type = instance.Type;
//
// Push the instance expression
//
if (addressRequired) {
//
// If the expression implements IMemoryLocation, then
// we can optimize and use AddressOf on the
// return.
//
// If not we have to use some temporary storage for
// it.
var iml = instance as IMemoryLocation;
if (iml != null) {
iml.AddressOf (ec, AddressOp.Load);
} else {
LocalTemporary temp = new LocalTemporary (instance_type);
instance.Emit (ec);
temp.Store (ec);
temp.AddressOf (ec, AddressOp.Load);
}
return;
}
instance.Emit (ec);
// Only to make verifier happy
if (instance_type.IsGenericParameter && !(instance is This) && TypeSpec.IsReferenceType (instance_type)) {
ec.Emit (OpCodes.Box, instance_type);
} else if (instance_type.IsStructOrEnum) {
ec.Emit (OpCodes.Box, instance_type);
}
}
示例13: Emit
public void Emit(EmitContext ec, bool leave_copy)
{
//
// Special case: length of single dimension array property is turned into ldlen
//
if (IsSingleDimensionalArrayLength ()) {
if (!prepared)
EmitInstance (ec, false);
ec.Emit (OpCodes.Ldlen);
ec.Emit (OpCodes.Conv_I4);
return;
}
Invocation.EmitCall (ec, IsBase, InstanceExpression, spec.Get, null, loc, prepared, false);
if (leave_copy) {
ec.Emit (OpCodes.Dup);
if (!IsStatic) {
temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
}
示例14: EmitInstance
protected void EmitInstance (EmitContext ec, bool prepare_for_load)
{
if (IsStatic)
return;
if (InstanceExpression == EmptyExpression.Null) {
SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return;
}
if (InstanceExpression.Type.IsValueType) {
if (InstanceExpression is IMemoryLocation) {
((IMemoryLocation) InstanceExpression).AddressOf (ec, AddressOp.LoadStore);
} else {
LocalTemporary t = new LocalTemporary (InstanceExpression.Type);
InstanceExpression.Emit (ec);
t.Store (ec);
t.AddressOf (ec, AddressOp.Store);
}
} else
InstanceExpression.Emit (ec);
if (prepare_for_load)
ec.ig.Emit (OpCodes.Dup);
}
示例15: DoEmit
protected override void DoEmit (EmitContext ec)
{
if (CatchType != null)
ec.BeginCatchBlock (CatchType);
else
ec.BeginCatchBlock (TypeManager.object_type);
if (VarBlock != null)
VarBlock.Emit (ec);
if (Name != null) {
// TODO: Move to resolve
LocalVariableReference lvr = new LocalVariableReference (Block, Name, loc);
lvr.Resolve (new ResolveContext (ec.MemberContext));
// Only to make verifier happy
if (TypeManager.IsGenericParameter (lvr.Type))
ec.Emit (OpCodes.Unbox_Any, lvr.Type);
Expression source;
if (lvr.IsHoisted) {
LocalTemporary lt = new LocalTemporary (lvr.Type);
lt.Store (ec);
source = lt;
} else {
// Variable is at the top of the stack
source = EmptyExpression.Null;
}
lvr.EmitAssign (ec, source, false, false);
} else
ec.Emit (OpCodes.Pop);
Block.Emit (ec);
}