Boo.Lang.Compiler.Steps.ProcessMethodBodies.AddInitializedGuardToInitializer C# (CSharp) Метод

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

private AddInitializedGuardToInitializer ( Boo.Lang.Compiler.Ast.TypeDefinition type, Method initializer ) : void
type Boo.Lang.Compiler.Ast.TypeDefinition
initializer Boo.Lang.Compiler.Ast.Method
Результат void
        void AddInitializedGuardToInitializer(TypeDefinition type, Method initializer)
        {
            Field field = GetFieldsInitializerInitializedField(type);

            //run initializer code only if $initialized$ is false
            //hmm quasi-notation would be lovely here
            Block trueBlock = new Block();
            trueBlock.Add(new GotoStatement(LexicalInfo.Empty, new ReferenceExpression("___initialized___")));
            IfStatement cond = new IfStatement(CodeBuilder.CreateReference(field),
                trueBlock, null);
            initializer.Body.Insert(0, cond);

            //set $initialized$ field to true
            initializer.Body.Add(
                CodeBuilder.CreateFieldAssignment(field, new BoolLiteralExpression(true)));

            //label we're past the initializer
            initializer.Body.Add(
                new LabelStatement(LexicalInfo.Empty, "___initialized___"));
        }
ProcessMethodBodies