示例#1
0
        private TLType GetTLType(string typeName)
        {
            TLType type;

            if (!_tlTypesCache.TryGetValue(typeName, out type))
            {
                type = new TLType(typeName);
                _tlTypesCache.Add(typeName, type);
            }
            return(type);
        }
示例#2
0
        private List <TLType> UpdateAndGetTLTypes(IEnumerable <TLCombinator> constructors)
        {
            var types = new List <TLType>();

            foreach (TLCombinator constructor in constructors)
            {
                TLType type = constructor.Type;
                if (!type.Constructors.Contains(constructor))
                {
                    type.Constructors.Add(constructor);
                }
                if (!types.Contains(type))
                {
                    types.Add(type);
                }
            }
            return(types);
        }
示例#3
0
        private void FixType(TLType type)
        {
            // TODO: refactor this huge method.

            string typeName = type.OriginalName;

            //Additions for compatibity with layer 51 schema

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

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

            // bool.
            match = BoolRegex.Match(typeName);
            if (match.Success)
            {
                type.Name      = typeof(bool).FullName;
                type.IsBuiltIn = true;
                return;
            }

            // string.
            match = StringRegex.Match(typeName);
            if (match.Success)
            {
                type.Name      = typeof(string).FullName;
                type.IsBuiltIn = true;
                return;
            }

            // string.
            match = DoubleRegex.Match(typeName);
            if (match.Success)
            {
                type.Name      = typeof(double).FullName;
                type.IsBuiltIn = true;
                return;
            }

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

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

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

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

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

            // % bare types.
            match = BareTypeRegex.Match(typeName);
            if (match.Success)
            {
                typeName  = match.Groups["Type"].Value;
                type.Name = _constructors.Where(c => c.Type.Name == typeName).Select(c => c.Name).SingleOrDefault() ?? typeName;
                type.SerializationModeOverride = TLSerializationMode.Bare;
                // TODO: fix type.
                return;
            }

            // Object.
            match = TLObjectRegex.Match(typeName);
            if (match.Success)
            {
                type.Name      = typeof(Object).FullName;
                type.IsBuiltIn = true;
            }
        }
示例#4
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;
            }
        }
示例#5
0
        public void UpdateTypes()
        {
            // Update types constructors.
            foreach (TLCombinator constructor in _constructors)
            {
                constructor.Type.Constructors.Clear();
            }
            foreach (TLCombinator constructor in _constructors)
            {
                TLType type = constructor.Type;
                if (!type.Constructors.Contains(constructor))
                {
                    type.Constructors.Add(constructor);
                }
            }

            // Update TLTypesBox.
            _typesBox.Clear();
            foreach (TLCombinator combinator in _constructors.Union(_methods))
            {
                _typesBox.Add(combinator.Type);
                foreach (TLCombinatorParameter parameter in combinator.Parameters)
                {
                    _typesBox.Add(parameter.Type);
                }
            }

            var allTypes = _typesBox.GetAll();

            // Fix types.
            foreach (TLType tlType in _typesBox.GetAll())
            {
                FixType(tlType);
            }

//			foreach (TLCombinator method in _methods)
//			{
//				foreach (TLCombinatorParameter param in method.Parameters) {
//					FixType(param.Type);
//				}
//			}
//
//			foreach (TLCombinator constructor in _constructors)
//			{
//				foreach (TLCombinatorParameter param in constructor.Parameters) {
//					FixType(param.Type);
//				}
//			}


            // Fix void returns.
            foreach (TLCombinator method in _methods.Where(method => !method.Type.HasConstructors && !method.Type.IsBuiltIn))
            {
                method.Type = _typesBox["void"];
            }


            // When property name equals class name, they must not be equal.
            foreach (TLCombinator constructor in _constructors)
            {
                foreach (TLCombinatorParameter parameter in constructor.Parameters)
                {
                    if (parameter.Name == constructor.Name)
                    {
                        // TODO: give more pretty name.
                        parameter.Name += "Property";
                    }
                }
            }
        }