当前位置: 首页>>代码示例>>C#>>正文


C# Compiler类代码示例

本文整理汇总了C#中Compiler的典型用法代码示例。如果您正苦于以下问题:C# Compiler类的具体用法?C# Compiler怎么用?C# Compiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Compiler类属于命名空间,在下文中一共展示了Compiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileDereference

        protected virtual Expression CompileDereference(Compiler compiler, Frame frame, Expression left, Parse.BinaryExpression expression, System.Type typeHint)
        {
            left = compiler.MaterializeReference(left);

            var local = compiler.AddFrame(frame, expression);
            var memberType = left.Type.GenericTypeArguments[0];
            var parameters = new List<ParameterExpression>();

            var valueParam = compiler.CreateValueParam(expression, local, left, memberType);
            parameters.Add(valueParam);

            var indexParam = compiler.CreateIndexParam(expression, local);
            parameters.Add(indexParam);

            var right =
                compiler.MaterializeReference
                (
                    compiler.CompileExpression(local, expression.Right, typeHint)
                );

            var selection = Expression.Lambda(right, parameters);
            var select =
                typeof(Enumerable).GetMethodExt
                (
                    "Select",
                    new System.Type[] { typeof(IEnumerable<ReflectionUtility.T>), typeof(Func<ReflectionUtility.T, int, ReflectionUtility.T>) }
                );
            select = select.MakeGenericMethod(memberType, selection.ReturnType);
            return Expression.Call(select, left, selection);
        }
开发者ID:jgabb8989,项目名称:DotQL,代码行数:30,代码来源:NaryTypeHandler.cs

示例2: Main

 public static void Main(string[] args)
 {
     InputStream input = new InputStream("source.c");
     BytecodeStream output = new BytecodeStream();
     Compiler compiler = new Compiler();
     compiler.Compile(input, output);
 }
开发者ID:possientis,项目名称:Prog,代码行数:7,代码来源:facade.cs

示例3: GLVertoutput

        /// <summary>
        /// Create OpenGL object. Standard object constructor for ProtoFX.
        /// </summary>
        /// <param name="block"></param>
        /// <param name="scene"></param>
        /// <param name="debugging"></param>
        public GLVertoutput(Compiler.Block block, Dict scene, bool debugging)
            : base(block.Name, block.Anno)
        {
            var err = new CompileException($"vertoutput '{name}'");

            // PARSE ARGUMENTS
            Cmds2Fields(block, err);

            // CREATE OPENGL OBJECT
            glname = GL.GenTransformFeedback();
            GL.BindTransformFeedback(TransformFeedbackTarget.TransformFeedback, glname);

            // parse commands
            int numbindings = 0;
            foreach (var cmd in block["buff"])
                Attach(numbindings++, cmd, scene, err | $"command '{cmd.Text}'");

            // if errors occurred throw exception
            if (err.HasErrors())
                throw err;

            // unbind object and check for errors
            GL.BindTransformFeedback(TransformFeedbackTarget.TransformFeedback, 0);
            if (HasErrorOrGlError(err, block))
                throw err;
        }
开发者ID:h3tch,项目名称:ProtoFX,代码行数:32,代码来源:GLVertoutput.cs

示例4: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            if (((Literal)node).Value == null)
            {
                // nil
                compiler.AppendLine("$_stack[] = new F_NilClass;");
                return;
            }
            if (((Literal)node).Value is bool)
            {
                // True or False
                compiler.AppendLine("$_stack[] = new F_{0}Class;", ((Literal)node).Value.ToString());
                return;
            }
            if (((Literal)node).Value is string)
            {
                switch (((Literal)node).Value.ToString())
                {
                    case "self":
                        compiler.AppendLine("$_stack[] = $_locals->self;", ((Literal)node).Value.ToString());
                        break;
                    case "__FILE__":
                    case "__LINE__":
                        compiler.AppendLine("$_stack[] = F_String::__from_string({0});", ((Literal)node).Value.ToString());
                        break;
                }
                return;
            }

            compiler.AppendLine("$_stack[] = F_Number::__from_number({0});", ((Literal)node).Value.ToString());
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:31,代码来源:Literal.cs

