Пример #1
0
 public override void GenerateCode(ICodeGen gen)
 {
     foreach (Statement stmt in this.statement_list)
     {
         stmt.GenerateCode(gen);
     }
 }
Пример #2
0
        private static void GenCode(ICodeGen gen)
        {
            string strOut     = gen.ToCode();
            string strOutFile = gen.GetOutFileName();

            if (File.Exists(strOutFile))
            {
                StreamReader sr   = new StreamReader(strOutFile);
                string       file = sr.ReadToEnd();
                sr.Close();
                if (file == strOut)
                {
                    return;
                }
            }
            string dir = Path.GetDirectoryName(strOutFile);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            using (FileStream fs = new FileStream(strOutFile, FileMode.Create))
            {
                byte[] data = new UTF8Encoding().GetBytes(strOut);
                fs.Write(data, 0, data.Length);
                fs.SetLength(data.Length);
                fs.Flush();
                fs.Close();
            }
        }
        public static string MakeSource(ICodeGen codeGen)
        {
            var builder = new CodeBuilder();

            codeGen.CodeGen(builder);
            return(builder.ToString());
        }
        public UniformsAndFunctions(IEnumerable <NodeHelper <NodeInfo> > nodes, IList <NodeHelper <NodeInfo> > uniforms,
                                    ICodeGen codeGen)
        {
            Uniforms          = new HashSet <NodeHelper <NodeInfo> >(uniforms);
            _visitedFunctions = new HashSet <string>();
            Functions         = new List <RequiredFunction>();

            foreach (var scriptNode in nodes)
            {
                foreach (var uniform in codeGen.GetRequiredUniforms(scriptNode))
                {
                    Uniforms.Add(uniform);
                }
                foreach (var requiredFunction in codeGen.GetRequiredFunctions(scriptNode))
                {
                    AddFunction(requiredFunction, codeGen);
                }
            }

            foreach (var shaderUniform in Uniforms)
            {
                if (shaderUniform.Extra == null)
                {
                    shaderUniform.Extra = new NodeInfo {
                        Define = new PaintDefines.Container {
                            IsAlways = true
                        }
                    }
                }
            }
            ;
        }
Пример #5
0
        public static void Static(ITextTemplatingEngineHost host, string qualifiedAssemblyName, GrassOptions codeGenOptions = null)
        {
            var options = codeGenOptions ?? new GrassOptions();

            var callContext = CallContext.LogicalGetData("NamespaceHint");
            var ns          = callContext == null ? "ArtisanCode.Grass.GeneratedContent" : callContext.ToString();

            var staticClass = new ClassDefinition(qualifiedAssemblyName, ns, options);

            staticClass.PopulateStaticMethods(codeGenOptions);

            ICodeGen engine = CreateCodeGenEngine(host);

            var emittedInterface     = engine.EmitInterface(ns, staticClass, options);
            var emittedStaticWrapper = engine.EmitStaticWrapperClass(ns, staticClass, options);

            string templateDirectory    = Path.GetDirectoryName(host.TemplateFile);
            string interfaceFilePath    = Path.Combine(templateDirectory, emittedInterface.Filename);
            string classWrapperFilePath = Path.Combine(templateDirectory, emittedStaticWrapper.Filename);


            WriteCodefileToDisk(engine, emittedInterface.CompilationOutput, interfaceFilePath);
            WriteCodefileToDisk(engine, emittedStaticWrapper.CompilationOutput, classWrapperFilePath);

            AddFileToTemplate(host, interfaceFilePath);
            AddFileToTemplate(host, classWrapperFilePath);
        }
Пример #6
0
 public override void GenerateCode(ICodeGen gen)
 {
     if (!(this.expression is EmptyExpression))
     {
         this.expression.GenerateCode(gen);
         if (!(this.expression.GetType() is Symbols.VOID))
         {
             gen.Pop();
         }
     }
 }
Пример #7
0
        private static void RunT4TemplateImpl(ICodeGen eval, string file)
        {
            var output = @"..\..\..\PicNetML\" + file + ".cs";

            if (File.Exists(output))
            {
                File.Delete(output);
            }
            var generated = eval.TransformText();

            File.WriteAllText(output, generated);
        }
