public CodeWriter JoinStatement( ApplyStatement statement, string tempWriter, string list )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "foreach (var item in " );
            writer.AppendText( statement.From );
            writer.Indent = 0;
            writer.AppendLine( ")" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendText( tempWriter );
            writer.Indent = 0;
            writer.Append( " = this.Invoke( \"" );
            writer.AppendText( statement.ApplyMethod );
            writer.Indent = 0;
            writer.Append( "\", " );
            writer.AppendText( statement.Parameters );
            writer.Indent = 0;
            writer.AppendLine( " );" );
            writer.Indent = 1;
            writer.AppendText( list );
            writer.Indent = 0;
            writer.Append( ".Add( " );
            writer.AppendText( tempWriter );
            writer.Indent = 0;
            writer.AppendLine( " );" );
            writer.Append( "}" );

            return writer;
        }
        public CodeWriter Statement( CodeStatement code, string writerName )
        {
            var writer = new CodeWriter();

            writer.AppendText( code.Value );

            return writer;
        }
예제 #3
0
        public CodeWriter Class( RuleClassStatement ruleClassStatement, string fileName )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "public partial class " );
            writer.AppendText( ruleClassStatement.Name );
            writer.Indent = 0;
            writer.AppendLine( " : GeneratorBase" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in ruleClassStatement.RuleMethodStatements.OfType<MethodStatement>())
                {
                    temp = this.Invoke( "Method", item, fileName );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => mmg.IsMatched ).SelectMany( mmg => mmg.RuleMethodStatements ).Select( ms => ms.MatchMethodStatement ))
                {
                    temp = this.Invoke( "Match", item, fileName );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => mmg.IsMatched ).SelectMany( mmg => mmg.RuleMethodStatements ))
                {
                    temp = this.Invoke( "Rule", item, fileName, false, true );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => mmg.IsMatched ).SelectMany( mmg => mmg.DefaultStatements ))
                {
                    temp = this.Invoke( "Rule", item, fileName, true,  true );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => !mmg.IsMatched ).SelectMany( mmg => mmg.DefaultStatements ))
                {
                    temp = this.Invoke( "Rule", item, fileName, false, false );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
        public CodeWriter JoinStatement( CallStatement statement, string tempWriter, string list )
        {
            var writer = new CodeWriter();

            writer.AppendText( list );
            writer.Indent = 0;
            writer.Append( ".Add( " );
            writer.Append( this.Invoke( "GenerateInvoke", statement ) );
            writer.Indent = 0;
            writer.Append( " );" );

            return writer;
        }
        public CodeWriter Statement( CallStatement call, string writerName )
        {
            var writer = new CodeWriter();

            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( ".Append( " );
            writer.Append( this.Invoke( "GenerateInvoke", call ) );
            writer.Indent = 0;
            writer.Append( " );" );

            return writer;
        }
예제 #6
0
        public CodeWriter GetValue( EnumItem item )
        {
            var writer = new CodeWriter();

            writer.AppendText( ConvertName( item.Name ) );
            writer.Indent = 0;
            writer.Append( " = " );
            writer.AppendText( item.Value );
            writer.Indent = 0;
            writer.Append( "," );

            return writer;
        }
예제 #7
0
        public CodeWriter Generate( string @namespace, RuleClassStatement ruleClassStatement, string fileName )
        {
            var writer = new CodeWriter();

            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in ruleClassStatement.UsingStatements.Select( u => u.Namespace ).Concat( defaultNamespaces ).Distinct())
                {
                    temp = this.Invoke( "Using", item );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine();
            if (@namespace != null)
            {
            writer.Indent = 0;
            writer.Append( "namespace " );
            writer.AppendText( @namespace );
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.Append( this.Invoke( "Class", ruleClassStatement, fileName ) );
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine( "}" );
            }
            else
            {
            writer.Append( this.Invoke( "Class", ruleClassStatement, fileName ) );
            writer.Indent = 0;
            writer.AppendLine();
            }

            return writer;
        }
예제 #8
0
        public CodeWriter GenerateEnum( EnumData enumData, IList<TypeMap> typeMapList, IList<CSTypeMap> csTypeMapList )
        {
            var writer = new CodeWriter();

            var glTypeMap = typeMapList.FirstOrDefault(map => map.GLName == enumData.Name);
                    if (glTypeMap != null)
                    {
                        var csTypeMap = csTypeMapList.FirstOrDefault( map => map.GLName == glTypeMap.LanguageName.Name );
                        if (csTypeMap != null && csTypeMap.Attributes.Contains( "flags" ))
                        {
            writer.Indent = 0;
            writer.Append( "[Flags]" );
            }
                    }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "public enum " );
            writer.AppendText( GetCSName( enumData.Name ) );
            writer.Indent = 0;
            writer.AppendLine( " : uint" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in enumData.ItemList)
                {
                    temp = this.Invoke( "GetValue", item );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
        public CodeWriter JoinStatement( ValueStatement statement, string tempWriter, string list )
        {
            var writer = new CodeWriter();

            writer.AppendText( tempWriter );
            writer.Indent = 0;
            writer.AppendLine( " = new CodeWriter();" );
            writer.AppendText( tempWriter );
            writer.Indent = 0;
            writer.Append( ".AppendText( " );
            writer.AppendText( statement.Value );
            writer.Indent = 0;
            writer.AppendLine( " );" );
            writer.AppendText( list );
            writer.Indent = 0;
            writer.Append( ".Add( " );
            writer.AppendText( tempWriter );
            writer.Indent = 0;
            writer.Append( " );" );

            return writer;
        }
예제 #10
0
        public void CloneAppendTypeTest()
        {
            var codeWriter = new CodeWriter();

            var lines = new[]
                        {
                            "private int val;",
                            "private string val;"
                        };

            var commentText = "// ";
            codeWriter.Append( commentText );
            codeWriter.AppendType = AppendType.CloneLastLine;
            foreach (var line in lines)
            {
                codeWriter.AppendLine( line );
            }
            codeWriter.AppendType = AppendType.EmptyLastLine;

            var expectedText = string.Join( "\r\n", lines.Select( s => commentText + s ).ToArray() );
            var actualText = codeWriter.ToString();

            Assert.AreEqual( expectedText, actualText );
        }
        public CodeWriter Statement( TextStatement text, string writerName )
        {
            var writer = new CodeWriter();

            if (text.Lines.Count == 0) return new CodeWriter();

            var oldIndent = text.Lines[0].Indent;
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( ".Indent = " );
            writer.AppendText( oldIndent.ToString() );
            writer.Indent = 0;
            writer.AppendLine( ";" );
            for (var i = 0; i < text.Lines.Count; i++)
            {
                var line = text.Lines[i];

                if (oldIndent != line.Indent)
                {
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( ".Indent = " );
            writer.AppendText( line.Indent.ToString() );
            writer.Indent = 0;
            writer.AppendLine( ";" );
            oldIndent = line.Indent;
                }

                var generatedText = line.GetText().Replace( "\"", "\\\"" );
                string append;

                if (i == text.Lines.Count - 1 && !text.CropLastLine)
                {
                    if (generatedText == "") continue;
                    append = "Append";
                }
                else append = "AppendLine";

                string result;
                if (generatedText == "") result = "";
                else                     result = " \"" + generatedText + "\" ";
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( "." );
            writer.AppendText( append );
            writer.Indent = 0;
            writer.Append( "(" );
            writer.AppendText( result );
            writer.Indent = 0;
            writer.AppendLine( ");" );
            }

            return writer;
        }
예제 #12
0
        public CodeWriter GenerateInvoke_IsNotEmpty( CallStatement call )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "this.Invoke( \"" );
            writer.AppendText( call.Name );
            writer.Indent = 0;
            writer.Append( "\", " );
            writer.AppendText( call.Parameters );
            writer.Indent = 0;
            writer.Append( " )" );

            return writer;
        }
        public CodeWriter Statement( ValueStatement value, string writerName )
        {
            var writer = new CodeWriter();

            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( ".AppendText( " );
            writer.AppendText( value.Value );
            writer.Indent = 0;
            writer.Append( " );" );

            return writer;
        }
