示例#1
0
        public CompileResponse Compile(CompileRequest args)
        {
            var skc = new CompilerTool {
                Args = args.Args, CommandLineArguments = new string[] { args.CommandLineArgs }
            };
            var x  = skc.Run();
            var xx = new CompileResponse {
                Output = skc.Log.Console.Items.ToList(), ExitCode = x
            };

            return(xx);
        }
示例#2
0
        public static ITypeDefinition GetDefinitionOrArrayType(this IType ce, CompilerTool compiler)
        {
            var def = ce.GetDefinition();

            if (def == null)
            {
                if (ce.Kind == TypeKind.Array)
                {
                    return(Cs.ArrayType(compiler.Project));
                }
            }
            return(def);
        }
示例#3
0
        static int Main(string[] args)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            CollectionExtensions.Parallel          = ConfigurationManager.AppSettings["Parallel"] == "true";
            CollectionExtensions.ParallelPreAction = () => Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            //Console.AutoFlush = true;
            Console.WriteLine("Parallel=" + CollectionExtensions.Parallel);
            var skc = new CompilerTool {
                CommandLineArguments = args
            };

#if DEBUG
            skc.Debug = true;
#endif
            var res = skc.Run();
            stopwatch.Stop();
            //Console.FormatLine("Total: {0}ms", stopwatch.ElapsedMilliseconds);
            //Console.Flush();
            return(res);
        }
示例#4
0
        public static ResolveResult GetValueTypeInitializer(IType ce, CompilerTool compiler)
        {
            var Project = compiler.Project;

            if (ce.FullName == "System.Nullable")
            {
                return(Cs.Null());
            }
            if (ce is ITypeDefinition)
            {
                var def = (ITypeDefinition)ce;
                if (def.KnownTypeCode != KnownTypeCode.None)
                {
                    if (def.KnownTypeCode == KnownTypeCode.Boolean)
                    {
                        return(Cs.Value(false, Project));
                    }
                    else if (def.KnownTypeCode == KnownTypeCode.Char)
                    {
                        return(Cs.Value('\0', Project));
                    }
                    else if (def.KnownTypeCode == KnownTypeCode.SByte ||
                             def.KnownTypeCode == KnownTypeCode.Int16 ||
                             def.KnownTypeCode == KnownTypeCode.Int32 ||
                             def.KnownTypeCode == KnownTypeCode.Int64 ||
                             def.KnownTypeCode == KnownTypeCode.UInt16 ||
                             def.KnownTypeCode == KnownTypeCode.UInt32 ||
                             def.KnownTypeCode == KnownTypeCode.UInt64 ||
                             def.KnownTypeCode == KnownTypeCode.Byte ||
                             def.KnownTypeCode == KnownTypeCode.Decimal ||
                             def.KnownTypeCode == KnownTypeCode.Double ||
                             def.KnownTypeCode == KnownTypeCode.Single
                             )
                    {
                        return(Cs.Value(0, Project));
                    }
                }
            }
            if (ce.Kind == TypeKind.Enum)
            {
                var en                = ce;
                var enumMembers       = en.GetFields();
                var defaultEnumMember = enumMembers.Where(t => (t.ConstantValue is int) && (int)t.ConstantValue == 0).FirstOrDefault() ?? enumMembers.FirstOrDefault();
                if (defaultEnumMember != null)
                {
                    return(defaultEnumMember.AccessSelf());//.Access().Member(c.CreateTypeRef(en), defaultEnumMember);
                }
                else
                {
                    return(null);
                }
            }
            else if (ce.GetEntityType().FullName == "System.DateTime")
            {
                var minDateFe = ce.GetFields(t => t.Name == "MinValue").First();
                return(minDateFe.AccessSelf());// c.Member(c.Class(c.DateTimeType), minDateFe);
            }
            else
            {
                return(Cs.New(ce));
            }
        }