@VisitorCore.visit.dispatch
def visit(self, node: astx.InlineVariableDeclaration) -> None:
"""
title: Visit InlineVariableDeclaration nodes.
parameters:
node:
type: astx.InlineVariableDeclaration
"""
symbol_key = semantic_symbol_key(node, node.name)
if self.named_values.get(symbol_key):
raise Exception(f"Identifier already declared: {node.name}")
type_str = node.type_.__class__.__name__.lower()
if node.value is not None:
self.visit_child(node.value)
init_val = safe_pop(self.result_stack)
if init_val is None:
raise Exception("Initializer code generation failed.")
elif "float" in type_str:
init_val = ir.Constant(self._llvm.get_data_type(type_str), 0.0)
else:
init_val = ir.Constant(self._llvm.get_data_type(type_str), 0)
if type_str == "string":
alloca = self.create_entry_block_alloca(node.name, "stringascii")
else:
alloca = self.create_entry_block_alloca(node.name, type_str)
self._llvm.ir_builder.store(init_val, alloca)
if node.mutability == astx.MutabilityKind.constant:
self.const_vars.add(symbol_key)
self.named_values[symbol_key] = alloca
self.result_stack.append(init_val)