예제 #14
0
        public void SpaceAppendTypeTest()
        {
            var codeWriter = new CodeWriter();

            var lines = new[]
                        {
                            "int val",
                            "string val1",
                            "object val2",
                            "decimal val3",
                        };

            var startLineText = "Constructor( ";
            var endLineText = " )";
            codeWriter.Append( startLineText );
            codeWriter.AppendType = AppendType.SpaceLastLine;
            for (var i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                codeWriter.Append( line );
                if (i < lines.Length - 1) codeWriter.AppendLine( "," );
            }
            codeWriter.AppendLine( endLineText );
            codeWriter.AppendType = AppendType.EmptyLastLine;

            var expectedText = startLineText +
                               string.Join( ",\r\n", lines.Select(
                                                     	( s, i ) =>
                                                     	(i > 0
                                                     	 	? new string( ' ', startLineText.Length )
                                                     	 	: "") + s ).ToArray() ) +
                               endLineText;
            var actualText = codeWriter.ToString();

            Assert.AreEqual( expectedText, actualText );
        }
예제 #15
0
        public CodeWriter Rule( RuleMethodStatement ruleMethodStatement, string fileName, bool isDefault, bool generateAttribute )
        {
            var writer = new CodeWriter();

            if (generateAttribute)
            {
            writer.Indent = 0;
            writer.Append( "[RuleMethod( \"" );
            writer.AppendText( ruleMethodStatement.Name );
            writer.Indent = 0;
            writer.Append( "\", " );
            if (ruleMethodStatement.MatchMethodStatement != null){
            writer.Indent = 0;
            writer.Append( "\"" );
            writer.AppendText( ruleMethodStatement.MatchMethodStatement.Name );
            writer.Indent = 0;
            writer.Append( "\"" );
            }else{
            writer.Indent = 0;
            writer.Append( "null" );
            }
            writer.Indent = 0;
            writer.Append( ", \"" );
            writer.AppendText( fileName );
            writer.Indent = 0;
            writer.AppendLine( "\" )]" );
            }
            writer.Indent = 0;
            writer.Append( "public CodeWriter " );
            writer.AppendText( ruleMethodStatement.Name );
            if (ruleMethodStatement.MatchMethodStatement != null){
            writer.Indent = 0;
            writer.Append( "_" );
            writer.AppendText( ruleMethodStatement.MatchMethodStatement.Name );
            }else if (isDefault){
            writer.Indent = 0;
            writer.Append( "_Default" );
            }
            writer.Indent = 0;
            writer.Append( "(" );
            writer.Append( this.Invoke( "MethodParamenters", ruleMethodStatement.Variables ) );
            writer.Indent = 0;
            writer.AppendLine( ")" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendLine( "var writer = new CodeWriter();" );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in ruleMethodStatement.Statements)
                {
                    temp = this.Invoke( "Statement", item, "writer" );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine();
            writer.Indent = 1;
            writer.AppendLine( "return writer;" );
            writer.Indent = 0;
            writer.Append( "}" );

            return writer;
        }
예제 #16
0
        public CodeWriter MethodParamenters( IEnumerable<Variable> variables )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( " " );
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in variables)
                {
                    temp = this.Invoke( "Parameter", item );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( ", " );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.Append( " " );

            return writer;
        }
