本文整理匯總了C#中AST.Find方法的典型用法代碼示例。如果您正苦於以下問題:C# AST.Find方法的具體用法?C# AST.Find怎麽用?C# AST.Find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AST
的用法示例。
在下文中一共展示了AST.Find方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetExprTypeEnv
public Tuple<AST.Env, AST.ExprType> GetExprTypeEnv(Boolean is_struct, AST.Env env, Boolean is_const, Boolean is_volatile) {
if (name == "") {
// If no name is supplied: must be complete.
// struct { ... } or union { ... }
if (declns == null) {
throw new ArgumentNullException("Error: parser should ensure declns != null");
}
Tuple<AST.Env, List<Tuple<String, AST.ExprType>>> r_attribs = GetAttribs(env);
env = r_attribs.Item1;
if (is_struct) {
return new Tuple<AST.Env, AST.ExprType>(env, AST.TStructOrUnion.CreateStruct("<anonymous>", r_attribs.Item2, is_const, is_volatile));
} else {
return new Tuple<AST.Env, AST.ExprType>(env, AST.TStructOrUnion.CreateUnion("<anonymous>", r_attribs.Item2, is_const, is_volatile));
}
} else {
// If a name is supplied, split into 2 cases.
String typename = is_struct ? $"struct {name}" : $"union {name}";
if (declns == null) {
// Case 1: If no attribute list supplied, then we are either
// 1) mentioning an already-existed struct/union
// or 2) creating an incomplete struct/union
Option<AST.Env.Entry> entry_opt = env.Find(typename);
if (entry_opt.IsNone) {
// If the struct/union is not in the current environment,
// then add an incomplete struct/union into the environment
AST.ExprType type =
is_struct
? AST.TStructOrUnion.CreateIncompleteStruct(name, is_const, is_volatile)
: AST.TStructOrUnion.CreateIncompleteUnion(name, is_const, is_volatile);
env = env.PushEntry(AST.Env.EntryKind.TYPEDEF, typename, type);
return Tuple.Create(env, type);
}
if (entry_opt.Value.kind != AST.Env.EntryKind.TYPEDEF) {
throw new InvalidProgramException(typename + " is not a type? This should be my fault.");
}
// If the struct/union is found, return it.
return Tuple.Create(env, entry_opt.Value.type);
} else {
// Case 2: If an attribute list is supplied.
// 1) Make sure there is no complete struct/union in the current environment.
Option<AST.Env.Entry> entry_opt = env.Find(typename);
if (entry_opt.IsSome && entry_opt.Value.type.kind == AST.ExprType.Kind.STRUCT_OR_UNION && ((AST.TStructOrUnion)entry_opt.Value.type).IsComplete) {
throw new InvalidOperationException($"Redefining {typename}");
}
// 2) Add an incomplete struct/union into the environment.
AST.TStructOrUnion type =
is_struct
? AST.TStructOrUnion.CreateIncompleteStruct(name, is_const, is_volatile)
: AST.TStructOrUnion.CreateIncompleteUnion(name, is_const, is_volatile);
env = env.PushEntry(AST.Env.EntryKind.TYPEDEF, typename, type);
// 3) Iterate over the attributes.
Tuple<AST.Env, List<Tuple<String, AST.ExprType>>> r_attribs = GetAttribs(env);
env = r_attribs.Item1;
// 4) Make the type complete. This would also change the entry inside env.
if (is_struct) {
type.DefineStruct(r_attribs.Item2);
} else {
type.DefineUnion(r_attribs.Item2);
}
return new Tuple<AST.Env, AST.ExprType>(env, type);
}
}
}
示例2: GetExpr
public override AST.Expr GetExpr(AST.Env env)
{
Option<AST.Env.Entry> entry_opt = env.Find(name);
if (entry_opt.IsNone) {
throw new InvalidOperationException($"Cannot find variable '{name}'");
}
AST.Env.Entry entry = entry_opt.Value;
switch (entry.kind) {
case AST.Env.EntryKind.TYPEDEF:
throw new InvalidOperationException($"Expected a variable '{name}', not a typedef.");
case AST.Env.EntryKind.ENUM:
return new AST.ConstLong(entry.offset, env);
case AST.Env.EntryKind.FRAME:
case AST.Env.EntryKind.GLOBAL:
case AST.Env.EntryKind.STACK:
return new AST.Variable(entry.type, name, env);
default:
throw new InvalidOperationException($"Cannot find variable '{name}'");
}
}