示例5: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            var pmethod = parent.OfType<MethodDefinition>().SingleOrDefault();
            var isInBlock = pmethod != null && pmethod.Name.Contains("__lambda_");

            if (((ReturnStatement)node).Arguments == null || ((ReturnStatement)node).Arguments.Expressions.Count() == 0)
            {
                compiler.AppendLine("$_stack[] = new F_NilClass;");
            }
            else if (((ReturnStatement)node).Arguments.Expressions.Count() > 0)
            {
                compiler.CompileNode(((ReturnStatement)node).Arguments.Expressions.First(), parent.CreateChild(node));
            }
            else
            {
                compiler.CompileNode(new ArrayConstructor(((ReturnStatement)node).Arguments, ((ReturnStatement)node).Location), parent.CreateChild(node));
            }

            if (!isInBlock)
            {
                compiler.AppendLine("return array_pop($_stack);");
            }
            else
            {
                compiler.AppendLine("throw new ReturnFromBlock(array_pop($_stack));");
            }
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:27,代码来源:Return.cs

示例6: CompileCSharp6

        public void CompileCSharp6()
        {
            // see https://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status&referringTitle=Documentation

            const string code1 = @"
using System;
namespace Whatever
{
    public class Something
    {
        // auto-property initializer
        public int Value { get; set; } = 3;

        public void DoSomething()
        {
            Console.WriteLine(""Hello!"");
        }

        public void DoSomething(string[] args)
        {
            // conditional access
            var len = args?.Length ?? 0;
        }
    }
}
";

            var compiler = new Compiler(LanguageVersion.CSharp6);
            compiler.Compile(_tempDir, "Whatever", new Dictionary<string, string> { { "code", code1 } });
            Assert.IsTrue(File.Exists(Path.Combine(_tempDir, "Whatever.dll")));
        }
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:31,代码来源:CompilerTests.cs

示例7: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            if (node is IsDefinedExpression)
            {
                var ide = (IsDefinedExpression)node;
                switch(ide.Expression.NodeType)
                {
                    case NodeTypes.MethodCall:
                        compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(function_exists('{0}'));", Mangling.RubyMethodToPHP(((MethodCall)ide.Expression).MethodName));
                        return;
                    case NodeTypes.ConstantVariable:
                        compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(class_exists('{0}'));", Mangling.RubyMethodToPHP(((ConstantVariable)ide.Expression).Name));
                        return;
                    case NodeTypes.ClassVariable:
                    case NodeTypes.GlobalVariable:
                    case NodeTypes.InstanceVariable:
                    case NodeTypes.LocalVariable:
                        compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(isset({0}));", ((Variable)ide.Expression).ToPHPVariable());
                        return;
                    default:
                        throw new FructoseCompileException("Not supported yet: defined?( " + ide.Expression.NodeType.ToString() + " )", ide.Expression);
                }

            }
            else
                throw new FructoseCompileException("Not supported yet: " + node.ToString(), node);
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:27,代码来源:DescriptionExpression.cs

