Merge branch 'storage_class_optimize' into integration

This commit is contained in:
J. Nick Koston
2025-12-21 19:30:10 -10:00
2 changed files with 8 additions and 2 deletions

View File

@@ -256,9 +256,11 @@ async def to_code(configs):
True,
type=lv_font_t.operator("ptr").operator("const"),
)
# static=False because LV_FONT_CUSTOM_DECLARE creates an extern declaration
cg.new_variable(
globfont_id,
MockObj(await lvalid.lv_font.process(default_font), "->").get_lv_font(),
static=False,
)
add_define("LV_FONT_DEFAULT", df.DEFAULT_ESPHOME_FONT)
else:

View File

@@ -511,13 +511,17 @@ def with_local_variable(id_: ID, rhs: SafeExpType, callback: Callable, *args) ->
CORE.add(RawStatement("}")) # output closing curly brace
def new_variable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj":
def new_variable(
id_: ID, rhs: SafeExpType, type_: "MockObj" = None, *, static: bool = True
) -> "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).
:param static: If True (default), declare with static storage class for optimization.
Set to False when the variable must have external linkage (e.g., to match library declarations).
:return: The new variable as a MockObj.
"""
@@ -526,7 +530,7 @@ def new_variable(id_: ID, rhs: SafeExpType, type_: "MockObj" = None) -> "MockObj
obj = MockObj(id_, ".")
if type_ is not None:
id_.type = type_
decl = VariableDeclarationExpression(id_.type, "", id_, static=True)
decl = VariableDeclarationExpression(id_.type, "", id_, static=static)
CORE.add_global(decl)
assignment = AssignmentExpression(None, "", id_, rhs)
CORE.add(assignment)