本文整理汇总了C#中Mono.CSharp.BlockContext类的典型用法代码示例。如果您正苦于以下问题:C# BlockContext类的具体用法?C# BlockContext怎么用?C# BlockContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockContext类属于Mono.CSharp命名空间,在下文中一共展示了BlockContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve
public override bool Resolve (BlockContext ec)
{
expr = expr.Resolve (ec);
if (expr == null)
return false;
Report.Debug (64, "RESOLVE YIELD #1", this, ec, expr, expr.GetType (),
ec.CurrentAnonymousMethod, ec.CurrentIterator);
if (!CheckContext (ec, loc))
return false;
iterator = ec.CurrentIterator;
if (expr.Type != iterator.OriginalIteratorType) {
expr = Convert.ImplicitConversionRequired (
ec, expr, iterator.OriginalIteratorType, loc);
if (expr == null)
return false;
}
if (!ec.CurrentBranching.CurrentUsageVector.IsUnreachable)
unwind_protect = ec.CurrentBranching.AddResumePoint (this, loc, out resume_pc);
return true;
}
示例2: CreateExpressionTree
protected override Expression CreateExpressionTree (ResolveContext ec, Type delegate_type)
{
if (ec.IsInProbingMode)
return this;
BlockContext bc = new BlockContext (ec.MemberContext, ec.CurrentBlock.Explicit, TypeManager.void_type);
Expression args = Parameters.CreateExpressionTree (bc, loc);
Expression expr = Block.CreateExpressionTree (ec);
if (expr == null)
return null;
Arguments arguments = new Arguments (2);
arguments.Add (new Argument (expr));
arguments.Add (new Argument (args));
return CreateExpressionFactoryCall (ec, "Lambda",
new TypeArguments (new TypeExpression (delegate_type, loc)),
arguments);
}
示例3: DoResolve
protected override bool DoResolve(BlockContext ec)
{
//
// When delegate returns void, only expression statements can be used
//
if (ec.ReturnType == TypeManager.void_type) {
Expr = Expr.Resolve (ec);
if (Expr == null)
return false;
statement = Expr as ExpressionStatement;
if (statement == null)
Expr.Error_InvalidExpressionStatement (ec);
return true;
}
return base.DoResolve (ec);
}
示例4: ResolveUnreachable
/// <summary>
/// We already know that the statement is unreachable, but we still
/// need to resolve it to catch errors.
/// </summary>
public virtual bool ResolveUnreachable (BlockContext ec, bool warn)
{
//
// This conflicts with csc's way of doing this, but IMHO it's
// the right thing to do.
//
// If something is unreachable, we still check whether it's
// correct. This means that you cannot use unassigned variables
// in unreachable code, for instance.
//
if (warn)
ec.Report.Warning (162, 2, loc, "Unreachable code detected");
ec.StartFlowBranching (FlowBranching.BranchingType.Block, loc);
bool ok = Resolve (ec);
ec.KillFlowBranching ();
return ok;
}
示例5: CreateExpressionTree
protected override Expression CreateExpressionTree (ResolveContext ec, TypeSpec delegate_type)
{
if (ec.IsInProbingMode)
return this;
BlockContext bc = new BlockContext (ec.MemberContext, ec.ConstructorBlock, ec.BuiltinTypes.Void) {
CurrentAnonymousMethod = ec.CurrentAnonymousMethod
};
Expression args = Parameters.CreateExpressionTree (bc, loc);
Expression expr = Block.CreateExpressionTree (ec);
if (expr == null)
return null;
Arguments arguments = new Arguments (2);
arguments.Add (new Argument (expr));
arguments.Add (new Argument (args));
return CreateExpressionFactoryCall (ec, "Lambda",
new TypeArguments (new TypeExpression (delegate_type, loc)),
arguments);
}
示例6: FieldInitializerContext
public FieldInitializerContext (IMemberContext mc, BlockContext constructorContext)
: base (mc, null, constructorContext.ReturnType)
{
flags |= Options.FieldInitializerScope | Options.ConstructorScope;
this.ctor_block = constructorContext.CurrentBlock.Explicit;
}
示例7: GetCompletions
public string [] GetCompletions (string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
lock (evaluator_lock){
if (!inited)
Init ();
bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){
return null;
}
Class parser_result = parser.InteractiveResult;
#if NET_4_0
var access = AssemblyBuilderAccess.RunAndCollect;
#else
var access = AssemblyBuilderAccess.Run;
#endif
var a = new AssemblyDefinitionDynamic (module, "completions");
a.Create (AppDomain.CurrentDomain, access);
module.SetDeclaringAssembly (a);
// Need to setup MemberCache
parser_result.CreateContainer ();
var method = parser_result.Members[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
try {
method.Block.Resolve (null, bc, method);
} catch (CompletionResult cr) {
prefix = cr.BaseText;
return cr.Result;
}
}
return null;
}
示例8: GetCompletions
public static string [] GetCompletions (string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
lock (evaluator_lock){
if (!inited)
Init ();
bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){
if (CSharpParser.yacc_verbose_flag != 0)
Console.WriteLine ("DEBUG: No completions available");
return null;
}
Class parser_result = parser.InteractiveResult;
try {
var a = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp");
a.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run);
RootContext.ToplevelTypes.SetDeclaringAssembly (a);
RootContext.ToplevelTypes.CreateType ();
RootContext.ToplevelTypes.Define ();
parser_result.CreateType ();
parser_result.Define ();
if (ctx.Report.Errors != 0)
return null;
MethodOrOperator method = null;
foreach (MemberCore member in parser_result.Methods){
if (member.Name != "Host")
continue;
method = (MethodOrOperator) member;
break;
}
if (method == null)
throw new InternalErrorException ("did not find the the Host method");
BlockContext bc = new BlockContext (method, method.Block, method.ReturnType);
try {
method.Block.Resolve (null, bc, method);
} catch (CompletionResult cr){
prefix = cr.BaseText;
return cr.Result;
}
} finally {
parser.undo.ExecuteUndo ();
}
}
return null;
}
示例9: EmitCall
protected void EmitCall(EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
{
int dyn_args_count = arguments == null ? 0 : arguments.Count;
TypeExpr site_type = CreateSiteType (RootContext.ToplevelTypes.Compiler, arguments, dyn_args_count, isStatement);
FieldExpr site_field_expr = new FieldExpr (CreateSiteField (site_type), loc);
SymbolWriter.OpenCompilerGeneratedBlock (ec);
Arguments args = new Arguments (1);
args.Add (new Argument (binder));
StatementExpression s = new StatementExpression (new SimpleAssign (site_field_expr, new Invocation (new MemberAccess (site_type, "Create"), args)));
BlockContext bc = new BlockContext (ec.MemberContext, null, TypeManager.void_type);
if (s.Resolve (bc)) {
Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc), loc), s, loc);
init.Emit (ec);
}
args = new Arguments (1 + dyn_args_count);
args.Add (new Argument (site_field_expr));
if (arguments != null) {
foreach (Argument a in arguments) {
if (a is NamedArgument) {
// Name is not valid in this context
args.Add (new Argument (a.Expr, a.ArgType));
continue;
}
args.Add (a);
}
}
Expression target = new DelegateInvocation (new MemberAccess (site_field_expr, "Target", loc).Resolve (bc), args, loc).Resolve (bc);
if (target != null)
target.Emit (ec);
SymbolWriter.CloseCompilerGeneratedBlock (ec);
}
示例10: ResolveFieldInitializers
public void ResolveFieldInitializers (BlockContext ec)
{
Debug.Assert (!IsPartialPart);
if (ec.IsStatic) {
if (initialized_static_fields == null)
return;
bool has_complex_initializer = !ec.Module.Compiler.Settings.Optimize;
int i;
ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
for (i = 0; i < initialized_static_fields.Count; ++i) {
FieldInitializer fi = initialized_static_fields [i];
ExpressionStatement s = fi.ResolveStatement (ec);
if (s == null) {
s = EmptyExpressionStatement.Instance;
} else if (!fi.IsSideEffectFree) {
has_complex_initializer = true;
}
init [i] = s;
}
for (i = 0; i < initialized_static_fields.Count; ++i) {
FieldInitializer fi = initialized_static_fields [i];
//
// Need special check to not optimize code like this
// static int a = b = 5;
// static int b = 0;
//
if (!has_complex_initializer && fi.IsDefaultInitializer)
continue;
ec.AssignmentInfoOffset += fi.AssignmentOffset;
ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
}
return;
}
if (initialized_fields == null)
return;
for (int i = 0; i < initialized_fields.Count; ++i) {
FieldInitializer fi = initialized_fields [i];
//
// Clone before resolving otherwise when field initializer is needed
// in more than 1 constructor any resolve after the initial one would
// only took the resolved expression which is problem for expressions
// that generate extra expressions or code during Resolve phase
//
var cloned = fi.Clone (new CloneContext ());
ExpressionStatement s = fi.ResolveStatement (ec);
if (s == null) {
initialized_fields [i] = new FieldInitializer (fi.Field, ErrorExpression.Instance, Location.Null);
continue;
}
//
// Field is re-initialized to its default value => removed
//
if (fi.IsDefaultInitializer && Kind != MemberKind.Struct && ec.Module.Compiler.Settings.Optimize)
continue;
ec.AssignmentInfoOffset += fi.AssignmentOffset;
ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
initialized_fields [i] = (FieldInitializer) cloned;
}
}
示例11: CreateExpressionTreeVariable
public ExpressionStatement CreateExpressionTreeVariable (BlockContext ec)
{
if ((modFlags & Modifier.RefOutMask) != 0)
ec.Report.Error (1951, Location, "An expression tree parameter cannot use `ref' or `out' modifier");
expr_tree_variable = TemporaryVariableReference.Create (ResolveParameterExpressionType (ec, Location).Type, ec.CurrentBlock.ParametersBlock, Location);
expr_tree_variable = (TemporaryVariableReference) expr_tree_variable.Resolve (ec);
Arguments arguments = new Arguments (2);
arguments.Add (new Argument (new TypeOf (parameter_type, Location)));
arguments.Add (new Argument (new StringConstant (ec.BuiltinTypes, Name, Location)));
return new SimpleAssign (ExpressionTreeVariableReference (),
Expression.CreateExpressionFactoryCall (ec, "Parameter", null, arguments, Location));
}
示例12: Emit
//
// Emits the code
//
public void Emit (TypeDefinition parent)
{
DefineOverride (parent);
var mc = (IMemberContext) method;
method.ParameterInfo.ApplyAttributes (mc, MethodBuilder);
ToplevelBlock block = method.Block;
if (block != null) {
BlockContext bc = new BlockContext (mc, block, method.ReturnType);
if (block.Resolve (null, bc, method)) {
debug_builder = member.Parent.CreateMethodSymbolEntry ();
EmitContext ec = method.CreateEmitContext (MethodBuilder.GetILGenerator (), debug_builder);
block.Emit (ec);
}
}
}
示例13: 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;
var am = this as AnonymousMethodBody;
if (ec.HasSet (ResolveContext.Options.InferReturnType) && am != null) {
am.ReturnTypeInference = new TypeInferenceContext ();
}
var bc = ec as BlockContext;
if (bc != null) {
aec.AssignmentInfoOffset = bc.AssignmentInfoOffset;
aec.EnclosingLoop = bc.EnclosingLoop;
aec.EnclosingLoopOrSwitch = bc.EnclosingLoopOrSwitch;
aec.Switch = bc.Switch;
}
var errors = ec.Report.Errors;
bool res = Block.Resolve (aec);
if (res && errors == ec.Report.Errors) {
MarkReachable (new Reachability ());
if (!CheckReachableExit (ec.Report)) {
return null;
}
if (bc != null)
bc.AssignmentInfoOffset = aec.AssignmentInfoOffset;
}
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 and the body of F is either an expression classified as nothing
// or a statement block where no return statements have expressions, the inferred return type is Task
// If e is async and has an inferred result type T, the inferred return type is Task<T>
//
if (block.IsAsync && ReturnType != null) {
ReturnType = ReturnType.Kind == MemberKind.Void ?
ec.Module.PredefinedTypes.Task.TypeSpec :
ec.Module.PredefinedTypes.TaskGeneric.TypeSpec.MakeGenericType (ec, new [] { ReturnType });
}
}
if (res && errors != ec.Report.Errors)
return null;
return res ? this : null;
}
示例14: CreateExpressionTree
public Expression CreateExpressionTree (BlockContext ec, Location loc)
{
var initializers = new ArrayInitializer (Count, loc);
foreach (Parameter p in FixedParameters) {
//
// Each parameter expression is stored to local variable
// to save some memory when referenced later.
//
StatementExpression se = new StatementExpression (p.CreateExpressionTreeVariable (ec), Location.Null);
if (se.Resolve (ec)) {
ec.CurrentBlock.AddScopeStatement (new TemporaryVariableReference.Declarator (p.ExpressionTreeVariableReference ()));
ec.CurrentBlock.AddScopeStatement (se);
}
initializers.Add (p.ExpressionTreeVariableReference ());
}
return new ArrayCreation (
Parameter.ResolveParameterExpressionType (ec, loc),
initializers, loc);
}
示例15: GetCompletions
public static string [] GetCompletions (string input, out string prefix)
{
prefix = "";
if (input == null || input.Length == 0)
return null;
lock (evaluator_lock){
if (!inited)
Init ();
bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){
if (CSharpParser.yacc_verbose_flag != 0)
Console.WriteLine ("DEBUG: No completions available");
return null;
}
Class parser_result = parser.InteractiveResult as Class;
if (parser_result == null){
if (CSharpParser.yacc_verbose_flag != 0)
Console.WriteLine ("Do not know how to cope with !Class yet");
return null;
}
try {
RootContext.ResolveTree ();
if (ctx.Report.Errors != 0)
return null;
RootContext.PopulateTypes ();
if (ctx.Report.Errors != 0)
return null;
MethodOrOperator method = null;
foreach (MemberCore member in parser_result.Methods){
if (member.Name != "Host")
continue;
method = (MethodOrOperator) member;
break;
}
if (method == null)
throw new InternalErrorException ("did not find the the Host method");
BlockContext bc = new BlockContext (method, method.Block, method.ReturnType);
try {
method.Block.Resolve (null, bc, method);
} catch (CompletionResult cr){
prefix = cr.BaseText;
return cr.Result;
}
} finally {
parser.undo.ExecuteUndo ();
}
}
return null;
}