def __init__( self, import_list=None, decl_list=None, ): self.import_list = misc.tolist(import_list) self.decl_list = misc.tolist(decl_list) self.ident_list = None
def __init__( self, import_list=None, decl_list=None, ): self.import_list = misc.tolist(import_list) self.decl_list = misc.tolist(decl_list) self.ident_list = None
def __init__( self, param_list=None, generic_param_list=None, return_type=None, ): self.param_list = misc.tolist(param_list) self.generic_param_list = misc.tolist(generic_param_list) self.return_type = return_type
def __init__( self, param_list=None, generic_param_list=None, return_type=None, ): self.param_list = misc.tolist(param_list) self.generic_param_list = misc.tolist(generic_param_list) self.return_type = return_type
def __init__(self, name, signature, body=None): self.name = name self.signature = signature self.body = misc.tolist(body) # TODO: move to ast.Block ... self.vars = {} self.tmp_vars = {} self.constants = {}
def __init__(self, name, signature, body=None): self.name = name self.signature = signature self.body = misc.tolist(body) # TODO: move to ast.Block ... self.vars = {} self.tmp_vars = {} self.constants = {}
def find_func_signature(ident_list, func_decl, func_call_expr): expr = func_call_expr # shortcut assert isinstance(expr.called_expr, ast.Ident) func_name = expr.called_expr.name signature_list = ident_list[func_name] if not signature_list: raise Exception('Can not find any signatures') signature_list = misc.tolist(signature_list) for signature in signature_list: par_count = len(signature.param_list) arg_count = len(expr.arg_list) if par_count == 0 and arg_count == 0: return signature if par_count != arg_count: continue for arg, param in zip(expr.arg_list, signature.param_list): arg_type = get_expr_datatype(ident_list, func_decl, arg) if arg_type.name == param.datatype.name: return signature raise Exception('Can not find matching signature')
def test_obj_to_list(self): self.assertEqual( misc.tolist(1), [1], )
def __init__(self, expr, arg_list=None): self.called_expr = expr self.arg_list = misc.tolist(arg_list) self.binded_var_name = None
def __init__(self, name, prefix_list=None): self.name = name self.prefix_list = misc.tolist(prefix_list)
def test_1(self): self.assertEqual( misc.tolist(None), [], )
def __init__(self, expr, arg_list=None): self.called_expr = expr self.arg_list = misc.tolist(arg_list) self.binded_var_name = None
def __init__(self, name, field_list=None, decl_list=None): self.name = name self.field_list = misc.tolist(field_list) self.decl_list = misc.tolist(decl_list)
def test_2(self): self.assertEqual( misc.tolist([]), [], )
def ident_table(ast_): ''' Build simple ident table. ''' def standart_funcs(): datatype_int = datatype.SimpleDataType('Int') datatype_string = datatype.SimpleDataType('String') std_signature = ast.FuncSignature( return_type=datatype.SimpleDataType('Int'), param_list=[ ast.Param(name='a', datatype=datatype_int), ast.Param(name='b', datatype=datatype_int), ], ) ident_list = { # Int constructor 'Int': ast.FuncSignature( return_type=datatype_int, param_list=[ ast.Param(name='n', datatype=datatype_int), ], ), 'printNewLine': ast.FuncSignature(), 'print': [ ast.FuncSignature( param_list=[ ast.Param(name='s', datatype=datatype_string), ], ), ast.FuncSignature( param_list=[ ast.Param(name='n', datatype=datatype_int), ], ), ], 'allocInt': ast.FuncSignature( return_type=datatype.SimpleDataType( name='Int', prefix_list=['R'], ), ), 'isEqual': std_signature, 'isLess': std_signature, 'isGreater': std_signature, 'minus': std_signature, 'plus': std_signature, 'multiply': std_signature, } return ident_list def create_constructor_func(class_decl): return ast.FuncSignature( return_type=datatype.SimpleDataType(class_decl.name), ) ident_list = {} for decl in ast_.decl_list: if isinstance(decl, ast.FuncDecl): if decl.name in ident_list: ident_list[decl.name] = misc.tolist(ident_list[decl.name]) ident_list[decl.name].append(decl.signature) else: ident_list[decl.name] = [ decl.signature, ] elif isinstance(decl, ast.ClassDecl): ident_list[decl.name] = create_constructor_func(decl) ident_list.update(standart_funcs()) return ident_list
def __init__(self, name, field_list=None, decl_list=None): self.name = name self.field_list = misc.tolist(field_list) self.decl_list = misc.tolist(decl_list)
def test_3(self): self.assertEqual( misc.tolist([1, 2]), [1, 2], )