<commit_before>### Objects for representing decompiled code. ###

# Fields should be in order of evaluation.

from programIR.base.metaast import *
from pythonbase import *

class Existing(Reference):
	__metaclass__ = astnode
	__slots__     = 'object'
	__shared__    = True

	def __init__(self, o):
		super(Existing, self).__init__()
		#assert o is not None
		# TODO check that it's a program.AbstractObject?
		self.object = o

	def __repr__(self):
		return "%s(%r)" % (type(self).__name__, self.object)

##	def isConstant(self):
##		return True

	def isPure(self):
		return True

	def constantValue(self):
		return self.object.pyobj

	def __eq__(self, other):
		return type(self) is type(other) and self.object is other.object

	def __hash__(self):
		return hash(self.object)


class Local(Reference):
	__metaclass__ = astnode
	__slots__     = 'name'	
	__shared__    = True

	def __init__(self, name=None):
		super(Local, self).__init__()
		self.name = name

	def __repr__(self):
		if self.name:
			return "Local(%s/%d)" % (self.name, id(self))
		else:
			return "Local(%d)" % id(self)

	def __hash__(self):
		return id(self)

	def isPure(self):
		return True


class Cell(ASTNode):
	__metaclass__ = astnode
	__slots__     = 'name'
	__shared__    = True

	def __init__(self, name):
		super(Cell, self).__init__()
		assert isinstance(name, str)
		self.name = name

	def __eq__(self, other):
		if isinstance(other, type(self)):
			return self.name == other.name
		else:
			return False

	def __hash__(self):
		return hash(self.name)

	def isPure(self):
		return True

	def __repr__(self):
		return "%s(%r)" % (type(self).__name__, self.name)



class GetGlobal(Expression):
	__metaclass__ = astnode
	__fields__    = 'name'
	__types__     = {'name':Existing}

