当前位置: 首页>>代码示例>>C#>>正文


C# Env.PushEntry方法代码示例

本文整理汇总了C#中Env.PushEntry方法的典型用法代码示例。如果您正苦于以下问题:C# Env.PushEntry方法的具体用法?C# Env.PushEntry怎么用?C# Env.PushEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Env的用法示例。


在下文中一共展示了Env.PushEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetExternDecln

        public ISemantReturn<ImmutableList<Tuple<Env, ExternDecln>>> GetExternDecln(Env env) {
            var storageClass = this.Specs.GetStorageClass();
            var baseType = Semant(this.Specs.GetExprType, ref env);
            var name = this.Declr.Name;
            var type = Semant(this.Declr.DecorateType, baseType, ref env);

            var funcType = type as FunctionType;
            if (funcType == null) {
                throw new InvalidOperationException("Expected a function Type.");
            }

            switch (storageClass) {
                case StorageClass.AUTO:
                case StorageClass.EXTERN:
                case StorageClass.STATIC:
                    env = env.PushEntry(Env.EntryKind.GLOBAL, name, type);
                    break;
                case StorageClass.TYPEDEF:
                default:
                    throw new InvalidOperationException("Invalid storage class specifier for function definition.");
            }

            env = env.InScope();
            env = env.SetCurrentFunction(funcType);
            var stmt = SemantStmt(this.Stmt.GetStmt, ref env);
            env = env.OutScope();

            return SemantReturn.Create(env, ImmutableList.Create(Tuple.Create(env, new ABT.FuncDef(name, storageClass, funcType, stmt) as ExternDecln)));
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:29,代码来源:ExternalDeclarations.cs

示例2: GetDeclns

        public ISemantReturn<ImmutableList<Tuple<Env, ABT.Decln>>> GetDeclns(Env env) {
            var storageClass = this.DeclnSpecs.GetStorageClass();
            var baseType = Semant(this.DeclnSpecs.GetExprType, ref env);

            var declns = this.InitDeclrs.ConvertAll(
                initDeclr => {
                    var typeAndInitr = Semant(initDeclr.GetDecoratedTypeAndInitr, baseType, ref env);
                    var type = typeAndInitr.Item1;
                    var initr = typeAndInitr.Item2;
                    var name = initDeclr.GetName();

                    // Add the new symbol into the environment.
                    Env.EntryKind kind;
                    switch (storageClass) {
                        case StorageClass.AUTO:
                            if (env.IsGlobal()) {
                                kind = Env.EntryKind.GLOBAL;
                            } else {
                                kind = Env.EntryKind.STACK;
                            }
                            break;
                        case StorageClass.EXTERN:
                            kind = Env.EntryKind.GLOBAL;
                            break;
                        case StorageClass.STATIC:
                            kind = Env.EntryKind.GLOBAL;
                            break;
                        case StorageClass.TYPEDEF:
                            kind = Env.EntryKind.TYPEDEF;
                            break;
                        default:
                            throw new InvalidOperationException();
                    }
                    env = env.PushEntry(kind, name, type);

                    return Tuple.Create(env, new ABT.Decln(name, storageClass, type, initr));
                }
            );

            return SemantReturn.Create(env, declns);
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:41,代码来源:Declarations.cs

示例3: 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());
        }
开发者ID:phisiart,项目名称:C-Compiler,代码行数:49,代码来源:DeclarationSpecifiers.cs


注:本文中的Env.PushEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。