本文整理汇总了C#中Mono.CSharp.EmitContext.With方法的典型用法代码示例。如果您正苦于以下问题:C# EmitContext.With方法的具体用法?C# EmitContext.With怎么用?C# EmitContext.With使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.EmitContext
的用法示例。
在下文中一共展示了EmitContext.With方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoResolve
Expression DoResolve (EmitContext ec, bool lvalue_instance, bool out_access)
{
if (!FieldInfo.IsStatic){
if (InstanceExpression == null){
//
// This can happen when referencing an instance field using
// a fully qualified type expression: TypeName.InstanceField = xxx
//
SimpleName.Error_ObjectRefRequired (ec, loc, GetSignatureForError ());
return null;
}
// Resolve the field's instance expression while flow analysis is turned
// off: when accessing a field "a.b", we must check whether the field
// "a.b" is initialized, not whether the whole struct "a" is initialized.
if (lvalue_instance) {
using (ec.With (EmitContext.Flags.DoFlowAnalysis, false)) {
Expression right_side =
out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side, loc);
}
} else {
ResolveFlags rf = ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;
InstanceExpression = InstanceExpression.Resolve (ec, rf);
}
if (InstanceExpression == null)
return null;
using (ec.Set (EmitContext.Flags.OmitStructFlowAnalysis)) {
InstanceExpression.CheckMarshalByRefAccess (ec);
}
}
// TODO: the code above uses some non-standard multi-resolve rules
if (eclass != ExprClass.Invalid)
return this;
if (!ec.IsInObsoleteScope) {
FieldBase f = TypeManager.GetField (FieldInfo);
if (f != null) {
f.CheckObsoleteness (loc);
} else {
ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (FieldInfo);
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (FieldInfo), loc);
}
}
IFixedBuffer fb = AttributeTester.GetFixedBuffer (FieldInfo);
IVariableReference var = InstanceExpression as IVariableReference;
if (fb != null) {
IFixedExpression fe = InstanceExpression as IFixedExpression;
if (!ec.InFixedInitializer && (fe == null || !fe.IsFixed)) {
Report.Error (1666, loc, "You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement");
}
if (InstanceExpression.eclass != ExprClass.Variable) {
Report.SymbolRelatedToPreviousError (FieldInfo);
Report.Error (1708, loc, "`{0}': Fixed size buffers can only be accessed through locals or fields",
TypeManager.GetFullNameSignature (FieldInfo));
} else if (var != null && var.IsHoisted) {
AnonymousMethodExpression.Error_AddressOfCapturedVar (var, loc);
}
return new FixedBufferPtr (this, fb.ElementType, loc).Resolve (ec);
}
eclass = ExprClass.Variable;
// If the instance expression is a local variable or parameter.
if (var == null || var.VariableInfo == null)
return this;
VariableInfo vi = var.VariableInfo;
if (!vi.IsFieldAssigned (ec, FieldInfo.Name, loc))
return null;
variable_info = vi.GetSubStruct (FieldInfo.Name);
eclass = ExprClass.Variable;
return this;
}
示例2: ResolveMeta
protected void ResolveMeta (EmitContext ec, int offset)
{
Report.Debug (64, "BLOCK RESOLVE META", this, Parent);
// If some parent block was unsafe, we remain unsafe even if this block
// isn't explicitly marked as such.
using (ec.With (EmitContext.Flags.InUnsafe, ec.InUnsafe | Unsafe)) {
flags |= Flags.VariablesInitialized;
if (variables != null) {
foreach (LocalInfo li in variables.Values) {
if (!li.Resolve (ec))
continue;
li.VariableInfo = new VariableInfo (li, offset);
offset += li.VariableInfo.Length;
}
}
assignable_slots = offset;
DoResolveConstants (ec);
if (children == null)
return;
foreach (Block b in children)
b.ResolveMeta (ec, offset);
}
}
示例3: ConvertExpressionToArrayIndex
//
// Converts `source' to an int, uint, long or ulong.
//
public Expression ConvertExpressionToArrayIndex (EmitContext ec, Expression source)
{
Expression converted;
using (ec.With (EmitContext.Flags.CheckState, true)) {
converted = Convert.ImplicitConversion (ec, source, TypeManager.int32_type, source.loc);
if (converted == null)
converted = Convert.ImplicitConversion (ec, source, TypeManager.uint32_type, source.loc);
if (converted == null)
converted = Convert.ImplicitConversion (ec, source, TypeManager.int64_type, source.loc);
if (converted == null)
converted = Convert.ImplicitConversion (ec, source, TypeManager.uint64_type, source.loc);
if (converted == null) {
source.Error_ValueCannotBeConverted (ec, source.loc, TypeManager.int32_type, false);
return null;
}
}
//
// Only positive constants are allowed at compile time
//
Constant c = converted as Constant;
if (c != null) {
if (c.IsNegative) {
Error_NegativeArrayIndex (source.loc);
}
return c;
}
return new ArrayIndexCast (converted).Resolve (ec);
}
示例4: EmitStatement
public override void EmitStatement (EmitContext ec)
{
var stmt = new If (condition, new StatementExpression (invoke), new StatementExpression (assign), loc);
using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) {
stmt.Emit (ec);
}
}
示例5: EmitStatement
public override void EmitStatement (EmitContext ec)
{
if (resolved == null)
return;
//
// Emit sequence symbol info even if we are in compiler generated
// block to allow debugging field initializers when constructor is
// compiler generated
//
if (ec.HasSet (BuilderContext.Options.OmitDebugInfo) && ec.HasMethodSymbolBuilder) {
using (ec.With (BuilderContext.Options.OmitDebugInfo, false)) {
ec.Mark (loc);
}
}
if (resolved != this)
resolved.EmitStatement (ec);
else
base.EmitStatement (ec);
}
示例6: EmitScopeInitializers
protected void EmitScopeInitializers (EmitContext ec)
{
SymbolWriter.OpenCompilerGeneratedBlock (ec);
using (ec.With (EmitContext.Options.OmitDebugInfo, true)) {
foreach (Statement s in scope_initializers)
s.Emit (ec);
}
SymbolWriter.CloseCompilerGeneratedBlock (ec);
}
示例7: Emit
//
// Emits the code
//
public override void Emit ()
{
if (Parent.PartialContainer.IsComImport) {
if (!IsDefault ()) {
Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
Parent.GetSignatureForError ());
}
ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
}
if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
Compiler.PredefinedAttributes.DebuggerHidden.EmitAttribute (ConstructorBuilder);
if (OptAttributes != null)
OptAttributes.Emit ();
base.Emit ();
//
// If we use a "this (...)" constructor initializer, then
// do not emit field initializers, they are initialized in the other constructor
//
bool emit_field_initializers = ((ModFlags & Modifiers.STATIC) != 0) ||
!(Initializer is ConstructorThisInitializer);
BlockContext bc = new BlockContext (this, block, TypeManager.void_type);
bc.Set (ResolveContext.Options.ConstructorScope);
if (emit_field_initializers)
Parent.PartialContainer.ResolveFieldInitializers (bc);
if (block != null) {
// If this is a non-static `struct' constructor and doesn't have any
// initializer, it must initialize all of the struct's fields.
if ((Parent.PartialContainer.Kind == MemberKind.Struct) &&
((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
block.AddThisVariable (bc, Parent, Location);
if (block != null && (ModFlags & Modifiers.STATIC) == 0){
if (Parent.PartialContainer.Kind == MemberKind.Class && Initializer == null)
Initializer = new GeneratedBaseInitializer (Location);
if (Initializer != null) {
block.AddScopeStatement (new StatementExpression (Initializer));
}
}
}
parameters.ApplyAttributes (this, ConstructorBuilder);
SourceMethod source = SourceMethod.Create (Parent, ConstructorBuilder, block);
if (block != null) {
if (block.Resolve (null, bc, this)) {
EmitContext ec = new EmitContext (this, ConstructorBuilder.GetILGenerator (), bc.ReturnType);
ec.With (EmitContext.Options.ConstructorScope, true);
if (!ec.HasReturnLabel && bc.HasReturnLabel) {
ec.ReturnLabel = bc.ReturnLabel;
ec.HasReturnLabel = true;
}
block.Emit (ec);
}
}
if (source != null)
source.CloseMethod ();
if (declarative_security != null) {
foreach (var de in declarative_security) {
ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value);
}
}
block = null;
}
示例8: Resolve
public override bool Resolve (EmitContext ec)
{
bool ok = true;
ec.StartFlowBranching (this);
if (!stmt.Resolve (ec))
ok = false;
if (ok)
ec.CurrentBranching.CreateSibling (fini, FlowBranching.SiblingType.Finally);
using (ec.With (EmitContext.Flags.InFinally, true)) {
if (!fini.Resolve (ec))
ok = false;
}
ec.EndFlowBranching ();
ResolveReachability (ec);
return ok;
}
示例9: Resolve
public bool Resolve (EmitContext ec, Location loc)
{
if (Expr == null)
return false;
using (ec.With (EmitContext.Flags.DoFlowAnalysis, true)) {
// Verify that the argument is readable
if (ArgType != AType.Out)
Expr = Expr.Resolve (ec);
// Verify that the argument is writeable
if (Expr != null && (ArgType == AType.Out || ArgType == AType.Ref))
Expr = Expr.ResolveLValue (ec, EmptyExpression.OutAccess, loc);
return Expr != null;
}
}
示例10: DoEmit
protected override void DoEmit (EmitContext ec)
{
using (ec.With (EmitContext.Flags.InUnsafe, true))
Block.Emit (ec);
}
示例11: EmitCallWithInvoke
protected void EmitCallWithInvoke (EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
{
var module = ec.Module;
var site_container = ec.CreateDynamicSite ();
BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void);
FieldExpr site_field_expr = null;
StatementExpression s = null;
// create call site
var call_site = binder;
if (call_site != null) {
// resolve call site
call_site = call_site.Resolve(bc);
// create field for call site
var site_type_decl = call_site.Type;
var field = site_container.CreateCallSiteField (new TypeExpression(site_type_decl, loc), loc);
if (field == null) {
throw new InvalidOperationException("Could not create call site field");
}
// ???
bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired;
// ???
TypeSpec gt;
if (inflate_using_mvar || context_mvars == null) {
gt = site_container.CurrentType;
} else {
gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Types);
}
// When site container already exists the inflated version has to be
// updated manually to contain newly created field
if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) {
var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes;
var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments);
gt.MemberCache.AddMember (field.InflateMember (inflator));
}
site_field_expr = new FieldExpr (MemberCache.GetMember (gt, field), loc);
s = new StatementExpression (new SimpleAssign (site_field_expr, call_site));
}
using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) {
if (s!= null && s.Resolve (bc)) {
Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
init.Emit (ec);
}
// remove dynamics from argument list
arguments.CastDynamicArgs(bc);
IDynamicCallSite dynamicCallSite = (IDynamicCallSite)this.binder;
Expression target = dynamicCallSite.InvokeCallSite(bc, site_field_expr, arguments, type, isStatement);
if (target != null)
target = target.Resolve(bc);
if (target != null)
{
var statement = target as ExpressionStatement;
if (isStatement && statement != null)
{
statement.EmitStatement(ec);
}
else
{
if (!isStatement && (target.Type != type)) {
// PlayScript: If doing an invoke, we have to cast the return type to the type expected by the expression..
target = new Cast(new TypeExpression(type, loc), target, loc).Resolve (bc);
}
target.Emit(ec);
}
}
}
}
示例12: Emit
public override void Emit (EmitContext ec)
{
using (ec.With (EmitContext.Flags.AllCheckStateFlags, true))
Expr.Emit (ec);
}
示例13: Emit
//
// Emits the code
//
public override void Emit ()
{
if (Parent.PartialContainer.IsComImport) {
if (!IsDefault ()) {
Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
Parent.GetSignatureForError ());
}
// Set as internal implementation and reset block data
// to ensure no IL is generated
ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
block = null;
}
if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (ConstructorBuilder);
if (OptAttributes != null)
OptAttributes.Emit ();
base.Emit ();
parameters.ApplyAttributes (this, ConstructorBuilder);
BlockContext bc = new BlockContext (this, block, Compiler.BuiltinTypes.Void);
bc.Set (ResolveContext.Options.ConstructorScope);
//
// If we use a "this (...)" constructor initializer, then
// do not emit field initializers, they are initialized in the other constructor
//
if (!(Initializer is ConstructorThisInitializer))
Parent.PartialContainer.ResolveFieldInitializers (bc);
if (block != null) {
if (!IsStatic) {
if (Initializer == null) {
if (Parent.PartialContainer.Kind == MemberKind.Struct) {
//
// If this is a non-static `struct' constructor and doesn't have any
// initializer, it must initialize all of the struct's fields.
//
block.AddThisVariable (bc);
} else if (Parent.PartialContainer.Kind == MemberKind.Class) {
Initializer = new GeneratedBaseInitializer (Location);
}
}
if (Initializer != null) {
//
// Use location of the constructor to emit sequence point of initializers
// at beginning of constructor name
//
// TODO: Need to extend mdb to support line regions to allow set a breakpoint at
// initializer
//
block.AddScopeStatement (new StatementExpression (Initializer, Location));
}
}
if (block.Resolve (null, bc, this)) {
EmitContext ec = new EmitContext (this, ConstructorBuilder.GetILGenerator (), bc.ReturnType);
ec.With (EmitContext.Options.ConstructorScope, true);
SourceMethod source = SourceMethod.Create (Parent, ConstructorBuilder);
block.Emit (ec);
if (source != null)
source.CloseMethod ();
}
}
if (declarative_security != null) {
foreach (var de in declarative_security) {
#if STATIC
ConstructorBuilder.__AddDeclarativeSecurity (de);
#else
ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value);
#endif
}
}
block = null;
}
示例14: CreateExpressionTree
public override Expression CreateExpressionTree (EmitContext ec)
{
using (ec.With (EmitContext.Flags.AllCheckStateFlags, false))
return Expr.CreateExpressionTree (ec);
}
示例15: DoEmit
protected override void DoEmit (EmitContext ec)
{
using (ec.With (EmitContext.Options.AllCheckStateFlags, true))
Block.Emit (ec);
}