Пример #1
0
def test_sig_needles():
    fixture = {
        'function': [{'type': FuncSig(('int**', 'int', 'int'), 'int**'),
                      'span': DEFAULT_EXTENT}],
        'variable': [{'type': 'a',
                      'span': DEFAULT_EXTENT}],
    }
    eq_(list(sig_needles(fixture)),
        [(('c-sig', '(int**, int, int) -> int**'), DEFAULT_EXTENT)])
Пример #2
0
def test_sig_needles():
    dummy_extent = Extent(start=Position(0, 0), end=Position(0, 0))
    fixture = {
        'function': [{'type': FuncSig(('int**', 'int', 'int'), 'int**'),
                      'span': dummy_extent}],
        'variable': [{'type': 'a',
                      'span': dummy_extent}],
    }
    eq_(list(sig_needles(fixture)),
        [(('c-sig', '(int**, int, int) -> int**'), dummy_extent)])
Пример #3
0
def c_type_sig(inputs, output, method=None):
    """Return FuncSig based on C style input, output, and method."""
    inputs = remove(lambda x: x == "void", inputs)  # Void Elimination

    inputs = map(lambda x: x.replace(' ', ''), inputs)  # Space Elimination
    output = output.replace(' ', '')

    if method is not None:  # Implicit first argument
        inputs = [method] + inputs

    if len(inputs) == 0:  # Expand no inputs to a single void input
        inputs = ["void"]

    return FuncSig(tuple(inputs), output)
Пример #4
0
def test_type_classes():
    eq_(c_type_sig(['bool'], 'Q<T>'), FuncSig(('bool', ), 'Q<T>'))
Пример #5
0
def test_void_alias():
    eq_(c_type_sig([], 'a'), FuncSig(('void', ), 'a'))
Пример #6
0
def test_void_elimination():
    eq_(c_type_sig(["void"], "b", method="A"), FuncSig(("A", ), "b"))
Пример #7
0
def test_method():
    eq_(c_type_sig(["a"], "b", method="A"), FuncSig(("A", "a"), "b"))
Пример #8
0
def test_boxing():
    eq_(c_type_sig(["int **"], "int*"), FuncSig(("int**", ), ("int*")))
Пример #9
0

class ValueVisitor(NodeVisitor):
    def visit_val(self, node, (val,)):
        return val if val else node.text

    def visit_list(self, _, (_1, type_, _2)):
        return "[" + type_ + "]"

    def visittype_(self, node, (child,)):
        return child if child else node.text

    def visit_func(self, _, (_1, _2, args, _3, type_)):
        if type_ == []:
            type_ = [None]
        return FuncSig(args, type_[0])

    def visit_arg(self, _, (name, type_, _2)):
        return (name, type_[0] if type_ else None)

    def visit_argtype_(self, node, (_, val)):
        return val

    def visit_output(self, _, (_1, val)):
        return val

    def visit_name(self, node, _):
        return node.text

    def visit_qname(self, node, _):
        return node.text