本文整理汇总了C#中IronPython.Compiler.Ast.FunctionDefinition.Walk方法的典型用法代码示例。如果您正苦于以下问题:C# FunctionDefinition.Walk方法的具体用法?C# FunctionDefinition.Walk怎么用?C# FunctionDefinition.Walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IronPython.Compiler.Ast.FunctionDefinition
的用法示例。
在下文中一共展示了FunctionDefinition.Walk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildYieldTargets
public static YieldTarget[] BuildYieldTargets(FunctionDefinition func, CodeGen cg)
{
YieldLabelBuilder b = new YieldLabelBuilder(func, cg);
func.Walk(b);
return b.topYields;
}
示例2: CreateNewMethod
private CodeGen CreateNewMethod(FunctionDefinition node, CodeGen typeCctor, SignatureInfo sigInfo)
{
string strName = node.Name.GetString();
MethodAttributes attrs = GetMethodAttributes(node, strName);
int offset = (sigInfo.HasContext ? 2 : 1);
if ((attrs & MethodAttributes.Static) != 0) offset--;
if (node.Parameters.Count == 0 && (attrs & MethodAttributes.Static) == 0)
throw new CompilerException(String.Format("defining non-static method {0} with no parameters. Add self or @staticmethod decorator", node.Name), node, this.compctx.SourceFile);
Debug.Assert(sigInfo.ParamNames.Length >= offset,
"less param names then offset",
String.Format("Params: {0} Offset: {1}: Context: {2} Attrs: {3} Name: {4}",
sigInfo.ParamNames.Length, offset, sigInfo.HasContext, attrs, strName));
string[] paramNames = new string[sigInfo.ParamNames.Length - offset];
for (int i = 0; i < paramNames.Length; i++)
paramNames[i] = sigInfo.ParamNames[i + offset].GetString();
Type[] typeArr;
CustomAttributeBuilder[] cabs;
GetTypesAndAttrs(node, sigInfo, offset, out typeArr, out cabs);
object[] funcDefaults = GetStaticDefaults(node, paramNames.Length);
MethodInfo baseMethod = GetMethodOverload(strName, attrs);
Type retType;
if (baseMethod == null) {
// Check whether the method has a return statement, to decide whether it should
// return void or object
ReturnStatementFinder finder = new ReturnStatementFinder(node);
node.Walk(finder);
retType = finder.FoundReturnStatement ? typeof(object) : typeof(void);
} else {
// Get the return and param types from the base method
typeArr = CompilerHelpers.GetTypes(baseMethod.GetParameters());
retType = baseMethod.ReturnType;
attrs |= MethodAttributes.Virtual;
}
CodeGen icg = typeCctor.typeGen.DefineMethod(attrs,
strName,
retType,
typeArr,
paramNames,
funcDefaults,
cabs);
icg.Context = compctx;
if (baseMethod != null) icg.methodToOverride = baseMethod;
icg.Names = CodeGen.CreateLocalNamespace(icg);
for (int arg = offset; arg < sigInfo.ParamNames.Length; arg++) {
icg.Names.SetSlot(sigInfo.ParamNames[arg], icg.GetArgumentSlot(arg - offset));
}
if ((attrs & MethodAttributes.Static) == 0) {
icg.Names.SetSlot(sigInfo.ParamNames[offset - 1], new ArgSlot(0, typeCctor.typeGen.myType, icg));
}
icg.ContextSlot = stack.Peek().Type.moduleSlot;
EmitArgsToTuple(node, icg, sigInfo, paramNames.Length);
return icg;
}