Exemplo n.º 1
0
        public static void WriteVariableString(LangStreamWrapper stream, VariableObj variableObj, string namespaceName = "")
        {
            string typeString = ConvertDataType(variableObj.Type);

            if (typeString != "")
            {
                typeString += " ";
            }

            stream.Write(typeString + CreateNamespaceString(variableObj.Name, namespaceName));
        }
Exemplo n.º 2
0
        private void WriteSourceFile(CppWriter cppWriter)
        {
            LangStreamWrapper stream = cppWriter.SourceStream;

            foreach (ClassFunction classFunc in _functions)
            {
                stream.NewLine();

                CppWriter.WriteFunctionString(stream, classFunc.functionObj, CppWriter.CreateNamespaceString(_className, _namespaceName));
                stream.NewLine();
                stream.WriteLine("{");

                stream.IncreaseTab();
                classFunc.functionObj.ContentDelegate?.Invoke(stream);
                stream.DecreaseTab();

                stream.WriteLine("}");
            }
        }
Exemplo n.º 3
0
        public override void BeginWriter(string filename)
        {
            var headerFilenameInfo = new FilenameInfo(filename);

            headerFilenameInfo.Extname = ".h";
            HeaderStream = new LangStreamWrapper(
                new StreamWriter(
                    new FileStream(headerFilenameInfo.FullFilename, FileMode.Create, FileAccess.Write)
                    )
                );

            var sourceFilenameInfo = new FilenameInfo(filename);

            sourceFilenameInfo.Extname = ".cpp";
            SourceStream = new LangStreamWrapper(
                new StreamWriter(
                    new FileStream(sourceFilenameInfo.FullFilename, FileMode.Create, FileAccess.Write)
                    )
                );
        }
Exemplo n.º 4
0
        public static void WriteFunctionString(LangStreamWrapper stream, FunctionObj functionObj, string namespaceName = "")
        {
            WriteVariableString(stream, functionObj.TypeAndName, namespaceName);
            stream.Write("(");

            int index = 0;

            foreach (VariableObj funcParam in functionObj.FuncParams)
            {
                WriteVariableString(stream, funcParam, "");

                //add comma if not the last param
                if (index != functionObj.FuncParams.Count - 1)
                {
                    stream.Write(", ");
                }

                index++;
            }
            stream.Write(")");
        }
Exemplo n.º 5
0
        private void WriteHeaderFile(CppWriter cppWriter)
        {
            LangStreamWrapper stream = cppWriter.HeaderStream;

            var publicMembers    = new List <WriteToStream>();
            var protectedMembers = new List <WriteToStream>();
            var privateMembers   = new List <WriteToStream>();

            Action <AccessModifier, WriteToStream> EvaluateAccessModifier = (accessModifier, writeDelegate) =>
            {
                switch (accessModifier)
                {
                case AccessModifier.PRIVATE:
                    privateMembers.Add(writeDelegate);
                    break;

                case AccessModifier.PROTECTED:
                    protectedMembers.Add(writeDelegate);
                    break;

                default:     //ACCESS_PUBLIC
                    publicMembers.Add(writeDelegate);
                    break;
                }
            };

            //init member string
            {
                foreach (InnerClass innerClass in _innerClasses)
                {
                    EvaluateAccessModifier(innerClass.accessModifier, () =>
                    {
                        innerClass.classBuilder.WriteClass(cppWriter);
                        stream.NewLine();
                    });
                }

                foreach (ClassFunction classFunc in _functions)
                {
                    EvaluateAccessModifier(classFunc.accessModifier, () =>
                    {
                        CppWriter.WriteFunctionString(stream, classFunc.functionObj);
                        stream.WriteLine(";");
                    });
                }

                foreach (ClassMemeber classMemeber in _members)
                {
                    EvaluateAccessModifier(classMemeber.accessModifier, () =>
                    {
                        CppWriter.WriteVariableString(stream, classMemeber.variableObj);
                        stream.WriteLine(";");
                    });
                }
            }

            //write the file
            {
                stream.WriteLine("class " + _className);
                stream.WriteLine("{");
                {
                    var memberTuples = new List <Tuple <string, List <WriteToStream> > >();
                    memberTuples.Add(new Tuple <string, List <WriteToStream> >("public", publicMembers));
                    memberTuples.Add(new Tuple <string, List <WriteToStream> >("protected", protectedMembers));
                    memberTuples.Add(new Tuple <string, List <WriteToStream> >("private", privateMembers));

                    foreach (Tuple <string, List <WriteToStream> > memberTuple in memberTuples)
                    {
                        List <WriteToStream> writeMemberDelegates = memberTuple.Item2;
                        if (writeMemberDelegates.Count > 0)
                        {
                            stream.WriteLine(memberTuple.Item1 + ":");

                            stream.IncreaseTab();
                            foreach (WriteToStream writeMemberDelegate in writeMemberDelegates)
                            {
                                writeMemberDelegate.Invoke();
                            }
                            stream.DecreaseTab();

                            stream.NewLine();
                        }
                    }
                }
                stream.WriteLine("};");
            }
        }