本文整理汇总了C#中Env.FindInCurrentScope方法的典型用法代码示例。如果您正苦于以下问题:C# Env.FindInCurrentScope方法的具体用法?C# Env.FindInCurrentScope怎么用?C# Env.FindInCurrentScope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Env
的用法示例。
在下文中一共展示了Env.FindInCurrentScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExprType
public override ISemantReturn<ExprType> GetExprType(Env env) {
if (this.Enumrs.IsNone) {
// If no enumerators provided: must find enum Type in the current environment.
if (this.Name.IsNone) {
throw new InvalidProgramException("This should not pass the parser.");
}
var name = this.Name.Value;
var entryOpt = env.Find($"enum {name}");
if (entryOpt.IsNone || entryOpt.Value.Kind != Env.EntryKind.TYPEDEF) {
throw new InvalidOperationException($"enum {name} has not been defined.");
}
return SemantReturn.Create(env, new LongType());
}
// If enumerators are provided: add names to environment
Int32 offset = 0;
foreach (var enumr in this.Enumrs.Value) {
if (enumr.Init.IsSome) {
// If the user provides an initialization Value, use it.
var init = SemantExpr(enumr.Init.Value, ref env);
init = ABT.TypeCast.MakeCast(init, new LongType());
if (!init.IsConstExpr) {
throw new InvalidOperationException("Enumerator initialization must have a constant Value.");
}
offset = ((ConstLong)init).Value;
}
env = env.PushEnum(enumr.Name, new LongType(), offset);
offset++;
}
// If the user provides a name to the enum, add it to the environment.
if (this.Name.IsSome) {
var typeName = $"enum {this.Name.Value}";
if (env.FindInCurrentScope(typeName).IsSome) {
throw new InvalidOperationException($"{typeName} is already defined.");
}
env = env.PushEntry(Env.EntryKind.TYPEDEF, typeName, new LongType());
}
return SemantReturn.Create(env, new LongType());
}