本文整理汇总了C#中Mono.CSharp.LocalTemporary类的典型用法代码示例。如果您正苦于以下问题:C# LocalTemporary类的具体用法?C# LocalTemporary怎么用?C# LocalTemporary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalTemporary类属于Mono.CSharp命名空间,在下文中一共展示了LocalTemporary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: EmitPredefined
public void EmitPredefined (EmitContext ec, MethodSpec method, Arguments Arguments, bool statement = false, Location? loc = null)
{
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 {
call_op = IsVirtualCallRequired (InstanceExpression, method) ? OpCodes.Callvirt : OpCodes.Call;
if (HasAwaitArguments) {
instance_copy = InstanceExpression.EmitToField (ec);
var ie = new InstanceEmitter (instance_copy, IsAddressCall (instance_copy, call_op, method.DeclaringType));
if (Arguments == null) {
ie.EmitLoad (ec, true);
}
} else if (!InstanceExpressionOnStack) {
var ie = new InstanceEmitter (InstanceExpression, IsAddressCall (InstanceExpression, call_op, method.DeclaringType));
ie.Emit (ec, ConditionalAccess);
if (DuplicateArguments) {
ec.Emit (OpCodes.Dup);
if (Arguments != null && Arguments.Count != 0) {
lt = new LocalTemporary (ie.GetStackType (ec));
lt.Store (ec);
instance_copy = lt;
}
}
}
}
if (Arguments != null && !InstanceExpressionOnStack) {
EmittedArguments = Arguments.Emit (ec, DuplicateArguments, HasAwaitArguments);
if (EmittedArguments != null) {
if (instance_copy != null) {
var ie = new InstanceEmitter (instance_copy, IsAddressCall (instance_copy, call_op, method.DeclaringType));
ie.Emit (ec, ConditionalAccess);
if (lt != null)
lt.Release (ec);
}
EmittedArguments.Emit (ec);
}
}
if (call_op == OpCodes.Callvirt && (InstanceExpression.Type.IsGenericParameter || InstanceExpression.Type.IsStructOrEnum)) {
ec.Emit (OpCodes.Constrained, InstanceExpression.Type);
}
if (loc != null) {
//
// Emit explicit sequence point for expressions like Foo.Bar () to help debugger to
// break at right place when LHS expression can be stepped-into
//
ec.MarkCallEntry (loc.Value);
}
//
// 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);
} else {
//
// 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);
}
//
// Pop the return value if there is one and stack should be empty
//
if (statement && method.ReturnType.Kind != MemberKind.Void)
ec.Emit (OpCodes.Pop);
}
示例3: EmitAssign
public void EmitAssign (EmitContext ec)
{
var type = Expr.Type;
if (IsByRef) {
var ml = (IMemoryLocation) Expr;
ml.AddressOf (ec, AddressOp.Load);
type = ReferenceContainer.MakeType (type);
} else {
Expr.Emit (ec);
}
variable = new LocalTemporary (type);
variable.Store (ec);
Expr = variable;
}
示例4: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: EmitAssign
public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
{
FieldAttributes fa = FieldInfo.Attributes;
bool is_static = (fa & FieldAttributes.Static) != 0;
bool is_readonly = (fa & FieldAttributes.InitOnly) != 0;
ILGenerator ig = ec.ig;
if (is_readonly && !ec.IsConstructor){
Report_AssignToReadonly (source);
return;
}
prepared = prepare_for_load;
EmitInstance (ec, prepared);
source.Emit (ec);
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
if (!FieldInfo.IsStatic) {
temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
FieldBase f = TypeManager.GetField (FieldInfo);
if (f != null){
if ((f.ModFlags & Modifiers.VOLATILE) != 0)
ig.Emit (OpCodes.Volatile);
f.SetAssigned ();
}
if (is_static)
ig.Emit (OpCodes.Stsfld, GetConstructedFieldInfo ());
else
ig.Emit (OpCodes.Stfld, GetConstructedFieldInfo ());
if (temp != null) {
temp.Emit (ec);
temp.Release (ec);
temp = null;
}
}
示例9: EmitPredefined
public void EmitPredefined (EmitContext ec, MethodSpec method, Arguments Arguments, Location? loc = null)
{
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);
}
if (loc != null) {
//
// Emit explicit sequence point for expressions like Foo.Bar () to help debugger to
// break at right place when LHS expression can be stepped-into
//
// TODO: The list is probably not comprehensive, need to do more testing
//
if (InstanceExpression is PropertyExpr || InstanceExpression is Invocation || InstanceExpression is IndexerExpr ||
InstanceExpression is New || InstanceExpression is DelegateInvocation)
ec.Mark (loc.Value);
}
//
// 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);
}
示例10: 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);
}
示例11: Emit
public void Emit (EmitContext ec, bool leave_copy)
{
ILGenerator ig = ec.ig;
bool is_volatile = false;
FieldBase f = TypeManager.GetField (FieldInfo);
if (f != null){
if ((f.ModFlags & Modifiers.VOLATILE) != 0)
is_volatile = true;
f.SetMemberIsUsed ();
}
if (FieldInfo.IsStatic){
if (is_volatile)
ig.Emit (OpCodes.Volatile);
ig.Emit (OpCodes.Ldsfld, GetConstructedFieldInfo ());
} else {
if (!prepared)
EmitInstance (ec, false);
IFixedBuffer ff = AttributeTester.GetFixedBuffer (FieldInfo);
if (ff != null) {
ig.Emit (OpCodes.Ldflda, GetConstructedFieldInfo ());
ig.Emit (OpCodes.Ldflda, ff.Element);
} else {
if (is_volatile)
ig.Emit (OpCodes.Volatile);
ig.Emit (OpCodes.Ldfld, GetConstructedFieldInfo ());
}
}
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
if (!FieldInfo.IsStatic) {
temp = new LocalTemporary (this.Type);
temp.Store (ec);
}
}
}
示例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: 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);
}
示例14: Emit
public override bool Emit (EmitContext ec, IMemoryLocation target)
{
bool left_on_stack = base.Emit (ec, target);
if (initializers.IsEmpty)
return left_on_stack;
LocalTemporary temp = target as LocalTemporary;
if (temp == null) {
if (!left_on_stack) {
VariableReference vr = target as VariableReference;
// FIXME: This still does not work correctly for pre-set variables
if (vr != null && vr.IsRef)
target.AddressOf (ec, AddressOp.Load);
((Expression) target).Emit (ec);
left_on_stack = true;
}
temp = new LocalTemporary (type);
}
instance = temp;
if (left_on_stack)
temp.Store (ec);
initializers.Emit (ec);
if (left_on_stack) {
temp.Emit (ec);
temp.Release (ec);
}
return left_on_stack;
}
示例15: 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);
var get_enumerator_mg = ResolveGetEnumerator (ec);
if (get_enumerator_mg == null) {
return false;
}
var get_enumerator = get_enumerator_mg.BestCandidate;
var enumerator = new TemporaryVariable (get_enumerator.ReturnType, loc);
enumerator.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;
// 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 }.Resolve (ec);
if (current_pe == null)
return false;
VarExpr ve = var_type as VarExpr;
if (ve != null) {
// Infer implicitly typed local variable from foreach enumerable type
var_type = new TypeExpression (current_pe.Type, var_type.Location);
}
var_type = var_type.ResolveAsTypeTerminal (ec, false);
if (var_type == null)
return false;
var init = new Invocation (get_enumerator_mg, null);
init.Resolve (ec);
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.Type;
//
// Add Dispose method call when enumerator can be IDisposable
//
if (!enumerator.Type.ImplementsInterface (TypeManager.idisposable_type)) {
if (!enum_type.IsSealed && !TypeManager.IsValueType (enum_type)) {
//
// Runtime Dispose check
//
var tv = new LocalTemporary (TypeManager.idisposable_type);
statement = new Dispose (enumerator, tv, init, statement, loc);
} else {
//
// No Dispose call needed
//
this.init = new SimpleAssign (enumerator, init);
this.init.Resolve (ec);
}
} else {
//
// Static Dispose check
//
statement = new Dispose (enumerator, null, init, statement, loc);
}
return statement.Resolve (ec);
}