예제 #1
0
        private void CheckDefaultConstructorInit(AstNode node, Method function)
        {
            // Get the base building.
            Structure building = (Structure)function.GetParentScope();
            Structure baseBuilding = building.GetBase();
            if(baseBuilding == null)
                return; // Object class.

            // Find a default construcotor.
            FunctionGroup ctorGroup = baseBuilding.GetConstructor();
            Method ctor = null;
            foreach(FunctionGroupName ctorName in ctorGroup.GetFunctions())
            {
                // Ignore static constructors.
                if(ctorName.IsStatic())
                    continue;

                // Check the constructor type.
                FunctionType ctorType = ctorName.GetFunctionType();
                if(ctorType.GetArgumentCount() == 1)
                {
                    // Found, the first argument must be "this".
                    ctor = (Method)ctorName.GetFunction();
                    break;
                }
            }

            // If not found, raise error.
            if(ctor == null)
                Error(node, baseBuilding.GetFullName() + " doesn't have a default constructor.");

            // Store the default constructor.
            function.SetCtorParent(ctor);
        }