本文整理匯總了C#中Mono.CSharp.BlockContext.Set方法的典型用法代碼示例。如果您正苦於以下問題:C# BlockContext.Set方法的具體用法?C# BlockContext.Set怎麽用?C# BlockContext.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mono.CSharp.BlockContext
的用法示例。
在下文中一共展示了BlockContext.Set方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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 (block != null) {
//
// 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 (!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 &&
!(bc.FileType == SourceFileType.PlayScript && Initializer.IsAsExplicitSuperCall)) {
//
// mdb format does not support reqions. Try to workaround this by emitting the
// sequence point at initializer. Any breakpoint at constructor header should
// be adjusted to this sequence point as it's the next one which follows.
//
block.AddScopeStatement (new StatementExpression (Initializer));
}
}
if (block.Resolve (null, bc, this)) {
debug_builder = Parent.CreateMethodSymbolEntry ();
EmitContext ec = new EmitContext (this, ConstructorBuilder.GetILGenerator (), bc.ReturnType, debug_builder);
ec.With (EmitContext.Options.ConstructorScope, true);
block.Emit (ec);
}
}
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;
}
示例2: EmitJs
public override void EmitJs (JsEmitContext jec)
{
base.EmitJs (jec);
bool is_static = (this.ModFlags & Modifiers.STATIC) != 0;
if (!is_static) {
jec.Buf.Write ("\tfunction " + this.Parent.MemberName.Name + "(", Location);
parameters.EmitJs (jec);
jec.Buf.Write (") ");
}
BlockContext bc = new BlockContext (this, block, Compiler.BuiltinTypes.Void);
bc.Set (ResolveContext.Options.ConstructorScope);
bool emitted_block = false;
if (block != null) {
//
// 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 (!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 &&
!(bc.FileType == SourceFileType.PlayScript && Initializer.IsAsExplicitSuperCall)) {
//
// mdb format does not support reqions. Try to workaround this by emitting the
// sequence point at initializer. Any breakpoint at constructor header should
// be adjusted to this sequence point as it's the next one which follows.
//
block.AddScopeStatement (new StatementExpression (Initializer));
}
}
if (block.Resolve (null, bc, this)) {
block.EmitBlockJs (jec, false, is_static);
emitted_block = true;
}
}
if (!is_static) {
if (!emitted_block)
jec.Buf.Write ("{\n\t}", Location);
jec.Buf.Write ("\n");
}
block = null;
}
示例3: 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;
}
示例4: Compatible
public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae)
{
if (block.Resolved)
return this;
// TODO: Implement clone
BlockContext aec = new BlockContext (ec, block, ReturnType);
aec.CurrentAnonymousMethod = ae;
ResolveContext.Options flags = 0;
var am = this as AnonymousMethodBody;
if (ec.HasSet (ResolveContext.Options.InferReturnType) && am != null) {
am.ReturnTypeInference = new TypeInferenceContext ();
}
if (ec.IsInProbingMode)
flags |= ResolveContext.Options.ProbingMode;
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope))
flags |= ResolveContext.Options.FieldInitializerScope;
if (ec.HasSet (ResolveContext.Options.ExpressionTreeConversion))
flags |= ResolveContext.Options.ExpressionTreeConversion;
aec.Set (flags);
var errors = ec.Report.Errors;
bool res = Block.Resolve (ec.CurrentBranching, aec, null);
if (am != null && am.ReturnTypeInference != null) {
am.ReturnTypeInference.FixAllTypes (ec);
ReturnType = am.ReturnTypeInference.InferredTypeArguments [0];
am.ReturnTypeInference = null;
//
// If e is synchronous the inferred return type is T
// If e is asynchronous the inferred return type is Task<T>
//
if (block.IsAsync && ReturnType != null) {
ReturnType = ec.Module.PredefinedTypes.TaskGeneric.TypeSpec.MakeGenericType (ec, new [] { ReturnType });
}
}
if (res && errors != ec.Report.Errors)
return null;
return res ? this : null;
}
示例5: Resolve
public override bool Resolve (BlockContext ec)
{
using (ec.Set (ResolveContext.Options.UsingInitializerScope)) {
if (decl.Variable == null) {
decl.ResolveExpression (ec);
} else {
if (!decl.Resolve (ec))
return false;
if (decl.Declarators != null) {
stmt = decl.RewriteForDeclarators (ec, stmt);
}
}
}
ec.StartFlowBranching (this);
bool ok = stmt.Resolve (ec);
ec.EndFlowBranching ();
ok &= base.Resolve (ec);
return ok;
}
示例6: Compatible
public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae)
{
if (block.Resolved)
return this;
// TODO: Implement clone
BlockContext aec = new BlockContext (ec.MemberContext, Block, ReturnType);
aec.CurrentAnonymousMethod = ae;
ResolveContext.FlagsHandle? aec_dispose = null;
ResolveContext.Options flags = 0;
var am = this as AnonymousMethodBody;
if (ec.HasSet (ResolveContext.Options.InferReturnType) && am != null) {
am.ReturnTypeInference = new TypeInferenceContext ();
}
if (ec.IsInProbingMode)
flags |= ResolveContext.Options.ProbingMode;
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope))
flags |= ResolveContext.Options.FieldInitializerScope;
if (ec.IsUnsafe)
flags |= ResolveContext.Options.UnsafeScope;
if (ec.HasSet (ResolveContext.Options.CheckedScope))
flags |= ResolveContext.Options.CheckedScope;
if (ec.HasSet (ResolveContext.Options.ExpressionTreeConversion))
flags |= ResolveContext.Options.ExpressionTreeConversion;
// HACK: Flag with 0 cannot be set
if (flags != 0)
aec_dispose = aec.Set (flags);
var errors = ec.Report.Errors;
bool res = Block.Resolve (ec.CurrentBranching, aec, Block.Parameters, null);
if (aec.HasReturnLabel)
return_label = aec.ReturnLabel;
if (am != null && am.ReturnTypeInference != null) {
am.ReturnTypeInference.FixAllTypes (ec);
ReturnType = am.ReturnTypeInference.InferredTypeArguments [0];
am.ReturnTypeInference = null;
}
if (aec_dispose != null) {
aec_dispose.Value.Dispose ();
}
if (res && errors != ec.Report.Errors)
return null;
return res ? this : null;
}
示例7: Resolve
public override bool Resolve (BlockContext ec)
{
if (!ec.IsUnsafe){
Expression.UnsafeError (ec, loc);
return false;
}
TypeExpr texpr = type.ResolveAsContextualType (ec, false);
if (texpr == null) {
if (type is VarExpr)
ec.Report.Error (821, type.Location, "A fixed statement cannot use an implicitly typed local variable");
return false;
}
expr_type = texpr.Type;
data = new Emitter [declarators.Count];
if (!expr_type.IsPointer){
ec.Report.Error (209, loc, "The type of locals declared in a fixed statement must be a pointer type");
return false;
}
int i = 0;
foreach (var p in declarators){
LocalInfo vi = p.Key;
Expression e = p.Value;
vi.VariableInfo.SetAssigned (ec);
vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
//
// The rules for the possible declarators are pretty wise,
// but the production on the grammar is more concise.
//
// So we have to enforce these rules here.
//
// We do not resolve before doing the case 1 test,
// because the grammar is explicit in that the token &
// is present, so we need to test for this particular case.
//
if (e is Cast){
ec.Report.Error (254, loc, "The right hand side of a fixed statement assignment may not be a cast expression");
return false;
}
using (ec.Set (ResolveContext.Options.FixedInitializerScope)) {
e = e.Resolve (ec);
}
if (e == null)
return false;
//
// Case 2: Array
//
if (e.Type.IsArray){
TypeSpec array_type = TypeManager.GetElementType (e.Type);
//
// Provided that array_type is unmanaged,
//
if (!TypeManager.VerifyUnmanaged (ec.Compiler, array_type, loc))
return false;
//
// and T* is implicitly convertible to the
// pointer type given in the fixed statement.
//
ArrayPtr array_ptr = new ArrayPtr (e, array_type, loc);
Expression converted = Convert.ImplicitConversionRequired (
ec, array_ptr, vi.VariableType, loc);
if (converted == null)
return false;
//
// fixed (T* e_ptr = (e == null || e.Length == 0) ? null : converted [0])
//
converted = new Conditional (new BooleanExpression (new Binary (Binary.Operator.LogicalOr,
new Binary (Binary.Operator.Equality, e, new NullLiteral (loc), loc),
new Binary (Binary.Operator.Equality, new MemberAccess (e, "Length"), new IntConstant (0, loc), loc), loc)),
new NullPointer (loc),
converted, loc);
converted = converted.Resolve (ec);
data [i] = new ExpressionEmitter (converted, vi);
i++;
continue;
}
//
// Case 3: string
//
if (e.Type == TypeManager.string_type){
data [i] = new StringEmitter (e, vi, loc).Resolve (ec);
//.........這裏部分代碼省略.........
示例8: Compatible
public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae)
{
if (block.Resolved)
return this;
// TODO: Implement clone
BlockContext aec = new BlockContext (ec, block, ReturnType);
aec.CurrentAnonymousMethod = ae;
ResolveContext.Options flags = 0;
var am = this as AnonymousMethodBody;
if (ec.HasSet (ResolveContext.Options.InferReturnType) && am != null) {
am.ReturnTypeInference = new TypeInferenceContext ();
}
if (ec.IsInProbingMode)
flags |= ResolveContext.Options.ProbingMode;
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope))
flags |= ResolveContext.Options.FieldInitializerScope;
if (ec.HasSet (ResolveContext.Options.ExpressionTreeConversion))
flags |= ResolveContext.Options.ExpressionTreeConversion;
aec.Set (flags);
var errors = ec.Report.Errors;
bool res = Block.Resolve (ec.CurrentBranching, aec, null);
if (aec.HasReturnLabel)
return_label = aec.ReturnLabel;
if (am != null && am.ReturnTypeInference != null) {
am.ReturnTypeInference.FixAllTypes (ec);
ReturnType = am.ReturnTypeInference.InferredTypeArguments [0];
am.ReturnTypeInference = null;
}
if (res && errors != ec.Report.Errors)
return null;
return res ? this : null;
}
示例9: Resolve
public override bool Resolve (BlockContext ec)
{
VariableReference vr;
bool vr_locked = false;
using (ec.Set (ResolveContext.Options.UsingInitializerScope)) {
if (decl.Variable == null) {
vr = decl.ResolveExpression (ec) as VariableReference;
if (vr != null) {
vr_locked = vr.IsLockedByStatement;
vr.IsLockedByStatement = true;
}
} else {
if (!decl.Resolve (ec))
return false;
if (decl.Declarators != null) {
stmt = decl.RewriteForDeclarators (ec, stmt);
}
vr = null;
}
}
ec.StartFlowBranching (this);
stmt.Resolve (ec);
ec.EndFlowBranching ();
if (vr != null)
vr.IsLockedByStatement = vr_locked;
base.Resolve (ec);
return true;
}
示例10: 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;
}
示例11: Compatible
public bool Compatible (ResolveContext ec)
{
// TODO: Implement clone
BlockContext aec = new BlockContext (ec.MemberContext, Block, ReturnType);
aec.CurrentAnonymousMethod = this;
IDisposable aec_dispose = null;
ResolveContext.Options flags = 0;
if (ec.HasSet (ResolveContext.Options.InferReturnType)) {
flags |= ResolveContext.Options.InferReturnType;
aec.ReturnTypeInference = new TypeInferenceContext ();
}
if (ec.IsInProbingMode)
flags |= ResolveContext.Options.ProbingMode;
if (ec.HasSet (ResolveContext.Options.FieldInitializerScope))
flags |= ResolveContext.Options.FieldInitializerScope;
if (ec.IsUnsafe)
flags |= ResolveContext.Options.UnsafeScope;
if (ec.HasSet (ResolveContext.Options.CheckedScope))
flags |= ResolveContext.Options.CheckedScope;
// HACK: Flag with 0 cannot be set
if (flags != 0)
aec_dispose = aec.Set (flags);
bool res = Block.Resolve (ec.CurrentBranching, aec, Block.Parameters, null);
if (aec.HasReturnLabel)
return_label = aec.ReturnLabel;
if (ec.HasSet (ResolveContext.Options.InferReturnType)) {
aec.ReturnTypeInference.FixAllTypes (ec);
ReturnType = aec.ReturnTypeInference.InferredTypeArguments [0];
}
if (aec_dispose != null) {
aec_dispose.Dispose ();
}
return res;
}