本文整理汇总了C#中IronPython.Compiler.Ast.AstGenerator类的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator类的具体用法?C# AstGenerator怎么用?C# AstGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AstGenerator类属于IronPython.Compiler.Ast命名空间,在下文中一共展示了AstGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TransformSet
internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, PythonOperationKind op) {
MSAst.Expression assignment;
if (op != PythonOperationKind.None) {
right = ag.Operation(
typeof(object),
op,
Transform(ag, typeof(object)),
right
);
}
if (_reference.PythonVariable != null) {
assignment = ag.Globals.Assign(
ag.Globals.GetVariable(_reference.PythonVariable),
AstGenerator.ConvertIfNeeded(right, typeof(object))
);
} else {
assignment = Ast.Call(
null,
typeof(ScriptingRuntimeHelpers).GetMethod("SetName"),
new [] {
ag.LocalContext,
ag.Globals.GetSymbol(_name),
AstUtils.Convert(right, typeof(object))
}
);
}
SourceSpan aspan = span.IsValid ? new SourceSpan(Span.Start, span.End) : SourceSpan.None;
return ag.AddDebugInfoAndVoid(assignment, aspan);
}
开发者ID:tnachen,项目名称:ironruby,代码行数:32,代码来源:NameExpression.cs
示例2: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return ag.Get(
type,
_name,
ag.Transform(_target)
);
}
开发者ID:techarch,项目名称:ironruby,代码行数:7,代码来源:MemberExpression.cs
示例3: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return Ast.Call(
AstGenerator.GetHelperMethod("Repr"), // method
ag.LocalContext,
ag.TransformAsObject(_expression) // args
);
}
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:BackQuoteExpression.cs
示例4: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
MSAst.Expression left = ag.Transform(_left);
MSAst.Expression right = ag.Transform(_right);
Type t = left.Type == right.Type ? left.Type : typeof(object);
MSAst.ParameterExpression tmp = ag.GetTemporary("__all__", t);
return Ast.Condition(
Binders.Convert(
ag.BinderState,
typeof(bool),
ConversionResultKind.ExplicitCast,
AstUtils.Assign(
tmp,
AstUtils.Convert(
left,
t
)
)
),
AstUtils.Convert(
right,
t
),
tmp
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:27,代码来源:AndExpression.cs
示例5: AstGenerator
internal AstGenerator(AstGenerator/*!*/ parent, string name, bool generator, bool print)
: this(name, generator, false) {
Assert.NotNull(parent);
_context = parent.Context;
_binderState = parent.BinderState;
_document = _context.SourceUnit.Document;
}
开发者ID:octavioh,项目名称:ironruby,代码行数:7,代码来源:AstGenerator.cs
示例6: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
MSAst.ParameterExpression list = ag.GetTemporary("list_comprehension_list", typeof(List));
// 1. Initialization code - create list and store it in the temp variable
MSAst.Expression initialize =
Ast.Assign(
list,
Ast.Call(
AstGenerator.GetHelperMethod("MakeList", Type.EmptyTypes) // method
)
);
// 2. Create body from _item: list.Append(_item)
MSAst.Expression body = ag.AddDebugInfo(
Ast.Call(
AstGenerator.GetHelperMethod("ListAddForComprehension"),
list,
ag.TransformAsObject(_item)
),
_item.Span
);
// 3. Transform all iterators in reverse order, building the true body:
int current = _iterators.Length;
while (current-- > 0) {
ListComprehensionIterator iterator = _iterators[current];
body = iterator.Transform(ag, body);
}
return Ast.Block(
initialize,
body,
list // result
);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:35,代码来源:ListComprehension.cs
示例7: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return ag.Get(
type,
SymbolTable.IdToString(_name),
ag.Transform(_target)
);
}
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:MemberExpression.cs
示例8: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
List<MSAst.Expression> statements = new List<MSAst.Expression>();
for (int i = 0; i < _names.Length; i++) {
statements.Add(
// _references[i] = PythonOps.Import(<code context>, _names[i])
ag.AddDebugInfo(
AstUtils.Assign(
_variables[i].Variable,
Ast.Call(
AstGenerator.GetHelperMethod( // helper
_asNames[i] == SymbolId.Empty ? "ImportTop" : "ImportBottom"
),
AstUtils.CodeContext(), // 1st arg - code context
Ast.Constant(_names[i].MakeString()), // 2nd arg - module name
Ast.Constant(_forceAbsolute ? 0 : -1) // 3rd arg - absolute or relative imports
)
),
_names[i].Span
)
);
}
statements.Add(Ast.Empty());
return ag.AddDebugInfo(Ast.Block(statements.ToArray()), Span);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:26,代码来源:ImportStatement.cs
示例9: 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
);
}
开发者ID:jcteague,项目名称:ironruby,代码行数:28,代码来源:RaiseStatement.cs
示例10: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
MSAst.MethodCallExpression call;
if (_locals == null && _globals == null) {
// exec code
call = Ast.Call(
AstGenerator.GetHelperMethod("UnqualifiedExec"),
AstUtils.CodeContext(),
ag.TransformAsObject(_code)
);
} else {
// exec code in globals [ , locals ]
// We must have globals now (locals is last and may be absent)
Debug.Assert(_globals != null);
call = Ast.Call(
AstGenerator.GetHelperMethod("QualifiedExec"),
AstUtils.CodeContext(),
ag.TransformAsObject(_code),
ag.TransformAndDynamicConvert(_globals, typeof(IAttributesCollection)),
ag.TransformOrConstantNull(_locals, typeof(object))
);
}
return ag.AddDebugInfo(call, Span);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:25,代码来源:ExecStatement.cs
示例11: 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;
}
开发者ID:techarch,项目名称:ironruby,代码行数:26,代码来源:IfStatement.cs
示例12: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
if (ag.InLoop) {
return ag.AddDebugInfo(MSAst.Expression.Break(ag.BreakLabel), Span);
} else {
return null;
}
}
开发者ID:Hank923,项目名称:ironruby,代码行数:7,代码来源:BreakStatement.cs
示例13: 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);
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:26,代码来源:ImportStatement.cs
示例14: GetActionArgumentsForGetOrDelete
private MSAst.Expression[] GetActionArgumentsForGetOrDelete(AstGenerator ag) {
TupleExpression te = _index as TupleExpression;
if (te != null && te.IsExpandable) {
return ArrayUtils.Insert(AstUtils.CodeContext(), ag.Transform(_target), ag.Transform(te.Items));
}
SliceExpression se = _index as SliceExpression;
if (se != null) {
if (se.StepProvided) {
return new MSAst.Expression[] {
AstUtils.CodeContext(),
ag.Transform(_target),
GetSliceValue(ag, se.SliceStart),
GetSliceValue(ag, se.SliceStop),
GetSliceValue(ag, se.SliceStep)
};
}
return new MSAst.Expression[] {
AstUtils.CodeContext(),
ag.Transform(_target),
GetSliceValue(ag, se.SliceStart),
GetSliceValue(ag, se.SliceStop)
};
}
return new MSAst.Expression[] { AstUtils.CodeContext(), ag.Transform(_target), ag.Transform(_index) };
}
开发者ID:octavioh,项目名称:ironruby,代码行数:28,代码来源:IndexExpression.cs
示例15: 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
);
}
}
开发者ID:octavioh,项目名称:ironruby,代码行数:25,代码来源:MemberExpression.cs
示例16: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return Ast.Call(
AstGenerator.GetHelperMethod("Repr"), // method
Microsoft.Scripting.Ast.Utils.CodeContext(),
ag.TransformAsObject(_expression) // args
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:7,代码来源:BackQuoteExpression.cs
示例17: TransformSet
internal override MSAst.Expression TransformSet(AstGenerator ag, SourceSpan span, MSAst.Expression right, Operators op) {
MSAst.Expression variable = _reference.Variable;
MSAst.Expression assignment;
Type vt = variable != null ? variable.Type : typeof(object);
if (op != Operators.None) {
right = Binders.Operation(
ag.BinderState,
vt,
StandardOperators.FromOperator(op),
Transform(ag, vt),
right
);
}
if (variable != null) {
assignment = AstUtils.Assign(variable, AstGenerator.ConvertIfNeeded(right, variable.Type));
} else {
assignment = AstUtils.Assign(_name, right);
}
SourceSpan aspan = span.IsValid ? new SourceSpan(Span.Start, span.End) : SourceSpan.None;
return ag.AddDebugInfoAndVoid(assignment, aspan);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:25,代码来源:NameExpression.cs
示例18: GetSliceValue
private static MSAst.Expression GetSliceValue(AstGenerator ag, Expression expr) {
if (expr != null) {
return ag.Transform(expr);
}
return Ast.Field(null, typeof(MissingParameter).GetField("Value"));
}
开发者ID:octavioh,项目名称:ironruby,代码行数:7,代码来源:IndexExpression.cs
示例19: Transform
internal override MSAst.Expression Transform(AstGenerator ag, Type type) {
return ag.Operation(
type,
PythonOperatorToOperatorString(_op),
ag.Transform(_expression)
);
}
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:UnaryExpression.cs
示例20: Transform
internal override MSAst.Expression Transform(AstGenerator ag) {
if (ag.IsGenerator) {
if (_expression != null) {
// Statements can't return null, so return a rethrow.
// Callers should detecet the ag.AddError and avoid trying to execute the tree,
// but if they accidentally do, use Throw instead of empty so that
// we'll get an exception.
return Ast.Throw(
Ast.New(
typeof(InvalidOperationException).GetConstructor(Type.EmptyTypes)
)
);
}
return ag.AddDebugInfo(AstUtils.YieldBreak(ag.GeneratorLabel), Span);
}
return ag.AddDebugInfo(
Ast.Return(
ag.ReturnLabel,
ag.TransformOrConstantNull(_expression, typeof(object))
),
Span
);
}
开发者ID:Hank923,项目名称:ironruby,代码行数:25,代码来源:ReturnStatement.cs
注:本文中的IronPython.Compiler.Ast.AstGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论