Esempio n. 1
0
def static_const_array(id_, rhs) -> "MockObj":
    rhs = safe_exp(rhs)
    obj = MockObj(id_, ".")
    assignment = StaticConstAssignmentExpression(id_.type, id_, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id_, obj)
    return obj
Esempio n. 2
0
def progmem_array(id_, rhs) -> "MockObj":
    rhs = safe_exp(rhs)
    obj = MockObj(id_, ".")
    assignment = ProgmemAssignmentExpression(id_.type, id_, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id_, obj)
    return obj
def Pvariable(
        id,  # type: ID
        rhs,  # type: SafeExpType
        type=None  # type: MockObj
):
    # type: (...) -> MockObj
    """Declare a new pointer variable in the code generation.

    :param id: The ID used to declare the variable.
    :param rhs: The expression to place on the right hand side of the assignment.
    :param type: Manually define a type for the variable, only use this when it's not possible
      to do so during config validation phase (for example because of template arguments).

    :returns The new variable as a MockObj.
    """
    rhs = safe_exp(rhs)
    obj = MockObj(id, '->')
    if type is not None:
        id.type = type
    decl = VariableDeclarationExpression(id.type, '*', id)
    CORE.add_global(decl)
    assignment = AssignmentExpression(None, None, id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    return obj
def progmem_array(id, rhs):
    rhs = safe_exp(rhs)
    obj = MockObj(id, '.')
    assignment = ProgmemAssignmentExpression(id.type, id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    return obj
Esempio n. 5
0
def variable(id,  # type: ID
             rhs,  # type: Expression
             type=None  # type: MockObj
             ):
    # type: (...) -> MockObj
    rhs = safe_exp(rhs)
    obj = MockObj(id, u'.')
    id.type = type or id.type
    assignment = AssignmentExpression(id.type, '', id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    obj.requires.append(assignment)
    return obj
Esempio n. 6
0
def Pvariable(id,  # type: ID
              rhs,  # type: Expression
              has_side_effects=True,  # type: bool
              type=None  # type: MockObj
              ):
    # type: (...) -> MockObj
    rhs = safe_exp(rhs)
    if not has_side_effects and hasattr(rhs, '_has_side_effects'):
        # pylint: disable=attribute-defined-outside-init, protected-access
        rhs._has_side_effects = False
    obj = MockObj(id, u'->', has_side_effects=has_side_effects)
    id.type = type or id.type
    assignment = AssignmentExpression(id.type, '*', id, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id, obj)
    obj.requires.append(assignment)
    return obj
Esempio n. 7
0
def variable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj":
    """Declare a new variable, not pointer type, in the code generation.

    :param id_: The ID used to declare the variable.
    :param rhs: The expression to place on the right hand side of the assignment.
    :param type_: Manually define a type for the variable, only use this when it's not possible
      to do so during config validation phase (for example because of template arguments).

    :returns The new variable as a MockObj.
    """
    assert isinstance(id_, ID)
    rhs = safe_exp(rhs)
    obj = MockObj(id_, ".")
    if type_ is not None:
        id_.type = type_
    assignment = AssignmentExpression(id_.type, "", id_, rhs, obj)
    CORE.add(assignment)
    CORE.register_variable(id_, obj)
    return obj