Пример #1
0
 private void FixVoidReturns(TLSchema schema)
 {
     foreach (var method in schema.Methods.Where(method => !schema.Types.Contains(method.Type)))
     {
         method.Type = _tlTypesCache["void"];
     }
 }
Пример #2
0
 private void SetBuiltInTypeNames(TLSchema schema)
 {
     foreach (TLCombinatorParameter parameter in schema.Constructors.SelectMany(constructor => constructor.Parameters))
     {
         FixType(parameter.Type, schema);
     }
 }
Пример #3
0
        public static string CompileFromJson(string json, string defaultNamespace)
        {
            var      compiler = new TLSchemaCompiler(defaultNamespace);
            TLSchema schema   = compiler.GetTLSchemaFromJson(json);

            return(compiler.Compile(schema));
        }
Пример #4
0
        public static string CompileFromTL(string tl, string defaultNamespace)
        {
            var      compiler = new TLSchemaCompiler(defaultNamespace);
            TLSchema schema   = compiler.GetTLSchemaFromTL(tl);

            return(compiler.Compile(schema));
        }
Пример #5
0
        protected string Compile(TLSchema schema)
        {
            SetBuiltInTypeNames(schema);
            FixVoidReturns(schema);

            var template = new SharpTLDefaultTemplate(new TemplateVars {
                Schema = schema, Namespace = _defaultNamespace
            });

            return(template.TransformText());
        }
Пример #6
0
        public TLSchema GetTLSchemaFromJson(string json)
        {
            JsonObject tlSchemaJsonObject = JsonObject.Parse(json);

            List <TLCombinator> constructors = CreateConstructorsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("constructors"));
            List <TLCombinator> methods      = CreateMethodsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("methods"));
            List <TLType>       types        = UpdateAndGetTLTypes(constructors);

            var schema = new TLSchema {
                Constructors = constructors, Methods = methods, Types = types
            };

            return(schema);
        }
Пример #7
0
        public static string CompileFromJson(string json, CompilationParams compilationParams)
        {
            TLSchema schema = FromJson(json);

            return(schema.Compile(compilationParams));
        }
Пример #8
0
        private void FixType(TLType type, TLSchema schema)
        {
            List <TLCombinator> constructors = schema.Constructors;
            string typeName = type.OriginalName;

            // Vector.
            Match match = VectorRegex.Match(typeName);

            if (match.Success)
            {
                TLType itemsType = GetTLType(match.Groups["ItemsType"].Value);
                FixType(itemsType, schema);
                type.Name = string.Format("System.Collections.Generic.List<{0}>", itemsType.Name);
                if (match.Groups["Bare"].Success)
                {
                    type.SerializationModeOverride = TLSerializationMode.Bare;
                }
                return;
            }

            // int.
            match = Int32Regex.Match(typeName);
            if (match.Success)
            {
                type.Name = typeof(UInt32).FullName;
                return;
            }

            // long.
            match = Int64Regex.Match(typeName);
            if (match.Success)
            {
                type.Name = typeof(UInt64).FullName;
                return;
            }

            // int128.
            match = Int128Regex.Match(typeName);
            if (match.Success)
            {
                type.Name = typeof(Int128).FullName;
                return;
            }

            // int256.
            match = Int256Regex.Match(typeName);
            if (match.Success)
            {
                type.Name = typeof(Int256).FullName;
                return;
            }

            // bytes.
            match = TLBytesRegex.Match(typeName);
            if (match.Success)
            {
                type.Name = typeof(byte[]).FullName;
                return;
            }

            // % bare types.
            match = BareTypeRegex.Match(typeName);
            if (match.Success)
            {
                typeName  = match.Groups["Type"].Value;
                type.Name = constructors.Where(combinator => combinator.Type.Name == typeName).Select(combinator => combinator.Name).SingleOrDefault() ?? typeName;
                type.SerializationModeOverride = TLSerializationMode.Bare;
            }
        }
Пример #9
0
        public static string CompileFromTL(string tlSchemaText, CompilationParams compilationParams)
        {
            TLSchema schema = FromTL(tlSchemaText);

            return(schema.Compile(compilationParams));
        }