1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 19:32:19 +01:00

Declare Color objects in main.cpp (#1395)

This commit is contained in:
Keith Burzinski
2021-03-19 05:40:05 -05:00
committed by GitHub
parent dedf343bd5
commit 818a7f1c78
3 changed files with 25 additions and 1 deletions

View File

@@ -448,6 +448,29 @@ def variable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj":
return obj
def new_variable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj":
"""Declare and define 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_
decl = VariableDeclarationExpression(id_.type, "", id_)
CORE.add_global(decl)
assignment = AssignmentExpression(None, "", id_, rhs, obj)
CORE.add(assignment)
CORE.register_variable(id_, obj)
return obj
def Pvariable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj":
"""Declare a new pointer variable in the code generation.