示例#1
0
        private void CheckMainCandidate(AstNode node, Function main)
        {
            // Ignore the main type if the module is not executable.
            if(currentModule.GetModuleType() != ModuleType.Executable)
                return;

            // Get the function type.
            FunctionType type = main.GetFunctionType();

            // Check the return type.
            IChelaType returnType = type.GetReturnType();
            if(returnType != ChelaType.GetVoidType() &&
               returnType != ChelaType.GetIntType())
                return;

            // Check the argument count.
            if(type.GetArgumentCount() > 1)
                return;

            // Check the argument.
            if(type.GetArgumentCount() == 1)
            {
                IChelaType strArrayType = ReferenceType.Create(ArrayType.Create(currentModule.TypeMap(ChelaType.GetStringType())));
                if(strArrayType != type.GetArgument(0))
                   return;
            }

            // Make usure it could be.
            string fullName = main.GetFullName();
            string mainName = currentModule.GetMainName();
            if(mainName != null && fullName != mainName)
                return;

            // This is a main candidate.
            Function oldMain = currentModule.GetMainFunction();
            if(oldMain != null && oldMain != main)
                Error(node, "multiple main functions defined");

            // This is the main.
            currentModule.SetMainFunction(main);
        }