AST.EnumSpec.GetExprType C# (CSharp) Метод

GetExprType() приватный Метод

private GetExprType ( Env env ) : ISemantReturn
env Env
Результат ISemantReturn
        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());
        }