本文整理汇总了C#中IronPython.Compiler.Ast.AstGenerator.AddDebugInfoAndVoid方法的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator.AddDebugInfoAndVoid方法的具体用法?C# AstGenerator.AddDebugInfoAndVoid怎么用?C# AstGenerator.AddDebugInfoAndVoid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Compiler.Ast.AstGenerator
的用法示例。
在下文中一共展示了AstGenerator.AddDebugInfoAndVoid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformSet
internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
if (op == Operators.None) {
return ag.AddDebugInfoAndVoid(
Binders.Set(
ag.BinderState,
typeof(object),
SymbolTable.IdToString(_name),
ag.Transform(_target),
right
),
span
);
} else {
MSAst.ParameterExpression temp = ag.GetTemporary("inplace");
return ag.AddDebugInfo(
Ast.Block(
Ast.Assign(temp, ag.Transform(_target)),
SetMemberOperator(ag, right, op, temp),
Ast.Empty()
),
Span.Start,
span.End
);
}
}
示例2: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>();
for (int i = 0; i < _names.Length; i++) {
statements.Add(
// _references[i] = PythonOps.Import(<code context>, _names[i])
ag.AddDebugInfoAndVoid(
GlobalAllocator.Assign(
ag.Globals.GetVariable(ag, _variables[i]),
Ast.Call(
AstGenerator.GetHelperMethod( // helper
_asNames[i] == null ? "ImportTop" : "ImportBottom"
),
ag.LocalContext, // 1st arg - code context
AstUtils.Constant(_names[i].MakeString()), // 2nd arg - module name
AstUtils.Constant(_forceAbsolute ? 0 : -1) // 3rd arg - absolute or relative imports
)
),
_names[i].Span
)
);
}
statements.Add(AstUtils.Empty());
return ag.AddDebugInfo(Ast.Block(statements.ToReadOnlyCollection()), Span);
}
示例3: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.Expression result;
if (_else != null) {
result = ag.Transform(_else);
} else {
result = AstUtils.Empty();
}
// Now build from the inside out
int i = _tests.Length;
while (i-- > 0) {
IfStatementTest ist = _tests[i];
result = ag.AddDebugInfoAndVoid(
Ast.Condition(
ag.TransformAndDynamicConvert(ist.Test, typeof(bool)),
ag.TransformMaybeSingleLineSuite(ist.Body, ist.Test.Start),
result
),
new SourceSpan(ist.Start, ist.Header)
);
}
return result;
}
示例4: Transform
internal override MSAst.Expression Transform(AstGenerator ag, MSAst.Expression body) {
return ag.AddDebugInfoAndVoid(
AstUtils.If(
ag.TransformAndDynamicConvert(_test, typeof(bool)),
body
),
Span
);
}
示例5: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.Expression expression = ag.Transform(_expression);
if (ag.PrintExpressions) {
expression = Ast.Call(
AstGenerator.GetHelperMethod("PrintExpressionValue"),
ag.LocalContext,
AstGenerator.ConvertIfNeeded(expression, typeof(object))
);
}
return ag.AddDebugInfoAndVoid(expression, _expression.Span);
}
示例6: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
// Only the body is "in the loop" for the purposes of break/continue
// The "else" clause is outside
MSAst.LabelTarget breakLabel, continueLabel;
ConstantExpression constTest = _test as ConstantExpression;
if (constTest != null && constTest.Value is int) {
// while 0: / while 1:
int val = (int)constTest.Value;
if (val == 0) {
// completely optimize the loop away
if (_else == null) {
return MSAst.Expression.Empty();
} else {
return ag.Transform(_else);
}
}
MSAst.Expression test = MSAst.Expression.Constant(true);
MSAst.Expression res = AstUtils.While(
test,
ag.TransformLoopBody(_body, SourceLocation.Invalid, out breakLabel, out continueLabel),
ag.Transform(_else),
breakLabel,
continueLabel
);
if (_test.Start.Line != _body.Start.Line) {
res = ag.AddDebugInfoAndVoid(res, _test.Span);
}
return res;
}
return AstUtils.While(
ag.AddDebugInfo(
ag.TransformAndDynamicConvert(_test, typeof(bool)),
Header
),
ag.TransformLoopBody(_body, _test.Start, out breakLabel, out continueLabel),
ag.Transform(_else),
breakLabel,
continueLabel
);
}
示例7: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
// If debugging is off, return empty statement
if (ag.Optimize) {
return AstUtils.Empty();
}
// Transform into:
// if (_test) {
// } else {
// RaiseAssertionError(_message);
// }
return ag.AddDebugInfoAndVoid(
AstUtils.Unless( // if
ag.TransformAndDynamicConvert(_test, typeof(bool)), // _test
Ast.Call( // else branch
AstGenerator.GetHelperMethod("RaiseAssertionError"),
ag.TransformOrConstantNull(_message, typeof(object))
)
),
Span
);
}
示例8: TransformSet
internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, PythonOperationKind op) {
if (op == PythonOperationKind.None) {
return ag.AddDebugInfoAndVoid(
ag.Set(
typeof(object),
_name,
ag.Transform(_target),
right
),
span
);
} else {
MSAst.ParameterExpression temp = ag.GetTemporary("inplace");
return ag.AddDebugInfo(
Ast.Block(
Ast.Assign(temp, ag.Transform(_target)),
SetMemberOperator(ag, right, op, temp),
AstUtils.Empty()
),
Span.Start,
span.End
);
}
}
示例9: Transform
/// <summary>
/// WithStatement is translated to the DLR AST equivalent to
/// the following Python code snippet (from with statement spec):
///
/// mgr = (EXPR)
/// exit = mgr.__exit__ # Not calling it yet
/// value = mgr.__enter__()
/// exc = True
/// try:
/// VAR = value # Only if "as VAR" is present
/// BLOCK
/// except:
/// # The exceptional case is handled here
/// exc = False
/// if not exit(*sys.exc_info()):
/// raise
/// # The exception is swallowed if exit() returns true
/// finally:
/// # The normal and non-local-goto cases are handled here
/// if exc:
/// exit(None, None, None)
///
/// </summary>
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.ParameterExpression lineUpdated = ag.GetTemporary("$lineUpdated_with", typeof(bool));
// Five statements in the result...
ReadOnlyCollectionBuilder<MSAst.Expression> statements = new ReadOnlyCollectionBuilder<MSAst.Expression>(6);
//******************************************************************
// 1. mgr = (EXPR)
//******************************************************************
MSAst.ParameterExpression manager = ag.GetTemporary("with_manager");
statements.Add(
ag.MakeAssignment(
manager,
ag.Transform(_contextManager),
new SourceSpan(Start, _header)
)
);
//******************************************************************
// 2. exit = mgr.__exit__ # Not calling it yet
//******************************************************************
MSAst.ParameterExpression exit = ag.GetTemporary("with_exit");
statements.Add(
AstGenerator.MakeAssignment(
exit,
ag.Get(
typeof(object),
"__exit__",
manager
)
)
);
//******************************************************************
// 3. value = mgr.__enter__()
//******************************************************************
MSAst.ParameterExpression value = ag.GetTemporary("with_value");
statements.Add(
ag.AddDebugInfoAndVoid(
AstGenerator.MakeAssignment(
value,
ag.Invoke(
typeof(object),
new CallSignature(0),
ag.Get(
typeof(object),
"__enter__",
manager
)
)
),
new SourceSpan(Start, _header)
)
);
//******************************************************************
// 4. exc = True
//******************************************************************
MSAst.ParameterExpression exc = ag.GetTemporary("with_exc", typeof(bool));
statements.Add(
AstGenerator.MakeAssignment(
exc,
AstUtils.Constant(true)
)
);
//******************************************************************
// 5. The final try statement:
//
// try:
// VAR = value # Only if "as VAR" is present
// BLOCK
// except:
// # The exceptional case is handled here
// exc = False
// if not exit(*sys.exc_info()):
// raise
//.........这里部分代码省略.........
示例10: TransformSet
internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
if (op != Operators.None) {
right = Binders.Operation(
ag.BinderState,
typeof(object),
StandardOperators.FromOperator(op),
Binders.Operation(
ag.BinderState,
typeof(object),
GetOperatorString,
ArrayUtils.RemoveFirst(GetActionArgumentsForGetOrDelete(ag))
),
right
);
}
return ag.AddDebugInfoAndVoid(
Binders.Operation(
ag.BinderState,
typeof(object),
SetOperatorString,
ArrayUtils.RemoveFirst(GetActionArgumentsForSet(ag, right))
),
Span
);
}
示例11: AssignComplex
private MSAst.Expression AssignComplex(AstGenerator ag, MSAst.Expression right) {
// Python assignment semantics:
// - only evaluate RHS once.
// - evaluates assignment from left to right
// - does not evaluate getters.
//
// So
// a=b[c]=d=f()
// should be:
// $temp = f()
// a = $temp
// b[c] = $temp
// d = $temp
List<MSAst.Expression> statements = new List<MSAst.Expression>();
// 1. Create temp variable for the right value
MSAst.ParameterExpression right_temp = ag.GetTemporary("assignment");
// 2. right_temp = right
statements.Add(
AstGenerator.MakeAssignment(right_temp, right)
);
// Do left to right assignment
foreach (Expression e in _left) {
if (e == null) {
continue;
}
// 3. e = right_temp
MSAst.Expression transformed = e.TransformSet(ag, Span, right_temp, PythonOperationKind.None);
statements.Add(transformed);
}
// 4. Create and return the resulting suite
statements.Add(AstUtils.Empty());
return ag.AddDebugInfoAndVoid(
Ast.Block(statements.ToArray()),
Span
);
}
示例12: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
string className = _name;
AstGenerator classGen = new AstGenerator(ag, className, false, "class " + className);
classGen.Parameter(_parentContextParam);
// we always need to create a nested context for class defs
classGen.CreateNestedContext();
List<MSAst.Expression> init = new List<MSAst.Expression>();
classGen.AddHiddenVariable(ArrayGlobalAllocator._globalContext);
init.Add(Ast.Assign(ArrayGlobalAllocator._globalContext, Ast.Call(typeof(PythonOps).GetMethod("GetGlobalContext"), _parentContextParam)));
init.AddRange(classGen.Globals.PrepareScope(classGen));
CreateVariables(classGen, _parentContextParam, init, true, false);
List<MSAst.Expression> statements = new List<MSAst.Expression>();
// Create the body
MSAst.Expression bodyStmt = classGen.Transform(_body);
// __module__ = __name__
MSAst.Expression modStmt = GlobalAllocator.Assign(
classGen.Globals.GetVariable(classGen, _modVariable),
classGen.Globals.GetVariable(classGen, _modNameVariable));
string doc = classGen.GetDocumentation(_body);
if (doc != null) {
statements.Add(
GlobalAllocator.Assign(
classGen.Globals.GetVariable(classGen, _docVariable),
AstUtils.Constant(doc)
)
);
}
FunctionCode funcCodeObj = new FunctionCode(
ag.PyContext,
null,
null,
Name,
ag.GetDocumentation(_body),
ArrayUtils.EmptyStrings,
FunctionAttributes.None,
Span,
ag.Context.SourceUnit.Path,
ag.EmitDebugSymbols,
ag.ShouldInterpret,
FreeVariables,
GlobalVariables,
CellVariables,
AppendVariables(new List<string>()),
Variables == null ? 0 : Variables.Count,
classGen.LoopLocationsNoCreate,
classGen.HandlerLocationsNoCreate
);
MSAst.Expression funcCode = classGen.Globals.GetConstant(funcCodeObj);
classGen.FuncCodeExpr = funcCode;
if (_body.CanThrow && ag.PyContext.PythonOptions.Frames) {
bodyStmt = AstGenerator.AddFrame(classGen.LocalContext, funcCode, bodyStmt);
classGen.AddHiddenVariable(AstGenerator._functionStack);
}
bodyStmt = classGen.WrapScopeStatements(
Ast.Block(
statements.Count == 0 ?
AstGenerator.EmptyBlock :
Ast.Block(new ReadOnlyCollection<MSAst.Expression>(statements)),
modStmt,
bodyStmt,
classGen.LocalContext // return value
)
);
var lambda = Ast.Lambda<Func<CodeContext, CodeContext>>(
classGen.MakeBody(_parentContextParam, init.ToArray(), bodyStmt),
classGen.Name + "$" + _classId++,
classGen.Parameters
);
funcCodeObj.Code = lambda;
MSAst.Expression classDef = Ast.Call(
AstGenerator.GetHelperMethod("MakeClass"),
ag.EmitDebugSymbols ?
(MSAst.Expression)lambda :
Ast.Convert(funcCode, typeof(object)),
ag.LocalContext,
AstUtils.Constant(_name),
Ast.NewArrayInit(
typeof(object),
ag.TransformAndConvert(_bases, typeof(object))
),
AstUtils.Constant(FindSelfNames())
);
classDef = ag.AddDecorators(classDef, _decorators);
return ag.AddDebugInfoAndVoid(GlobalAllocator.Assign(ag.Globals.GetVariable(ag, _variable), classDef), new SourceSpan(Start, Header));
}
示例13: TransformDelete
internal override MSAst.Expression TransformDelete(AstGenerator ag) {
return ag.AddDebugInfoAndVoid(
Binders.Operation(
ag.BinderState,
typeof(object),
DeleteOperatorString,
ArrayUtils.RemoveFirst(GetActionArgumentsForGetOrDelete(ag))
),
Span
);
}
示例14: TransformDelete
internal override MSAst.Expression TransformDelete(AstGenerator ag) {
MSAst.Expression index;
if (IsSlice) {
index = ag.DeleteSlice(typeof(object), GetActionArgumentsForGetOrDelete(ag));
} else {
index = ag.DeleteIndex(typeof(void), GetActionArgumentsForGetOrDelete(ag));
}
return ag.AddDebugInfoAndVoid(index, Span);
}
示例15: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
Debug.Assert(_variable != null, "Shouldn't be called by lambda expression");
MSAst.Expression function = TransformToFunctionExpression(ag);
return ag.AddDebugInfoAndVoid(GlobalAllocator.Assign(ag.Globals.GetVariable(ag, _variable), function), new SourceSpan(Start, Header));
}