예제 #17
0
        public CodeWriter Using( string @namespace )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "using " );
            writer.AppendText( @namespace );
            writer.Indent = 0;
            writer.Append( ";" );

            return writer;
        }
예제 #18
0
 public void CodeWriterExceptionTest()
 {
     var codeWriter = new CodeWriter();
     codeWriter.Append( "new\r\nline" );
 }
예제 #19
0
 private static CodeWriter GetCodeWriter( IEnumerable<CodeWriterHelper> lines )
 {
     var codeWriter = new CodeWriter();
     AppendCodeWriter( codeWriter, lines );
     return codeWriter;
 }
예제 #20
0
 private static void AppendCodeWriter( CodeWriter codeWriter, IEnumerable<CodeWriterHelper> lines )
 {
     foreach (var line in lines)
     {
         codeWriter.Indent = line.indent;
         foreach (var text in line.texts)
             codeWriter.AppendText( text );
         codeWriter.AppendLine();
     }
 }
예제 #21
0
        public CodeWriter Match( MatchMethodStatement matchMethodStatement, string fileName )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "[MatchMethod( \"" );
            writer.AppendText( matchMethodStatement.RuleMethod.Name );
            writer.Indent = 0;
            writer.Append( "\", \"" );
            writer.AppendText( matchMethodStatement.Name );
            writer.Indent = 0;
            writer.Append( "\", \"" );
            writer.AppendText( fileName );
            writer.Indent = 0;
            writer.AppendLine( "\" )]" );
            writer.Append( "private bool Match_" );
            writer.AppendText( matchMethodStatement.RuleMethod.Name );
            writer.Indent = 0;
            writer.Append( "_" );
            writer.AppendText( matchMethodStatement.Name );
            writer.Indent = 0;
            writer.Append( "(" );
            writer.Append( this.Invoke( "MethodParamenters", matchMethodStatement.RuleMethod.Variables ) );
            writer.Indent = 0;
            writer.AppendLine( ")" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendText( matchMethodStatement.Code );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
예제 #22
0
        public CodeWriter Main( IEnumerable<Function> functionList, IList<TypeMap> typeMapList, IList<CSTypeMap> csTypeMapList, IList<EnumData> enumDatas, bool first, string name, IEnumerable<string> names )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.AppendLine( "using System;" );
            writer.AppendLine( "using System.Runtime.InteropServices;" );
            writer.AppendLine();
            writer.AppendLine( "namespace ManagedOpenGL" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendLine( "public static partial class OpenGLNative" );
            writer.AppendLine( "{	" );
            writer.Indent = 2;
            writer.Append( "static void OpenGLNative" );
            writer.AppendText( name.ToCSName() );
            writer.Indent = 0;
            writer.AppendLine( "Init()" );
            writer.Indent = 2;
            writer.AppendLine( "{" );
            writer.Indent = 3;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in functionList)
                {
                    temp = this.Invoke( "GetFunction", item, typeMapList, csTypeMapList, enumDatas );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 2;
            writer.AppendLine( "}" );
            if (first) {
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 2;
            writer.AppendLine( "static OpenGLNative()" );
            writer.AppendLine( "{" );
            writer.Indent = 3;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in names)
                {
                    temp = this.Invoke( "GenetateCallInit", item );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 2;
            writer.AppendLine( "}" );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 2;
            writer.AppendLine( "public static T GetProcAdress<T>( string functionName )" );
            writer.Indent = 3;
            writer.AppendLine( "where T : class" );
            writer.Indent = 2;
            writer.AppendLine( "{" );
            writer.Indent = 3;
            writer.AppendLine( "var ptr = WindowsOpenGLNative.wglGetProcAddress( functionName );" );
            writer.AppendLine( "if (ptr == IntPtr.Zero) return null;" );
            writer.AppendLine( "return Marshal.GetDelegateForFunctionPointer( ptr, typeof(T) ) as T;" );
            writer.Indent = 2;
            writer.AppendLine( "}" );
            }
            writer.Indent = 1;
            writer.AppendLine();
            writer.Indent = 2;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in functionList)
                {
                    temp = this.Invoke( "GenerateFunction", item, typeMapList, csTypeMapList, enumDatas );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 1;
            writer.AppendLine( "}" );
            writer.Indent = 0;
            writer.Append( "}" );

            return writer;
        }
예제 #23
0
        public CodeWriter Method( MethodStatement method, string fileName )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "public " );
            writer.AppendText( method.ReturnType.ToString() );
            writer.Indent = 0;
            writer.Append( " " );
            writer.AppendText( method.Name );
            writer.Indent = 0;
            writer.Append( "(" );
            writer.Append( this.Invoke( "MethodParamenters", method.Variables ) );
            writer.Indent = 0;
            writer.AppendLine( ")" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendText( method.Code );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
예제 #24
0
 public void Append( CodeWriter codeWriter )
 {
     AppendLines( codeWriter.Lines, false );
 }
예제 #25
0
        public CodeWriter Parameter( Variable var )
        {
            var writer = new CodeWriter();

            writer.AppendText( var.ToString() );

            return writer;
        }
        public CodeWriter Statement( JoinStatement join, string writerName )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendLine( "var list = new List<CodeWriter>();" );
            writer.AppendLine( "CodeWriter temp;" );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in join.Statements)
                {
                    temp = this.Invoke( "JoinStatement", item, "temp", "list" );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine();
            writer.Indent = 1;
            writer.Append( "writer.AppendType = AppendType." );
            writer.AppendText( join.AppendType.ToString() );
            writer.Indent = 0;
            writer.AppendLine( ";" );
            writer.Indent = 1;
            writer.AppendLine( "for (var listI = 0; listI < list.Count; listI++)" );
            writer.AppendLine( "{" );
            writer.Indent = 2;
            writer.AppendLine( "var codeWriter = list[listI];" );
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.AppendLine( ".Append( codeWriter );" );
            writer.Indent = 2;
            writer.AppendLine( "if (listI < list.Count - 1)" );
            writer.Indent = 3;
            writer.AppendText( writerName );
            writer.Indent = 0;
            writer.Append( ".AppendText( \"" );
            writer.AppendText( join.String );
            writer.Indent = 0;
            writer.AppendLine( "\" );" );
            writer.Indent = 1;
            writer.AppendLine( "}" );
            writer.AppendLine( "writer.AppendType = AppendType.EmptyLastLine;" );
            writer.Indent = 0;
            writer.Append( "}" );

            return writer;
        }