class SetGlobal(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'name', 'value'
	__types__     = {'name':Existing, 'value':Expression}

class DeleteGlobal(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'name'
	__types__     = {'name':Existing}


# Gets the actual cell.
class GetCell(Expression):
	__metaclass__ = astnode
	__fields__    = 'cell'
	__types__     = {'cell':Cell}

	def isPure(self):
		return True


# Gets the contents of a cell.
class GetCellDeref(Expression):
	__metaclass__ = astnode
	__fields__    = 'cell'
	__types__     = {'cell':Cell}

# Sets the contents of a cell.
class SetCellDeref(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'value', 'cell'
	__types__     = {'cell':Cell, 'value':Expression}


class Yield(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class GetIter(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class ConvertToBool(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class Import(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'name', 'fromlist', 'level'
	__types__ 	= {'name':str, 'fromlist':(tuple, list), 'level':int}
	__optional__ 	= 'fromlist'

# TODO make UnaryPrefixOp? It is in a class of its own...
class Not(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class UnaryPrefixOp(Expression):
	__metaclass__ 	= astnode	
	__fields__ 	= 'op', 'expr'
	__types__ 	= {'op':str, 'expr':Expression}
	
class BinaryOp(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'left', 'op', 'right'
	__types__ 	= {'left':Expression, 'op':str, 'right':Expression}

class GetSubscript(Expression):
	__metaclass__ = astnode
	__fields__    = 'expr', 'subscript'
	__types__     = {'expr':Expression, 'subscript':Expression}

class SetSubscript(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'value', 'expr', 'subscript'
	__types__     = {'value':Expression, 'expr':Expression, 'subscript':Expression}
	
class DeleteSubscript(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'expr', 'subscript'
	__types__     = {'expr':Expression, 'subscript':Expression}


class GetSlice(Expression):
	__metaclass__ = astnode
	__fields__    = 'expr', 'start', 'stop', 'step'
	__types__     = {'expr':Expression, 'start':Expression, 'step':Expression, 'step':Expression}
	__optional__  = 'start', 'stop', 'step'

	
class SetSlice(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'value', 'expr', 'start', 'stop', 'step', 
	__types__     = {'value':Expression, 'expr':Expression, 'start':Expression, 'step':Expression, 'step':Expression}
	__optional__  = 'start', 'stop', 'step'
	
class DeleteSlice(SimpleStatement):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr', 'start', 'stop', 'step'
	__types__ 	= {'expr':Expression, 'start':Expression, 'step':Expression, 'step':Expression}
	__optional__ 	= 'start', 'stop', 'step'

		
class Call(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr', 'args', 'kwds', 'vargs', 'kargs'
	__types__ 	= {'expr':Expression, 'args':(list, tuple), 'kwds':(list, tuple)}
	__optional__ 	= 'vargs', 'kargs'


class MethodCall(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr', 'name', 'args', 'kwds', 'vargs', 'kargs'
	__types__ 	= {'expr':Expression, 'name':Expression, 'args':(list, tuple), 'kwds':(list, tuple)}
	__optional__ 	= 'vargs', 'kargs'


class DirectCall(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'func', 'selfarg', 'args', 'kwds', 'vargs', 'kargs'
	__types__ 	= {'args':(list, tuple), 'kwds':(list, tuple)}
	__optional__ 	= 'selfarg', 'vargs', 'kargs'


	def __repr__(self):
		return "%s(<%s>, %r, %r, %r, %r, %r)" % (type(self).__name__, self.func.name,
						       self.selfarg,
						       self.args, self.kwds,
						       self.vargs, self.kargs)

class BuildTuple(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'args'
	__types__ 	= {'args':(tuple, list)}
	
	def isPure(self):
		return True

class BuildList(Expression):
	__metaclass__ = astnode
	__fields__    = 'args'
	__types__     = {'args':(tuple, list)}<commit_msg>Added several missing field types for the DirectCall ast node.<commit_after>### Objects for representing decompiled code. ###

# Fields should be in order of evaluation.

from programIR.base.metaast import *
from pythonbase import *

class Existing(Reference):
	__metaclass__ = astnode
	__slots__     = 'object'
	__shared__    = True

	def __init__(self, o):
		super(Existing, self).__init__()
		#assert o is not None
		# TODO check that it's a program.AbstractObject?
		self.object = o

	def __repr__(self):
		return "%s(%r)" % (type(self).__name__, self.object)

##	def isConstant(self):
##		return True

	def isPure(self):
		return True

	def constantValue(self):
		return self.object.pyobj

	def __eq__(self, other):
		return type(self) is type(other) and self.object is other.object

	def __hash__(self):
		return hash(self.object)


class Local(Reference):
	__metaclass__ = astnode
	__slots__     = 'name'	
	__shared__    = True

	def __init__(self, name=None):
		super(Local, self).__init__()
		self.name = name

	def __repr__(self):
		if self.name:
			return "Local(%s/%d)" % (self.name, id(self))
		else:
			return "Local(%d)" % id(self)

	def __hash__(self):
		return id(self)

	def isPure(self):
		return True


class Cell(ASTNode):
	__metaclass__ = astnode
	__slots__     = 'name'
	__shared__    = True

	def __init__(self, name):
		super(Cell, self).__init__()
		assert isinstance(name, str)
		self.name = name

	def __eq__(self, other):
		if isinstance(other, type(self)):
			return self.name == other.name
		else:
			return False

	def __hash__(self):
		return hash(self.name)

	def isPure(self):
		return True

	def __repr__(self):
		return "%s(%r)" % (type(self).__name__, self.name)



class GetGlobal(Expression):
	__metaclass__ = astnode
	__fields__    = 'name'
	__types__     = {'name':Existing}

class SetGlobal(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'name', 'value'
	__types__     = {'name':Existing, 'value':Expression}

class DeleteGlobal(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'name'
	__types__     = {'name':Existing}


# Gets the actual cell.
class GetCell(Expression):
	__metaclass__ = astnode
	__fields__    = 'cell'
	__types__     = {'cell':Cell}

	def isPure(self):
		return True


# Gets the contents of a cell.
class GetCellDeref(Expression):
	__metaclass__ = astnode
	__fields__    = 'cell'
	__types__     = {'cell':Cell}

# Sets the contents of a cell.
class SetCellDeref(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'value', 'cell'
	__types__     = {'cell':Cell, 'value':Expression}


class Yield(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class GetIter(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class ConvertToBool(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class Import(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'name', 'fromlist', 'level'
	__types__ 	= {'name':str, 'fromlist':(tuple, list), 'level':int}
	__optional__ 	= 'fromlist'

# TODO make UnaryPrefixOp? It is in a class of its own...
class Not(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr'
	__types__ 	= {'expr':Expression}

class UnaryPrefixOp(Expression):
	__metaclass__ 	= astnode	
	__fields__ 	= 'op', 'expr'
	__types__ 	= {'op':str, 'expr':Expression}
	
class BinaryOp(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'left', 'op', 'right'
	__types__ 	= {'left':Expression, 'op':str, 'right':Expression}

class GetSubscript(Expression):
	__metaclass__ = astnode
	__fields__    = 'expr', 'subscript'
	__types__     = {'expr':Expression, 'subscript':Expression}

class SetSubscript(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'value', 'expr', 'subscript'
	__types__     = {'value':Expression, 'expr':Expression, 'subscript':Expression}
	
class DeleteSubscript(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'expr', 'subscript'
	__types__     = {'expr':Expression, 'subscript':Expression}


class GetSlice(Expression):
	__metaclass__ = astnode
	__fields__    = 'expr', 'start', 'stop', 'step'
	__types__     = {'expr':Expression, 'start':Expression, 'step':Expression, 'step':Expression}
	__optional__  = 'start', 'stop', 'step'

	
class SetSlice(SimpleStatement):
	__metaclass__ = astnode
	__fields__    = 'value', 'expr', 'start', 'stop', 'step', 
	__types__     = {'value':Expression, 'expr':Expression, 'start':Expression, 'step':Expression, 'step':Expression}
	__optional__  = 'start', 'stop', 'step'
	
class DeleteSlice(SimpleStatement):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr', 'start', 'stop', 'step'
	__types__ 	= {'expr':Expression, 'start':Expression, 'step':Expression, 'step':Expression}
	__optional__ 	= 'start', 'stop', 'step'

		
class Call(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr', 'args', 'kwds', 'vargs', 'kargs'
	__types__ 	= {'expr':Expression, 'args':(list, tuple), 'kwds':(list, tuple)}
	__optional__ 	= 'vargs', 'kargs'


class MethodCall(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'expr', 'name', 'args', 'kwds', 'vargs', 'kargs'
	__types__ 	= {'expr':Expression, 'name':Expression, 'args':(list, tuple), 'kwds':(list, tuple)}
	__optional__ 	= 'vargs', 'kargs'


class DirectCall(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'func', 'selfarg', 'args', 'kwds', 'vargs', 'kargs'
	__types__ 	= {'selfarg':Expression, 'args':(list, tuple), 'kwds':(list, tuple),
			   'vargs':Expression, 'kargs':Expression}
	__optional__ 	= 'selfarg', 'vargs', 'kargs'


	def __repr__(self):
		return "%s(<%s>, %r, %r, %r, %r, %r)" % (type(self).__name__, self.func.name,
						       self.selfarg,
						       self.args, self.kwds,
						       self.vargs, self.kargs)

class BuildTuple(Expression):
	__metaclass__ 	= astnode
	__fields__ 	= 'args'
	__types__ 	= {'args':(tuple, list)}
	
	def isPure(self):
		return True

class BuildList(Expression):
	__metaclass__ = astnode
	__fields__    = 'args'
	__types__     = {'args':(tuple, list)}
{'fraction_non_alphanumeric': 0.14594594594594595, 'fraction_numerical': 0.0, 'mean_word_length': 4.562442183163737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600527', 'n_tokens_mistral': 4542, 'n_tokens_neox': 4342, 'n_words': 1001}