示例8: Compile

        public override void Compile(Compiler compiler, IronRuby.Compiler.Ast.Node node, NodeParent parent)
        {
            var sae = (SimpleAssignmentExpression)node;

            // substitute a method call of []= rather than the crap that ironruby's parser produces:
            switch (sae.Left.NodeType)
            {
                case NodeTypes.ArrayItemAccess:
                    var aia = (ArrayItemAccess)sae.Left;
                    compiler.CompileNode(new MethodCall(aia.Array, "[]=", new Arguments(aia.Arguments.Expressions.Concat(new[] { sae.Right }).ToArray()), sae.Location), parent.CreateChild(node));
                    return;
                case NodeTypes.AttributeAccess:
                    var aa = (AttributeAccess)sae.Left;
                    compiler.CompileNode(new MethodCall(aa.Qualifier, aa.Name, new Arguments(sae.Right), aa.Location), parent.CreateChild(node));
                    return;
            }

            compiler.CompileNode(sae.Right, parent.CreateChild(node));
            if (sae.Operation != null)
            {
                compiler.AppendLine("$_stack[] = {0};", assignmentVar(sae.Left, parent));
                compiler.AppendLine("$_stack[] = array_pop($_stack)->{0}(NULL, array_pop($_stack));", Mangling.RubyMethodToPHP(sae.Operation));
            }
            compiler.AppendLine("{0} = $_stack[count($_stack)-1];", assignmentVar(sae.Left, parent));
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:25,代码来源:Assignment.cs

示例9: CompilerLanguageVersionTest

        public void CompilerLanguageVersionTest()
        {
            const string code = @"
class Test
{
    private string GetValue()
    {
        return ""value"";
    }

    // this is csharp v6
    public string Value => this.GetValue();
}
";
            var files = new Dictionary<string, string> { { "source", code } };
            SyntaxTree[] trees;
            Compiler compiler;

            Assert.Throws<Exception>(() =>
            {
                compiler = new Compiler();
                compiler.GetCompilation("Umbraco.ModelsBuilder.Generated", files, out trees);
            });

            // works
            compiler = new Compiler(LanguageVersion.CSharp6);
            compiler.GetCompilation("Umbraco.ModelsBuilder.Generated", files, out trees);
        }
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:28,代码来源:RoslynTests.cs

示例10: Compile

 public void Compile(ProgramGraph graph, CompilerOutputInfo info)
 {
     if (!(info is ShaderOutputInfo))
     return;
      ShaderOutputInfo outputInfo = info as ShaderOutputInfo;
      RegisterDict = new Dictionary<string, int>();
      for(int i = 0; i < graph.getMaxDepth(); i++)
      {
     foreach (Vertex v in graph.getVerticesForLayer(i))
     {
        foreach (NodeItem outputItem in v.Data.Items.Where(item => item.Output.Enabled))
        {
           if(outputItem.OutputData is ShaderTypes.sampler2D)
           {
              ShaderTypes.sampler2D Sampler = (ShaderTypes.sampler2D)outputItem.OutputData;
              if (!RegisterDict.ContainsKey(Sampler.path))
                 RegisterDict.Add(Sampler.path, RegisterDict.Count);
           }
        }
     }
      }
      mCompiler = new HLSLCompiler(new Dictionary<object, string>(), RegisterDict);
      WritePostFxScript(outputInfo);
      if (mCompiler == null)
     return;
      mCompiler.Compile(graph, outputInfo);
 }
开发者ID:RichardRanft,项目名称:CGF,代码行数:27,代码来源:T3DPostFxCompiler.cs

示例11: Initialise

 public void Initialise(Compiler compiler)
 {
     if (compiler.m_XEngineLSLCompatabilityModule)
         LSL_Converter = new LegacyCSCodeGenerator();
     else
         LSL_Converter = new CSCodeGenerator(compiler.m_SLCompatabilityMode, null);
 }
开发者ID:NickyPerian,项目名称:Aurora,代码行数:7,代码来源:LSLConverter.cs

示例12: EmitDedicatedMethod

        bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
        {
            System.Reflection.Emit.MethodBuilder method = ctx.GetDedicatedMethod(key, read);
            if (method == null) return false;
            using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, typeof(SubItemToken)))
            {
                Type rwType = read ? typeof(ProtoReader) : typeof(ProtoWriter);
                ctx.LoadValue(valueFrom);
                if (!read) // write requires the object for StartSubItem; read doesn't
                {
                    if (type.IsValueType) { ctx.LoadNullRef(); }
                    else { ctx.CopyValue(); }
                }
                ctx.LoadReaderWriter();
                ctx.EmitCall(rwType.GetMethod("StartSubItem"));
                ctx.StoreValue(token);

                // note: value already on the stack
                ctx.LoadReaderWriter();                
                ctx.EmitCall(method);
                // handle inheritance (we will be calling the *base* version of things,
                // but we expect Read to return the "type" type)
                if (read && type != method.ReturnType) ctx.Cast(this.type);
                ctx.LoadValue(token);
                
                ctx.LoadReaderWriter();
                ctx.EmitCall(rwType.GetMethod("EndSubItem"));
            }            
            return true;
        }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:30,代码来源:SubItemSerializer.cs

