示例#1
0
        private void ClassTranslator_GenerateField(Identifier id, ExpTranslator xlat, AssignExp ass)
        {
            IEnumerable <Exp> slotNames = null;

            if (ass.Src is PyList srcList)
            {
                slotNames = srcList.elts;
            }
            else if (ass.Src is PyTuple srcTuple)
            {
                slotNames = srcTuple.values;
            }
            if (id.Name == "__slots__")
            {
                if (slotNames == null)
                {
                    // dynamically generated slots are hard.
                    gen.Comment(ass.ToString());
                }
                else
                {
                    foreach (var slotName in slotNames.OfType <Str>())
                    {
                        GenerateField(slotName.s, null);
                    }
                }
            }
            else
            {
                GenerateField(id.Name, ass.Src.Accept(xlat));
            }
        }
示例#2
0
        private void ClassTranslator_GenerateField(Identifier id, ExpTranslator xlat, AssignExp ass)
        {
            IEnumerable <Exp> slotNames = null;

            if (ass.Src is PyList srcList)
            {
                slotNames = srcList.elts;
            }
            else if (ass.Src is PyTuple srcTuple)
            {
                slotNames = srcTuple.values;
            }
            if (id.Name == "__slots__")
            {
                if (slotNames == null)
                {
                    // dynamically generated slots are hard.
                    gen.Comment(ass.ToString());
                }
                else
                {
                    foreach (var slotName in slotNames.OfType <Str>())
                    {
                        //$TODO: test type inference for slots.
                        var slotType = new CodeTypeReference(typeof(object));
                        GenerateField(slotName.s, slotType, null);
                    }
                }
            }
            else
            {
                var(fieldType, nmspcs) = types.TranslateTypeOf(id);
                gen.EnsureImports(nmspcs);

                GenerateField(id.Name, fieldType, ass.Src.Accept(xlat));
            }
        }