Read about our upcoming Code of Conduct on this issue

Commit 9a2fa2e7 authored by Ronan Lamy's avatar Ronan Lamy
Browse files

kill _make_none_union()

parent f02e2ea76f2e
......@@ -2,12 +2,11 @@
Binary operations between SomeValues.
import py
import operator
from rpython.tool.pairtype import pair, pairtype
from rpython.annotator.model import (
SomeObject, SomeInteger, SomeBool, s_Bool, SomeString, SomeChar, SomeList,
SomeDict, SomeOrderedDict, SomeUnicodeCodePoint, SomeUnicodeString,
SomeDict, SomeUnicodeCodePoint, SomeUnicodeString,
SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance,
SomeBuiltinMethod, SomeIterator, SomePBC, SomeNone, SomeFloat, s_None,
SomeByteArray, SomeWeakRef, SomeSingleFloat,
......@@ -784,29 +783,6 @@ class __extend__(pairtype(SomeNone, SomeImpossibleValue)):
def union((none, imp2)):
return s_None
def _make_none_union(classname, constructor_args='', glob=None):
if glob is None:
glob = globals()
loc = locals()
source = py.code.Source("""
class __extend__(pairtype(%(classname)s, SomeNone)):
def union((obj, none)):
return %(classname)s(%(constructor_args)s)
class __extend__(pairtype(SomeNone, %(classname)s)):
def union((none, obj)):
return %(classname)s(%(constructor_args)s)
""" % loc)
exec source.compile() in glob
_make_none_union('SomeInstance', 'classdef=obj.classdef, can_be_None=True')
_make_none_union('SomeString', 'no_nul=obj.no_nul, can_be_None=True')
_make_none_union('SomeUnicodeString', 'can_be_None=True')
_make_none_union('SomeList', 'obj.listdef')
_make_none_union('SomeOrderedDict', 'obj.dictdef')
_make_none_union('SomeDict', 'obj.dictdef')
_make_none_union('SomeWeakRef', 'obj.classdef')
class __extend__(pairtype(SomePBC, SomeObject)):
def getitem((pbc, o)):
......@@ -261,11 +261,17 @@ class SomeString(SomeStringOrUnicode):
"Stands for an object which is known to be a string."
knowntype = str
def noneify(self):
return SomeString(can_be_None=True, no_nul=self.no_nul)
class SomeUnicodeString(SomeStringOrUnicode):
"Stands for an object which is known to be an unicode string"
knowntype = unicode
def noneify(self):
return SomeUnicodeString(can_be_None=True, no_nul=self.no_nul)
class SomeByteArray(SomeStringOrUnicode):
immutable = False
......@@ -316,6 +322,9 @@ class SomeList(SomeObject):
def can_be_none(self):
return True
def noneify(self):
return SomeList(self.listdef)
class SomeTuple(SomeObject):
"Stands for a tuple of known length."
......@@ -361,6 +370,9 @@ class SomeDict(SomeObject):
return '{...%s...}' % (len(const),)
def noneify(self):
return type(self)(self.dictdef)
class SomeOrderedDict(SomeDict):
from collections import OrderedDict as knowntype
......@@ -420,6 +432,9 @@ class SomeInstance(SomeObject):
def nonnoneify(self):
return SomeInstance(self.classdef, can_be_None=False)
def noneify(self):
return SomeInstance(self.classdef, can_be_None=True)
class SomePBC(SomeObject):
"""Stands for a global user instance, built prior to the analysis,
......@@ -592,6 +607,9 @@ class SomeWeakRef(SomeObject):
# 'classdef' is None for known-to-be-dead weakrefs.
self.classdef = classdef
def noneify(self):
return SomeWeakRef(self.classdef)
# ____________________________________________________________
......@@ -446,6 +446,9 @@ class SomeStringBuilder(SomeObject):
def rtyper_makekey(self):
return self.__class__,
def noneify(self):
return self
class SomeUnicodeBuilder(SomeObject):
def method_append(self, s_str):
......@@ -483,6 +486,9 @@ class SomeUnicodeBuilder(SomeObject):
def rtyper_makekey(self):
return self.__class__,
def noneify(self):
return self
class BaseEntry(object):
def compute_result_annotation(self, s_init_size=None):
......@@ -506,29 +512,6 @@ class UnicodeBuilderEntry(BaseEntry, ExtRegistryEntry):
use_unicode = True
class __extend__(pairtype(SomeStringBuilder, SomePBC)):
def union((sb, p)):
assert p.const is None
return SomeStringBuilder()
class __extend__(pairtype(SomePBC, SomeStringBuilder)):
def union((p, sb)):
assert p.const is None
return SomeStringBuilder()
class __extend__(pairtype(SomeUnicodeBuilder, SomePBC)):
def union((sb, p)):
assert p.const is None
return SomeUnicodeBuilder()
class __extend__(pairtype(SomePBC, SomeUnicodeBuilder)):
def union((p, sb)):
assert p.const is None
return SomeUnicodeBuilder()
# Support functions for SomeString.no_nul
from rpython.annotator import model as annmodel
from rpython.tool.pairtype import pairtype
from rpython.annotator.binaryop import _make_none_union, SomeNone # SomeNone needed by _make_none_union
from rpython.annotator.bookkeeper import getbookkeeper
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.annlowlevel import cachedtype
......@@ -216,6 +215,9 @@ class SomeControlledInstance(annmodel.SomeObject):
def can_be_none(self):
return self.controller.can_be_None
def noneify(self):
return SomeControlledInstance(self.s_real_obj, self.controller)
def rtyper_makerepr(self, rtyper):
from rpython.rtyper.rcontrollerentry import ControlledInstanceRepr
return ControlledInstanceRepr(rtyper, self.s_real_obj, self.controller)
......@@ -224,7 +226,6 @@ class SomeControlledInstance(annmodel.SomeObject):
real_key = self.s_real_obj.rtyper_makekey()
return self.__class__, real_key, self.controller
_make_none_union("SomeControlledInstance", "obj.s_real_obj, obj.controller", globals())
class __extend__(SomeControlledInstance):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment