Example #1
0
def _lift_method_decl(location, *args):
    if len(args) >= 2 and isinstance(args[1], six.string_types):
        return_type, args = args[0], args[1:]
        if isinstance(return_type, Reference):
            if len(return_type.name) != 1:
                raise ParseError("type: \"%s\" is not a valid type" % return_type.name, location)
            return_type = normalise_type(return_type.name[0]) # dont want references
    else:
        return_type = None # void
    id = args[0]
    return Method(id, return_type, list(args[1:]), location)
Example #2
0
def p_method(t):
    '''method : void ID LPAREN parameter_list RPAREN SEMI
              | type ID LPAREN parameter_list RPAREN SEMI
              | ID ID LPAREN parameter_list RPAREN SEMI'''
    if t[1] == 'void':
        return_type = None
    elif isinstance(t[1], Type):
        return_type = t[1]
    else:
        return_type = Reference(t[1], Type, filename=t.lexer.filename,
            lineno=t.lexer.lineno)
    name = t[2]
    parameters = t[4]
    assert isinstance(parameters, list)
    for i in parameters: assert isinstance(i, Parameter)
    t[0] = Method(name, return_type, parameters, filename=t.lexer.filename, \
        lineno=t.lexer.lineno)