예제 #1
0
def get_field_ast(field):
    triple = field.get_class_name()[1:-1], field.get_name(
    ), field.get_descriptor()

    expr = None
    if field.init_value:
        val = field.init_value.value
        expr = dummy(str(val))

        if val is not None:
            if field.get_descriptor() == 'Ljava/lang/String;':
                expr = literal_string(val)
            elif field.proto == 'B':
                expr = literal_hex_int(struct.unpack('<b', struct.pack("B", val))[0])

    return {
        'triple': triple,
        'type': parse_descriptor(field.get_descriptor()),
        'flags': util.get_access_field(field.get_access_flags()),
        'expr': expr,
    }
예제 #2
0
def get_field_ast(field):
    triple = field.get_class_name()[1:-1], field.get_name(
    ), field.get_descriptor()

    expr = None
    if field.init_value:
        val = field.init_value.value
        expr = dummy(str(val))

        if val is not None:
            if field.get_descriptor() == 'Ljava/lang/String;':
                expr = literal_string(val)
            elif field.proto == 'B':
                expr = literal_hex_int(struct.unpack('<b', struct.pack("B", val))[0])

    return {
        'triple': triple,
        'type': parse_descriptor(field.get_descriptor()),
        'flags': util.get_access_field(field.get_access_flags()),
        'expr': expr,
    }
예제 #3
0
def get_field_ast(field, annotations):
    triple = field.get_class_name()[1:-1], field.get_name(
    ), field.get_descriptor()

    expr = None
    if field.init_value:
        val = field.init_value.value
        expr = None

        if val is not None:
            descriptor = str(field.get_descriptor())
            if descriptor == 'Ljava/lang/String;':
                expr = literal_string(val)
            elif descriptor == 'Z':
                expr = literal_bool(val == 'True')
            elif descriptor in 'ISC':
                expr = literal_int(val)
            elif field.proto == 'B':
                expr = literal_hex_int(
                    struct.unpack('<b', struct.pack("B", val))[0])
            elif descriptor in 'J':
                expr = literal_long(val)
            elif descriptor in 'F':
                expr = literal_float(val)
            elif descriptor in 'D':
                expr = literal_double(val)
            elif descriptor == 'Ljava/lang/Class;':
                expr = literal_class(val)
            else:
                expr = dummy(str(val))

    return {
        'triple': triple,
        'type': parse_descriptor(field.get_descriptor()),
        'flags': util.get_access_field(field.get_access_flags()),
        'annotations': annotations,
        'expr': expr,
    }