本文整理汇总了C#中IronPython.Compiler.Ast.AstGenerator.UpdateLineUpdated方法的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator.UpdateLineUpdated方法的具体用法?C# AstGenerator.UpdateLineUpdated怎么用?C# AstGenerator.UpdateLineUpdated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Compiler.Ast.AstGenerator
的用法示例。
在下文中一共展示了AstGenerator.UpdateLineUpdated方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.Expression raiseExpression;
if (_type == null && _value == null && _traceback == null) {
raiseExpression = Ast.Call(
AstGenerator.GetHelperMethod("MakeRethrownException"),
ag.LocalContext
);
if (!ag._isEmittingFinally) {
raiseExpression = Ast.Block(
ag.UpdateLineUpdated(true),
raiseExpression
);
}
} else {
raiseExpression = Ast.Call(
AstGenerator.GetHelperMethod("MakeException"),
ag.LocalContext,
ag.TransformOrConstantNull(_type, typeof(object)),
ag.TransformOrConstantNull(_value, typeof(object)),
ag.TransformOrConstantNull(_traceback, typeof(object))
);
}
return ag.AddDebugInfo(
Ast.Throw(raiseExpression),
Span
);
}
示例2: TransformToAst
internal ScriptCode/*!*/ TransformToAst(CompilationMode mode, CompilerContext/*!*/ context) {
// Create the ast generator
// Use the PrintExpression value for the body (global level code)
PythonCompilerOptions pco = context.Options as PythonCompilerOptions;
Debug.Assert(pco != null);
string name;
if (!context.SourceUnit.HasPath || (pco.Module & ModuleOptions.ExecOrEvalCode) != 0) {
name = "<module>";
} else {
name = context.SourceUnit.Path;
}
AstGenerator ag = new AstGenerator(mode, context, _body.Span, name, false, _printExpressions);
MSAst.Expression body = Ast.Block(
Ast.Call(
AstGenerator.GetHelperMethod("ModuleStarted"),
ag.LocalContext,
AstUtils.Constant(ag.BinderState, typeof(object)),
AstUtils.Constant(_languageFeatures)
),
ag.UpdateLineNumber(0),
ag.UpdateLineUpdated(false),
ag.WrapScopeStatements(Transform(ag)), // new ComboActionRewriter().VisitNode(Transform(ag))
AstUtils.Empty()
);
if (_isModule) {
string moduleName = pco.ModuleName;
if (moduleName == null) {
#if !SILVERLIGHT
if (context.SourceUnit.HasPath && context.SourceUnit.Path.IndexOfAny(Path.GetInvalidFileNameChars()) == -1) {
moduleName = Path.GetFileNameWithoutExtension(context.SourceUnit.Path);
#else
if (context.SourceUnit.HasPath) {
moduleName = context.SourceUnit.Path;
#endif
} else {
moduleName = "<module>";
}
}
Debug.Assert(moduleName != null);
body = Ast.Block(
ag.Globals.Assign(ag.Globals.GetVariable(ag, _fileVariable), Ast.Constant(name)),
ag.Globals.Assign(ag.Globals.GetVariable(ag, _nameVariable), Ast.Constant(moduleName)),
body // already typed to void
);
if ((pco.Module & ModuleOptions.Initialize) != 0) {
MSAst.Expression tmp = ag.HiddenVariable(typeof(object), "$originalModule");
// TODO: Should be try/fault
body = AstUtils.Try(
Ast.Assign(tmp, Ast.Call(AstGenerator.GetHelperMethod("PublishModule"), ag.LocalContext, Ast.Constant(moduleName))),
body
).Catch(
typeof(Exception),
Ast.Call(AstGenerator.GetHelperMethod("RemoveModule"), ag.LocalContext, Ast.Constant(moduleName), tmp),
Ast.Rethrow(body.Type)
);
}
}
body = ag.AddProfiling(body);
body = ag.AddReturnTarget(body);
if (body.Type == typeof(void)) {
body = Ast.Block(body, Ast.Constant(null));
}
return ag.MakeScriptCode(body, context, this);
}
示例3: AddFinally
private MSAst.Expression AddFinally(AstGenerator/*!*/ ag, MSAst.Expression/*!*/ body, MSAst.ParameterExpression noNestedException) {
if (_finally != null) {
Debug.Assert(noNestedException != null);
MSAst.ParameterExpression nestedFrames = ag.GetTemporary("$nestedFrames", typeof(List<DynamicStackFrame>));
bool inFinally = ag.InFinally;
ag.InFinally = true;
MSAst.Expression @finally = ag.Transform(_finally);
ag.InFinally = inFinally;
if (@finally == null) {
// error reported during compilation
return null;
}
if (ag.TrackLines) {
// lots is going on here. We need to consider:
// 1. Exceptions propagating out of try/except/finally. Here we need to save the line #
// from the exception block and not save the # from the finally block later.
// 2. Exceptions propagating out of the finally block. Here we need to report the line number
// from the finally block and leave the existing stack traces cleared.
// 3. Returning from the try block: Here we need to run the finally block and not update the
// line numbers.
body = AstUtils.Try(// we use a filter to know when we have an exception and when control leaves normally (via
// either a return or the body completing successfully).
AstUtils.Try(
ag.AddDebugInfo(Ast.Empty(), new SourceSpan(Span.Start, _header)),
Ast.Assign(noNestedException, Ast.Constant(true)),
body
).Filter(
typeof(Exception),
// condition is never true, just note the exception and let it propagate
Ast.Equal(
Ast.Assign(noNestedException, Ast.Constant(false)),
Ast.Constant(true)
),
Ast.Default(body.Type)
)
).Finally(
// if we had an exception save the line # that was last executing during the try
AstUtils.If(
Ast.Not(noNestedException),
ag.GetLineNumberUpdateExpression(false)
),
// clear the frames incase thae finally throws, and allow line number
// updates to proceed
ag.UpdateLineUpdated(false),
Ast.Assign(
nestedFrames,
Ast.Call(AstGenerator.GetHelperMethod("GetAndClearDynamicStackFrames"))
),
// run the finally code
@finally,
// if the finally exits normally restore any previous exception info
Ast.Call(
AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
nestedFrames
),
ag.UpdateLineUpdated(true)
);
ag.FreeTemp(nestedFrames);
ag.FreeTemp(noNestedException);
} else {
body = AstUtils.Try(body).Finally(
Ast.Assign(
nestedFrames,
Ast.Call(AstGenerator.GetHelperMethod("GetAndClearDynamicStackFrames"))
),
// run the finally code
@finally,
// if the finally exits normally restore any previous exception info
Ast.Call(
AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
nestedFrames
)
);
}
}
return body;
}
示例4: AddFinally
private MSAst.Expression AddFinally(AstGenerator/*!*/ ag, MSAst.Expression/*!*/ body, MSAst.ParameterExpression nestedException) {
if (_finally != null) {
bool isEmitting = ag._isEmittingFinally;
ag._isEmittingFinally = true;
int loopId = ++ag._loopOrFinallyId;
ag.LoopOrFinallyIds.Add(loopId, true);
try {
Debug.Assert(nestedException != null);
MSAst.ParameterExpression nestedFrames = ag.GetTemporary("$nestedFrames", typeof(List<DynamicStackFrame>));
bool inFinally = ag.InFinally;
ag.InFinally = true;
MSAst.Expression @finally = ag.Transform(_finally);
ag.InFinally = inFinally;
if (@finally == null) {
// error reported during compilation
return null;
}
// lots is going on here. We need to consider:
// 1. Exceptions propagating out of try/except/finally. Here we need to save the line #
// from the exception block and not save the # from the finally block later.
// 2. Exceptions propagating out of the finally block. Here we need to report the line number
// from the finally block and leave the existing stack traces cleared.
// 3. Returning from the try block: Here we need to run the finally block and not update the
// line numbers.
body = AstUtils.Try( // we use a fault to know when we have an exception and when control leaves normally (via
// either a return or the body completing successfully).
AstUtils.Try(
ag.AddDebugInfo(AstUtils.Empty(), new SourceSpan(Span.Start, _header)),
Ast.Assign(nestedException, AstUtils.Constant(false)),
body
).Fault(
// fault
Ast.Assign(nestedException, AstUtils.Constant(true))
)
).FinallyWithJumps(
// if we had an exception save the line # that was last executing during the try
AstUtils.If(
nestedException,
ag.GetSaveLineNumberExpression(false)
),
// clear the frames incase thae finally throws, and allow line number
// updates to proceed
ag.UpdateLineUpdated(false),
Ast.Assign(
nestedFrames,
Ast.Call(AstGenerator.GetHelperMethod("GetAndClearDynamicStackFrames"))
),
// run the finally code
@finally,
// if the finally exits normally restore any previous exception info
Ast.Call(
AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
nestedFrames
),
// if we took an exception in the try block we have saved the line number. Otherwise
// we have no line number saved and will need to continue saving them if
// other exceptions are thrown.
AstUtils.If(
nestedException,
ag.UpdateLineUpdated(true)
)
);
ag.FreeTemp(nestedFrames);
ag.FreeTemp(nestedException);
} finally {
ag._isEmittingFinally = isEmitting;
ag.LoopOrFinallyIds.Remove(loopId);
}
}
return body;
}
示例5: Transform
//.........这里部分代码省略.........
//******************************************************************
MSAst.ParameterExpression exception = ag.GetTemporary("exception", typeof(Exception));
MSAst.ParameterExpression nestedFrames = ag.GetTemporary("$nestedFrames", typeof(List<DynamicStackFrame>));
statements[4] =
// try:
AstUtils.Try(
AstUtils.Try(// try statement body
ag.PushLineUpdated(false, lineUpdated),
_var != null ?
ag.AddDebugInfo(
Ast.Block(
// VAR = value
_var.TransformSet(ag, SourceSpan.None, value, PythonOperationKind.None),
// BLOCK
ag.Transform(_body),
AstUtils.Empty()
),
_body.Span
) :
// BLOCK
ag.Transform(_body) // except:, // try statement location
).Catch(exception,
// Python specific exception handling code
TryStatement.GetTracebackHeader(
ag,
exception,
ag.AddDebugInfo(
Ast.Block(
// exc = False
ag.MakeAssignment(
exc,
AstUtils.Constant(false)
),
Ast.Assign(
nestedFrames,
Ast.Call(AstGenerator.GetHelperMethod("GetAndClearDynamicStackFrames"))
),
// if not exit(*sys.exc_info()):
// raise
AstUtils.IfThen(
ag.Convert(
typeof(bool),
ConversionResultKind.ExplicitCast,
ag.Operation(
typeof(bool),
PythonOperationKind.Not,
MakeExitCall(ag, exit, exception)
)
),
ag.UpdateLineUpdated(true),
Ast.Call(
AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
nestedFrames
),
Ast.Rethrow()
)
),
_body.Span
)
),
Ast.Call(
AstGenerator.GetHelperMethod("SetDynamicStackFrames"),
nestedFrames
),
ag.PopLineUpdated(lineUpdated),
Ast.Empty()
)
// finally:
).Finally(
// if exc:
// exit(None, None, None)
AstUtils.IfThen(
exc,
ag.AddDebugInfo(
Ast.Block(
Ast.Dynamic(
ag.BinderState.Invoke(
new CallSignature(3) // signature doesn't include function
),
typeof(object),
new MSAst.Expression[] {
ag.LocalContext,
exit,
AstUtils.Constant(null),
AstUtils.Constant(null),
AstUtils.Constant(null)
}
),
Ast.Empty()
),
_contextManager.Span
)
)
);
statements[4] = ag.AddDebugInfo(statements[4], Span);
statements[5] = AstUtils.Empty();
return ag.AddDebugInfo(Ast.Block(statements), _body.Span);
}
示例6: TransformToAst
internal MSAst.LambdaExpression/*!*/ TransformToAst(CompilerContext context) {
// Create the ast generator
// Use the PrintExpression value for the body (global level code)
PythonCompilerOptions pco = context.Options as PythonCompilerOptions;
Debug.Assert(pco != null);
string name;
if (!context.SourceUnit.HasPath || (pco.Module & ModuleOptions.ExecOrEvalCode) != 0) {
name = "<module>";
} else {
name = context.SourceUnit.Path;
}
AstGenerator ag = new AstGenerator(context, _body.Span, name, false, _printExpressions);
ag.Block.Global = true;
ag.Block.Body = Ast.Block(
Ast.Call(
AstGenerator.GetHelperMethod("ModuleStarted"),
AstUtils.CodeContext(),
Ast.Constant(ag.BinderState, typeof(object)),
Ast.Constant(_languageFeatures)
),
ag.UpdateLineNumber(0),
ag.UpdateLineUpdated(false),
ag.WrapScopeStatements(Transform(ag)), // new ComboActionRewriter().VisitNode(Transform(ag))
Ast.Empty()
);
if (_isModule) {
Debug.Assert(pco.ModuleName != null);
ag.Block.Body = Ast.Block(
AstUtils.Assign(_fileVariable.Variable, Ast.Constant(name)),
AstUtils.Assign(_nameVariable.Variable, Ast.Constant(pco.ModuleName)),
ag.Block.Body // already typed to void
);
if ((pco.Module & ModuleOptions.Initialize) != 0) {
MSAst.Expression tmp = ag.Block.HiddenVariable(typeof(object), "$originalModule");
// TODO: Should be try/fault
ag.Block.Body = AstUtils.Try(
Ast.Assign(tmp, Ast.Call(AstGenerator.GetHelperMethod("PublishModule"), AstUtils.CodeContext(), Ast.Constant(pco.ModuleName))),
ag.Block.Body
).Catch(
typeof(Exception),
Ast.Call(AstGenerator.GetHelperMethod("RemoveModule"), AstUtils.CodeContext(), Ast.Constant(pco.ModuleName), tmp),
Ast.Rethrow(ag.Block.Body.Type)
);
}
}
ag.Block.Body = ag.AddReturnTarget(ag.Block.Body);
DisableInterpreter = ag.DisableInterpreter;
return ag.Block.MakeLambda();
}