コード例 #1
0
ファイル: FunctionGenerator.cs プロジェクト: ronsaldo/chela
        private void GenerateStaticFieldInitializations(AstNode node, Function ctor, Structure building)
        {
            // Get the static initialization fields.
            List<FieldDeclaration> staticInitedField = new List<FieldDeclaration> ();
            bool isUnsafe = false;
            foreach(FieldDeclaration decl in building.GetFieldInitializations())
            {
                Variable variable = decl.GetVariable();
                if(variable.IsStatic())
                {
                    staticInitedField.Add(decl);
                    if(variable.IsUnsafe())
                        isUnsafe = true;
                }
            }

            // If there aren't field to initialize, don't create the static constructor.
            if(staticInitedField.Count == 0)
                return;

            // Check if unsafe its required.
            if(isUnsafe && !ctor.IsUnsafe())
                Error(node, "static constructor must be unsafe due to implicit unsafe static field initialization.");

            // Initialize the static fields.
            GenerateStaticFieldInitializations(node, staticInitedField);
        }