Пример #8
0
        private static void WriteCodefileToDisk(ICodeGen engine, CodeCompileUnit emittedInterface, string outputFilePath)
        {
            CodeDomProvider      provider = engine.CreateCodeDomProvider();
            CodeGeneratorOptions options  = new CodeGeneratorOptions();

            options.BracingStyle = "C";
            using (StreamWriter sourceWriter = new StreamWriter(outputFilePath))
            {
                provider.GenerateCodeFromCompileUnit(emittedInterface, sourceWriter, options);
                sourceWriter.Flush();
            }
        }
Пример #9
0
            public override void GenerateCode(ICodeGen gen)
            {
                int local = this.GetTable().GetVariables().Sum(v => v is ParamVar ? 0 : v.GetType().GetSizeType());

                gen.StartProc(this);
                foreach (LocalVar v in this.GetTable().GetVariables())
                {
                    gen.Decl(v);
                }

                this.body.GenerateCode(gen);
                gen.EndProc();
            }
Пример #10
0
 public override void GenerateCode(ICodeGen gen)
 {
     this.operand.GenerateCode(gen);
     if (this.type_cast is Symbols.INT || this.type_cast is Symbols.POINTER)
     {
         gen.ToInt(this.type_cast.GetSizeType());
     }
     else if (this.type_cast is Symbols.CHAR)
     {
         gen.ToInt(this.type_cast.GetSizeType());
     }
     else if (this.type_cast is Symbols.DOUBLE)
     {
         gen.ToFloat(this.type_cast.GetSizeType());
     }
 }
 private void AddFunction(RequiredFunction requiredFunction, ICodeGen codeGen)
 {
     if (!_visitedFunctions.Add(requiredFunction.Name))
     {
         return;
     }
     foreach (var uniform in codeGen.GetRequiredUniforms(requiredFunction))
     {
         Uniforms.Add(uniform);
     }
     foreach (var depFunction in codeGen.GetRequiredFunctions(requiredFunction))
     {
         AddFunction(depFunction, codeGen);
     }
     Functions.Add(requiredFunction);
 }
Пример #12
0
            public override void GenerateCode(ICodeGen gen)
            {
                this.arguments.Reverse();
                foreach (Expression arg in this.arguments)
                {
                    arg.GenerateCode(gen);
                }
                this.arguments.Reverse();

                this.operand.GenerateCode(gen);
                gen.Call((Symbols.Func) this.operand.GetType());

                for (int i = 0; i < this.arguments.Count; ++i)
                {
                    gen.Pop();
                }
            }
Пример #13
0
            public override void GenerateCode(ICodeGen gen)
            {
                this.left_operand.GenerateCode(gen);
                this.right_operand.GenerateCode(gen);
                switch (this.op.type)
                {
                case Token.Type.OP_STAR: break;

                case Token.Type.OP_ASSIGN: gen.Mov(); break;

                case Token.Type.OP_MOD: gen.Mod(); break;

                case Token.Type.OP_DIV: gen.Div(); break;

                case Token.Type.OP_PLUS: gen.Add(); break;

                case Token.Type.OP_SUB: gen.Sub(); break;

                case Token.Type.OP_XOR: gen.Xor(); break;

                case Token.Type.OP_BIT_AND: break;

                case Token.Type.OP_BIT_OR: break;

                case Token.Type.OP_AND: break;

                case Token.Type.OP_OR: break;

                case Token.Type.OP_EQUAL: break;

                case Token.Type.OP_NOT_EQUAL: break;

                case Token.Type.OP_MORE: break;

                case Token.Type.OP_LESS: break;

                case Token.Type.OP_MORE_OR_EQUAL: break;

                case Token.Type.OP_LESS_OR_EQUAL: break;

                case Token.Type.OP_L_SHIFT: break;

                case Token.Type.OP_R_SHIFT: break;
                }
            }
