示例#1
0
def ast_to_blitz_expr(ast_seq):
    """Convert an ast_sequence to a blitz expression."""
    # Don't overwrite orignal sequence in call to transform slices.
    ast_seq = copy.deepcopy(ast_seq)
    slice_handler.transform_slices(ast_seq)

    # Build the actual program statement from ast_seq
    expr = ast_tools.ast_to_string(ast_seq)

    # Now find and replace specific symbols to convert this to
    # a blitz++ compatible statement.
    # I'm doing this with string replacement here.  It could
    # also be done on the actual ast tree (and probably should from
    # a purest standpoint...).

    # this one isn't necessary but it helps code readability
    # and compactness. It requires that
    #   Range _all = blitz::Range::all();
    # be included in the generated code.
    # These could all alternatively be done to the ast in
    # build_slice_atom()
    expr = expr.replace('slice(_beg,_end)', '_all')
    expr = expr.replace('slice', 'blitz::Range')
    expr = expr.replace('[','(')
    expr = expr.replace(']', ')')
    expr = expr.replace('_stp', '1')

    # Instead of blitz::fromStart and blitz::toEnd.  This requires
    # the following in the generated code.
    #   Range _beg = blitz::fromStart;
    #   Range _end = blitz::toEnd;
    #expr = expr.replace('_beg', 'blitz::fromStart' )
    #expr = expr.replace('_end', 'blitz::toEnd' )

    return expr + ';\n'
示例#2
0
 def generic_check(self, suite_string, desired):
     ast_list = parser.suite(suite_string).tolist()
     slice_handler.transform_slices(ast_list)
     actual = ast_to_string(ast_list)
     # Remove white space from expressions so that equivalent
     # but differently formatted string will compare equally
     actual = remove_whitespace(actual)
     desired = remove_whitespace(desired)
     assert_equal(actual, desired, suite_string)
示例#3
0
 def generic_check(self, suite_string, desired):
     ast_list = parser.suite(suite_string).tolist()
     slice_handler.transform_slices(ast_list)
     actual = ast_to_string(ast_list)
     # Remove white space from expressions so that equivalent
     # but differently formatted string will compare equally
     actual = remove_whitespace(actual)
     desired = remove_whitespace(desired)
     assert_equal(actual, desired, suite_string)
示例#4
0
 def generic_test(self,suite_string,desired):
     import parser
     ast_list = parser.suite(suite_string).tolist()
     slice_handler.transform_slices(ast_list)
     actual = ast_to_string(ast_list)
     # Remove white space from expressions so that equivelant
     # but differently formatted string will compare equally
     import string
     actual = replace_whitespace(actual)
     desired = replace_whitespace(desired)
     print_assert_equal(suite_string,actual,desired)