Skip to main content

gobject_ast/model/statement/
for_stmt.rs

1use serde::Serialize;
2
3use crate::{
4    VariableDecl,
5    model::{SourceLocation, expression::Expression, statement::Statement},
6};
7
8/// The initializer clause of a `for` statement.
9#[derive(Debug, Clone, Serialize)]
10pub enum ForInit {
11    /// Expression initializer: `for (i = 0; ...)`
12    Expr(Box<Expression>),
13    /// Declaration initializer: `for (int i = 0; ...)` or `for (GList *l =
14    /// list; ...)`
15    Decl(Box<VariableDecl>),
16}
17
18#[derive(Debug, Clone, Serialize)]
19pub struct ForStatement {
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub initializer: Option<ForInit>,
22    /// Condition expression
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub condition: Option<Box<Expression>>,
25    /// Update expression
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub update: Option<Box<Expression>>,
28    /// Loop body (can be single statement or compound)
29    #[serde(skip_serializing_if = "Vec::is_empty")]
30    pub body: Vec<Statement>,
31    pub location: SourceLocation,
32}