本文整理汇总了C#中IronPython.Compiler.Ast.FunctionDefinition类的典型用法代码示例。如果您正苦于以下问题:C# FunctionDefinition类的具体用法?C# FunctionDefinition怎么用?C# FunctionDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FunctionDefinition类属于IronPython.Compiler.Ast命名空间,在下文中一共展示了FunctionDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostWalk
public override void PostWalk(FunctionDefinition node)
{
if (node.Body != null && node.Name != null) {
_scopes.Pop();
_scopeTree.Pop();
_curUnit = _analysisStack.Pop();
}
}
示例2: PythonMethod
public PythonMethod(IClass declaringType, FunctionDefinition methodDefinition, string name)
: base(declaringType, name)
{
ReturnType = new DefaultReturnType(declaringType);
Modifiers = ModifierEnum.Public;
GetMethodRegions(methodDefinition);
AddParameters(methodDefinition);
declaringType.Methods.Add(this);
}
示例3: Walk
public override bool Walk(FunctionDefinition node)
{
if (IsInitializeComponentMethod(node)) {
Type type = GetComponentType();
component = componentCreator.CreateComponent(type, componentName);
IResourceReader reader = componentCreator.GetResourceReader(CultureInfo.InvariantCulture);
if (reader != null) {
reader.Dispose();
}
node.Body.Walk(this);
}
return false;
}
示例4: Walk
public override bool Walk(FunctionDefinition functionDefinition)
{
if (functionDefinition.Body == null) {
return false;
}
IClass c = GetClassBeingWalked();
PythonMethodDefinition methodDefinition = new PythonMethodDefinition(functionDefinition);
PythonMethod method = methodDefinition.CreateMethod(c);
if (method is PythonConstructor) {
FindFields(c, functionDefinition);
}
return false;
}
示例5: GetImageListKind
private static ImageListKind GetImageListKind(FunctionDefinition funcDef)
{
ImageListKind imageKind = ImageListKind.Method;
if (funcDef.Decorators != null && funcDef.Decorators.Count == 1) {
foreach (var decorator in funcDef.Decorators) {
NameExpression nameExpr = decorator as NameExpression;
if (nameExpr != null) {
if (nameExpr.Name == "property") {
imageKind = ImageListKind.Property;
break;
} else if (nameExpr.Name == "staticmethod") {
imageKind = ImageListKind.StaticMethod;
break;
} else if (nameExpr.Name == "classmethod") {
imageKind = ImageListKind.ClassMethod;
break;
}
}
}
}
return imageKind;
}
示例6: ParseGeneratorExpression
// genexpr_for ::= "for" target_list "in" or_test [genexpr_iter]
// genexpr_iter ::= (genexpr_for | genexpr_if) *
//
// "for" has NOT been eaten before entering this method
private Expression ParseGeneratorExpression(Expression expr) {
ForStatement root = ParseGenExprFor();
Statement current = root;
for (; ; ) {
if (PeekToken(Tokens.KeywordForToken)) {
current = NestGenExpr(current, ParseGenExprFor());
} else if (PeekToken(Tokens.KeywordIfToken)) {
current = NestGenExpr(current, ParseGenExprIf());
} else {
// Generator Expressions have an implicit function definition and yield around their expression.
// (x for i in R)
// becomes:
// def f():
// for i in R: yield (x)
ExpressionStatement ys = new ExpressionStatement(new YieldExpression(expr));
ys.Expression.SetLoc(_globalParent, expr.IndexSpan);
ys.SetLoc(_globalParent, expr.IndexSpan);
NestGenExpr(current, ys);
break;
}
}
// We pass the outermost iterable in as a parameter because Python semantics
// say that this one piece is computed at definition time rather than iteration time
const string fname = "<genexpr>";
Parameter parameter = new Parameter("__gen_$_parm__", 0);
FunctionDefinition func = new FunctionDefinition(fname, new Parameter[] { parameter }, root);
func.IsGenerator = true;
func.SetLoc(_globalParent, root.StartIndex, GetEnd());
func.HeaderIndex = root.EndIndex;
// Transform the root "for" statement
Expression outermost = root.List;
NameExpression ne = new NameExpression("__gen_$_parm__");
ne.SetLoc(_globalParent, outermost.IndexSpan);
root.List = ne;
GeneratorExpression ret = new GeneratorExpression(func, outermost);
ret.SetLoc(_globalParent, expr.StartIndex, GetEnd());
return ret;
}
示例7: PushFunction
private void PushFunction(FunctionDefinition function) {
if (_functions == null) {
_functions = new Stack<FunctionDefinition>();
}
_functions.Push(function);
}
示例8: PythonMethodDefinition
public PythonMethodDefinition(FunctionDefinition methodDefinition)
{
this.methodDefinition = methodDefinition;
}
示例9: ParseLambdaHelperEnd
private Expression ParseLambdaHelperEnd(FunctionDefinition func, Expression expr) {
// Pep 342 in Python 2.5 allows Yield Expressions, which can occur inside a Lambda body.
// In this case, the lambda is a generator and will yield it's final result instead of just return it.
Statement body;
if (func.IsGenerator) {
YieldExpression y = new YieldExpression(expr);
y.SetLoc(_globalParent, expr.IndexSpan);
body = new ExpressionStatement(y);
} else {
body = new ReturnStatement(expr);
}
body.SetLoc(_globalParent, expr.StartIndex, expr.EndIndex);
FunctionDefinition func2 = PopFunction();
System.Diagnostics.Debug.Assert(func == func2);
func.Body = body;
func.EndIndex = GetEnd();
LambdaExpression ret = new LambdaExpression(func);
func.SetLoc(_globalParent, func.IndexSpan);
ret.SetLoc(_globalParent, func.IndexSpan);
return ret;
}
示例10: Walk
public override bool Walk(FunctionDefinition node)
{
// Do not recurse into nested functions
return node == func;
}
示例11: FindNames
public static string[] FindNames(FunctionDefinition function) {
var parameters = function.Parameters;
if (parameters.Count > 0) {
SelfNameFinder finder = new SelfNameFinder(function, parameters[0]);
function.Body.Walk(finder);
return ArrayUtils.ToArray(finder._names.Keys);
} else {
// no point analyzing function with no parameters
return ArrayUtils.EmptyStrings;
}
}
示例12: GetMethodRegions
void GetMethodRegions(FunctionDefinition methodDefinition)
{
GetBodyRegion(methodDefinition);
GetMethodRegion(methodDefinition);
}
示例13: GetMethodRegion
/// <summary>
/// Gets the region of a method. This does not include the body.
/// </summary>
void GetMethodRegion(FunctionDefinition methodDefinition)
{
SourceLocation start = methodDefinition.Start;
SourceLocation end = methodDefinition.Header;
Region = new DomRegion(start.Line, start.Column, end.Line, end.Column + 1);
}
示例14: PostWalk
// FunctionDefinition
public override void PostWalk(FunctionDefinition node)
{
Debug.Assert(_currentScope == node);
PopScope();
}
示例15: Walk
// FunctionDefinition
public override bool Walk(FunctionDefinition node)
{
node._nameVariable = _globalScope.EnsureGlobalVariable("__name__");
// Name is defined in the enclosing context
if (!node.IsLambda) {
node.PythonVariable = DefineName(node.Name);
}
// process the default arg values in the outer context
foreach (Parameter p in node.Parameters) {
if (p.DefaultValue != null) {
p.DefaultValue.Walk(this);
}
}
// process the decorators in the outer context
if (node.Decorators != null) {
foreach (Expression dec in node.Decorators) {
dec.Walk(this);
}
}
PushScope(node);
foreach (Parameter p in node.Parameters) {
p.Walk(_parameter);
}
node.Body.Walk(this);
return false;
}