private string generateSignature(COOPFunction function)
        {
            string returnType    = function.ReturnType.convertToC();
            var    generatedName = COOPFunctionConverter.generateFunctionName(function);

            var    typeNames  = generateTypeNames(function);
            string parameters = "(";

            for (var i = 0; i < typeNames.Count - 1; i++)
            {
                parameters += "" + typeNames[i][email protected]() + " " + typeNames[i].name + ", ";
            }

            if (typeNames.Count > 0)
            {
                int i = typeNames.Count - 1;
                parameters += "" + typeNames[i][email protected]() + " " + typeNames[i].name;
            }
            parameters += ")";

            return($"{returnType} {generatedName}{parameters}");
        }
Beispiel #2
0
        public Collection <FileConvertedInformation> convert(COOPClass coopObject, ClassHierarchy hierarchy)
        {
            var       output = new Collection <FileConvertedInformation>();
            COOPClass parent = hierarchy.getParent(coopObject);
            bool      createProtected, createPrivate;
            string    publicStructure = generatePublicStructure(coopObject, parent, out createProtected, out createPrivate);

            string cFile           = "",
                   protectedHeader = $"#ifndef SRC_PROTECTED_FILE_{coopObject.Name}\n#define SRC_PROTECTED_FILE_{coopObject.Name}\n",
                   publicHeader    = $"#ifndef SRC_PUBLIC_FILE_{coopObject.Name}\n#define SRC_PUBLIC_FILE_{coopObject.Name}\n";

            foreach (COOPClass coopObjectImport in coopObject.imports)
            {
                cFile += $"#include \"{coopObjectImport.Name}.h\"\n";
            }

            if (coopObject.Parent != null)
            {
                cFile += $"#include \"{coopObject.Parent.Name}_protected.h\"\n";
            }

            cFile += $"#include \"{coopObject.Name}_protected.h\"\n";


            if (createPrivate)
            {
                cFile += generatePrivateStructure(coopObject);
            }


            protectedHeader += $"#include \"{coopObject.Name}.h\"\n";
            if (createProtected)
            {
                protectedHeader += generateProtectedStructure(coopObject);
            }

            publicHeader += publicStructure;


            COOPFunctionConverter functionConverter = new COOPFunctionConverter(hierarchy, coopObject);
            List <FunctionConvertedInformation> functionConvertedInformations = new List <FunctionConvertedInformation>();

            foreach (var coopObjectFunction in coopObject.getFunctions())
            {
                var f = functionConverter.convert(coopObjectFunction);
                functionConvertedInformations.AddRange(f);
            }

            foreach (FunctionConvertedInformation functionConvertedInformation in
                     from f in functionConvertedInformations where f.accessLevel == AccessLevel.Private select f)
            {
                cFile += functionConvertedInformation.signature + ";\n";
            }

            foreach (FunctionConvertedInformation functionConvertedInformation in
                     from f in functionConvertedInformations where f.accessLevel == AccessLevel.Protected select f)
            {
                protectedHeader += functionConvertedInformation.signature + ";\n";
            }

            bool   hasMain = false;
            string sig     = "";

            foreach (FunctionConvertedInformation functionConvertedInformation in
                     from f in functionConvertedInformations where f.accessLevel == AccessLevel.Public select f)
            {
                publicHeader += functionConvertedInformation.signature + ";\n";
                //Console.WriteLine(functionConvertedInformation.signature);
                if (functionConvertedInformation.OriginalName == "main")
                {
                    Console.WriteLine("Main Method Found: " + functionConvertedInformation.signature);
                    hasMain = true;
                    sig     = functionConvertedInformation.signature;
                }
            }

            foreach (FunctionConvertedInformation functionConvertedInformation in functionConvertedInformations)
            {
                cFile += functionConvertedInformation.signature + "{\n";
                cFile += functionConvertedInformation.body;
                cFile += "}\n";
            }

            publicHeader    += "#endif";
            protectedHeader += "#endif";

            if (humanReadable)
            {
                cFile           = toHumanReadable(cFile);
                publicHeader    = toHumanReadable(publicHeader);
                protectedHeader = toHumanReadable(protectedHeader);
            }

            output.Add(new FileConvertedInformation(coopObject.Name + ".c", cFile));
            output.Add(new FileConvertedInformation(coopObject.Name + "_protected.h", protectedHeader));
            output.Add(new FileConvertedInformation(coopObject.Name + ".h", publicHeader));

            if (hasMain)
            {
                output[2].hasMainMethod = true;
                output[2].mainMethod    = sig;
                Console.WriteLine("Main Method Confirmed: " + sig);
            }

            return(output);
        }