本文整理汇总了C#中AST.SetCurrentFunction方法的典型用法代码示例。如果您正苦于以下问题:C# AST.SetCurrentFunction方法的具体用法?C# AST.SetCurrentFunction怎么用?C# AST.SetCurrentFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AST
的用法示例。
在下文中一共展示了AST.SetCurrentFunction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFuncDef
public Tuple<AST.Env, AST.FuncDef> GetFuncDef(AST.Env env)
{
// Get storage class specifier and base type from declaration specifiers.
Tuple<AST.Env, AST.Decln.SCS, AST.ExprType> r_specs = this.specs.GetSCSType(env);
env = r_specs.Item1;
AST.Decln.SCS scs = r_specs.Item2;
AST.ExprType base_type = r_specs.Item3;
// Get function name and function type from declarator.
Tuple<String, AST.ExprType> r_declr = this.declr.GetNameAndType(env, base_type);
String name = r_declr.Item1;
AST.ExprType type = r_declr.Item2;
AST.TFunction func_type;
if (type.kind == AST.ExprType.Kind.FUNCTION) {
func_type = (AST.TFunction)type;
} else {
throw new InvalidOperationException($"{name} is not a function.");
}
switch (scs) {
case AST.Decln.SCS.AUTO:
case AST.Decln.SCS.EXTERN:
case AST.Decln.SCS.STATIC:
env = env.PushEntry(AST.Env.EntryKind.GLOBAL, name, type);
break;
case AST.Decln.SCS.TYPEDEF:
default:
throw new InvalidOperationException("Invalid storage class specifier for function definition.");
}
env = env.SetCurrentFunction(func_type);
Tuple<AST.Env, AST.Stmt> r_stmt = this.stmt.GetStmt(env);
env = r_stmt.Item1;
AST.Stmt stmt = r_stmt.Item2;
env = env.SetCurrentFunction(new AST.TEmptyFunction());
return Tuple.Create(env, new AST.FuncDef(name, scs, func_type, stmt));
}