Пример #14
0
 public override void GenerateCode(ICodeGen gen)
 {
     if (this.GetType() is Func)
     {
         if (this.GetType() is ExternFunc)
         {
             gen.Import(this);
         }
         else
         {
             this.GetType().GenerateCode(gen);
         }
     }
     else
     {
         gen.Decl(this);
     }
 }
Пример #15
0
        private void GenerateCodeForNamespace(IEnumerable <Type> alltypes, Type generator, string ns, string targetdir)
        {
            Type[] types = alltypes.
                           Where(t => t.Namespace == ns).
                           ToArray();
            ns = ns.Replace("weka.", string.Empty);
            string[] tokens   = ns.Split('.');
            string   typename = string.Join(string.Empty, tokens.Select(w => char.ToUpper(w[0]) + w.Substring(1)));

            if (tokens.Length == 1)
            {
                typename += "General";
            }

            Console.WriteLine("Generating for type: " + typename);
            ICodeGen codegen = (ICodeGen)Activator.CreateInstance(generator, new object[] { types });

            generator.GetProperty("TypeName").SetValue(codegen, typename);
            RunT4TemplateImpl(codegen, targetdir + @"\Generated\" + typename);
        }
Пример #16
0
        public static void EmitCode(Node root, ICodeGen gen, StringBuilder sb, string nspace, bool supportsGC, bool internalFile)
        {
            gen.EmitNamespace(sb, false, nspace);

            int level = 0;

            if (gen.SupportsNamespace())
            {
                level = 1;
            }

            if (internalFile)
            {
                gen.EmitSerialBase(sb, level, supportsGC);
            }

            foreach (Node n in root.childNodes)
            {
                gen.EmitNode(n, sb, level);
            }

            gen.EmitNamespace(sb, true, nspace);
        }
Пример #17
0
 public override void GenerateCode(ICodeGen gen)
 {
 }
Пример #18
0
        private static void ParseFile(string projectPath, string path, string file, string nspace, string outputPath, string outFile, bool supportsGC, ICodeGen codeGen, string fileNameSuffix)
        {
            string languagePath = Path.Combine(projectPath, path);

            Directory.SetCurrentDirectory(languagePath);
            Queue <Token> tokenList = LanguageParser.TokenizeString(File.ReadAllText(Path.Combine(languagePath, file)));

            Node root = TokenAnalyzer.Analyze(tokenList);

            Node rootEnumNode    = new Node();
            Node rootMessageNode = new Node();

            // this is now heavily c# based code
            // anyone looking to modify JavaGen or crate a different generator has their work cut out for them

            rootEnumNode.childNodes.AddRange(root.childNodes.Where(n => n is EnumNode));
            rootMessageNode.childNodes.AddRange(root.childNodes.Where(n => n is ClassNode));

            StringBuilder enumBuilder    = new StringBuilder();
            StringBuilder messageBuilder = new StringBuilder();

            CodeGenerator.EmitCode(rootEnumNode, codeGen, enumBuilder, nspace, supportsGC, false);
            CodeGenerator.EmitCode(rootMessageNode, codeGen, messageBuilder, nspace + ".Internal", supportsGC, true);

            string outputEnumFile    = Path.Combine(outputPath, outFile + "." + fileNameSuffix);
            string outputMessageFile = Path.Combine(outputPath, outFile + "Internal." + fileNameSuffix);

            File.WriteAllText(Path.Combine(projectPath, outputEnumFile), enumBuilder.ToString());
            File.WriteAllText(Path.Combine(projectPath, outputMessageFile), messageBuilder.ToString());
        }
Пример #19
0
        public static void EmitCode(Node root, ICodeGen gen, StringBuilder sb, string nspace, bool supportsGC, bool internalFile )
        {
            gen.EmitNamespace(sb, false, nspace);

            int level = 0;
            if (gen.SupportsNamespace())
                level = 1;

            if ( internalFile )
                gen.EmitSerialBase( sb, level, supportsGC );

            foreach (Node n in root.childNodes)
            {
                gen.EmitNode(n, sb, level);
            }

            gen.EmitNamespace(sb, true, nspace);
        }
Пример #20
0
 public override void GenerateCode(ICodeGen gen)
 {
     if (!(this.expression is EmptyExpression))
     {
         this.expression.GenerateCode(gen);
         if (!(this.expression.GetType() is Symbols.VOID))
         {
             gen.Pop();
         }
     }
 }
Пример #21
0
 public override void GenerateCode(ICodeGen gen)
 {
     this.left_operand.GenerateCode(gen);
     this.right_operand.GenerateCode(gen);
     switch (this.op.type)
     {
         case Token.Type.OP_STAR: break;
         case Token.Type.OP_ASSIGN: gen.Mov(); break;
         case Token.Type.OP_MOD: gen.Mod(); break;
         case Token.Type.OP_DIV: gen.Div(); break;
         case Token.Type.OP_PLUS: gen.Add(); break;
         case Token.Type.OP_SUB: gen.Sub(); break;
         case Token.Type.OP_XOR: gen.Xor(); break;
         case Token.Type.OP_BIT_AND: break;
         case Token.Type.OP_BIT_OR: break;
         case Token.Type.OP_AND: break;
         case Token.Type.OP_OR: break;
         case Token.Type.OP_EQUAL: break;
         case Token.Type.OP_NOT_EQUAL: break;
         case Token.Type.OP_MORE: break;
         case Token.Type.OP_LESS: break;
         case Token.Type.OP_MORE_OR_EQUAL: break;
         case Token.Type.OP_LESS_OR_EQUAL: break;
         case Token.Type.OP_L_SHIFT: break;
         case Token.Type.OP_R_SHIFT: break;
     }
 }
Пример #22
0
 public override void GenerateCode(ICodeGen gen)
 {
     foreach (Statement stmt in this.statement_list)
     {
         stmt.GenerateCode(gen);
     }
 }
Пример #23
0
 public override void GenerateCode(ICodeGen gen)
 {
     gen.Push(this);
 }
Пример #24
0
 public override void GenerateCode(ICodeGen gen)
 {
     this.operand.GenerateCode(gen);
     if (this.type_cast is Symbols.INT || this.type_cast is Symbols.POINTER)
     {
         gen.ToInt(this.type_cast.GetSizeType());
     }
     else if (this.type_cast is Symbols.CHAR)
     {
         gen.ToInt(this.type_cast.GetSizeType());
     }
     else if (this.type_cast is Symbols.DOUBLE)
     {
         gen.ToFloat(this.type_cast.GetSizeType());
     }
 }
Пример #25
0
            public override void GenerateCode(ICodeGen gen)
            {
                this.arguments.Reverse();
                foreach (Expression arg in this.arguments)
                {
                    arg.GenerateCode(gen);
                }
                this.arguments.Reverse();

                this.operand.GenerateCode(gen);
                gen.Call((Symbols.Func)this.operand.GetType());

                for (int i = 0; i < this.arguments.Count; ++i )
                {
                    gen.Pop();
                }
            }
Пример #26
0
 public override void GenerateCode(ICodeGen gen)
 {
     gen.Push(this);
 }
Пример #27
0
 public virtual void GenerateCode(ICodeGen gen)
 {
 }
Пример #28
0
            public override void GenerateCode(ICodeGen gen)
            {
                int local = this.GetTable().GetVariables().Sum(v => v is ParamVar ? 0 : v.GetType().GetSizeType());
                gen.StartProc(this);
                foreach (LocalVar v in this.GetTable().GetVariables())
                {
                    gen.Decl(v);
                }

                this.body.GenerateCode(gen);
                gen.EndProc();
            }
Пример #29
0
 public override void GenerateCode(ICodeGen gen)
 {
 }
Пример #30
0
 virtual public void GenerateCode(ICodeGen gen)
 {
 }
Пример #31
0
 public override void GenerateCode(ICodeGen gen)
 {
     if (this.GetType() is Func)
     {
         if (this.GetType() is ExternFunc)
         {
             gen.Import(this);
         }
         else
         {
             this.GetType().GenerateCode(gen);
         }
     }
     else
     {
         gen.Decl(this);
     }
 }