示例13: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
            using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
            using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
            {
                ctx.LoadReaderWriter();
                ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
                ctx.StoreValue(token);

                Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();

                ctx.MarkLabel(next);

                ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
                ctx.CopyValue();
                ctx.StoreValue(field);
                ctx.LoadValue(Tag); // = 1 - process
                ctx.BranchIfEqual(processField, true);
                ctx.LoadValue(field);
                ctx.LoadValue(1); // < 1 - exit
                ctx.BranchIfLess(end, false);

                // default: skip
                ctx.LoadReaderWriter();
                ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
                ctx.Branch(next, true);

                // process
                ctx.MarkLabel(processField);
                if (Tail.RequiresOldValue)
                {
                    if (Helpers.IsValueType(expectedType))
                    {
                        ctx.LoadAddress(oldValue, expectedType);
                        ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
                    }
                    else
                    {
                        ctx.LoadValue(oldValue);
                    }
                }
                Tail.EmitRead(ctx, null);
                // note we demanded always returns a value
                if (Helpers.IsValueType(expectedType))
                {
                    ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
                }
                ctx.StoreValue(oldValue);
                ctx.Branch(next, false);

                // outro
                ctx.MarkLabel(end);
               
                ctx.LoadValue(token);
                ctx.LoadReaderWriter();
                ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
                ctx.LoadValue(oldValue); // load the old value
            }
        }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:60,代码来源:NullDecorator.cs

示例14: EmitBeq

        private void EmitBeq(Compiler.CompilerContext ctx, Compiler.CodeLabel label, Type type)
        {
            switch (Helpers.GetTypeCode(type))
            {
                case ProtoTypeCode.Boolean:
                case ProtoTypeCode.Byte:
                case ProtoTypeCode.Char:
                case ProtoTypeCode.Double:
                case ProtoTypeCode.Int16:
                case ProtoTypeCode.Int32:
                case ProtoTypeCode.Int64:
                case ProtoTypeCode.SByte:
                case ProtoTypeCode.Single:
                case ProtoTypeCode.UInt16:
                case ProtoTypeCode.UInt32:
                case ProtoTypeCode.UInt64:
                    ctx.BranchIfEqual(label, false);
                    break;
                default:
                    MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Public | BindingFlags.Static,
                        null, new Type[] { type, type }, null);
                    if (method == null || method.ReturnType != typeof(bool))
                    {
                        throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
                    }
                    ctx.EmitCall(method);
                    ctx.BranchIfTrue(label, false);
                    break;

            }
        }
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:31,代码来源:DefaultValueDecorator.cs

示例15: Emitter

        public Emitter(Compiler compiler)
        {
            Compiler = compiler;

              // create assembly object
              var name = new AssemblyNameDefinition("MirelleCompiled", new Version(1, 0, 0, 0));
              Assembly = AssemblyDefinition.CreateAssembly(name, "MirelleCompiled", ModuleKind.Console);

              var attr = typeof(STAThreadAttribute).GetConstructor(new Type[] { } );

              // register global method
              GlobalBody = new MethodDefinition("main", MethodAttributes.Static | MethodAttributes.Private | MethodAttributes.HideBySig, Assembly.MainModule.TypeSystem.Void);
              GlobalBody.CustomAttributes.Add(new CustomAttribute(AssemblyImport(attr)));
              RootNode.GlobalMethod = new MethodNode("main", new SignatureNode("void"), true, false, GlobalBody);
              RootNode.GlobalMethod.Scope = new Utils.Scope(GlobalBody);

              // register global type
              GlobalType = new TypeDefinition("MirelleCompiled", ".program", TypeAttributes.AutoClass | TypeAttributes.Public | TypeAttributes.SpecialName | TypeAttributes.BeforeFieldInit, Assembly.MainModule.TypeSystem.Object);
              Assembly.MainModule.Types.Add(GlobalType);
              GlobalType.Methods.Add(GlobalBody);
              Assembly.EntryPoint = GlobalBody;

              // register marker interfaces
              MirelleTypeInterface = AssemblyImport(typeof(MirelleStdlib.IMirelleType));
              MirelleEnumInterface = AssemblyImport(typeof(MirelleStdlib.IMirelleEnum));
        }
开发者ID:menozz,项目名称:mirelle,代码行数:26,代码来源:Emitter.cs


注:本文中的Compiler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。