示例#1
0
 private void CreateImplicitBaseConstructor(AstNode node, Method function)
 {
     Function parentConstructor = function.GetCtorParent();
     if(parentConstructor != null &&
        function.GetParentScope().IsStructure() == parentConstructor.GetParentScope().IsStructure())
     {
         builder.CreateLoadArg(0);
         builder.CreateCall(parentConstructor, 1);
     }
 }
示例#2
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);
        }