예제 #27
0
        public CodeWriter Using( UsingStatement usingStatement )
        {
            var writer = new CodeWriter();

            writer.Append( this.Invoke( "Namespace", usingStatement.Namespace ) );

            return writer;
        }
예제 #28
0
        public void PrivateTest()
        {
            var codeWriter = new CodeWriter();
            dynamic codeWriterAccessor = new AccessPrivateWrapper( codeWriter );

            Assert.IsNull( codeWriterAccessor.lastLine, "After initialize CodeWriter lastLine must be null" );
            Assert.IsNotNull( codeWriterAccessor.Lines, "Lines must be not null" );
            Assert.AreEqual( 0, codeWriterAccessor.Lines.Count, "Lines must be empty" );

            codeWriter.Append( "Test" );
            Assert.That( codeWriterAccessor.lastLine, Is.Not.Null, "After Append text lastLine must be not null" );
            Assert.That( codeWriter.Lines, Is.Not.Null.And.Count.EqualTo( 1 ),
                         "After first Append text code write must consist from one line" );

            codeWriter.AppendLine( "Text" );
            Assert.That( (object)codeWriterAccessor.lastLine, Is.Null, "After initialize CodeWriter lastLine must be null" );
            Assert.That( codeWriter.Lines, Is.Not.Null.And.Count.EqualTo( 1 ),
                         "After first Append text code write must consist from one line" );

            codeWriterAccessor.InnerAppend( "Text", false );
            Assert.That( codeWriterAccessor.lastLine, Is.Not.Null, "After Append text lastLine must be not null" );
            Assert.That( codeWriter.Lines, Is.Not.Null.And.Count.EqualTo( 2 ), "CodeWrite must consist from two line" );

            codeWriterAccessor.InnerAppend( "Text", true );
            Assert.That( (object)codeWriterAccessor.lastLine, Is.Null, "After Append text lastLine must be null" );
            Assert.That( codeWriter.Lines, Is.Not.Null.And.Count.EqualTo( 2 ), "CodeWrite must consist from two line" );

            codeWriter.AppendText( "new\r\nline" );
            Assert.That( codeWriterAccessor.lastLine, Is.Not.Null, "Appended text not finish last line, but CodeWriter finish it" );
            Assert.That( codeWriter.Lines, Is.Not.Null.And.Count.EqualTo( 4 ), "CodeWrite must consist from four line" );

            codeWriter.AppendText( "new\r\nlines\r\n" );
            Assert.That( (object)codeWriterAccessor.lastLine, Is.Null, "Appended text finish last line, but CodeWriter doesn't" );
            Assert.That( codeWriter.Lines, Is.Not.Null.And.Count.EqualTo( 5 ), "CodeWrite must consist from five line" );
        }
예제 #29
0
        public CodeWriter Main( IEnumerable<EnumData> enumList, IList<TypeMap> typeMapList, IList<CSTypeMap> csTypeMapList )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.AppendLine( "using System;" );
            writer.AppendLine();
            writer.AppendLine( "namespace ManagedOpenGL" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in enumList)
                {
                    temp = this.Invoke( "GenerateEnum", item, typeMapList, csTypeMapList );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
예제 #30
0
        public CodeWriter GetFunction( Function function, IList<TypeMap> typeMapList, IList<CSTypeMap> csTypeMapList, IList<EnumData> enumDatas )
        {
            var writer = new CodeWriter();

            if ((function.Version == null || (function.Version.MajorVersion <= 1 && function.Version.MinorVersion <= 1)) && !function.Contains( "extension" ))
                return writer;
            writer.Indent = 0;
            writer.Append( "_" );
            writer.AppendText( function.Name );
            writer.Indent = 0;
            writer.Append( " = GetProcAdress< " );
            writer.AppendText( function.Name );
            writer.Indent = 0;
            writer.Append( "Delegate >( \"gl" );
            writer.AppendText( function.Name );
            writer.Indent = 0;
            writer.Append( "\" );" );

            return writer;
        }