Skip to content

Commit dd7e9ac

Browse files
committed
feat(ast): add missing type definitions for Rust analysis
Add RustGenericParam, RustLifetimeParam, RustParameter, RustCallSite, and RustVariableDeclaration classes to complete the type hierarchy. These model generic types, lifetimes, parameters, call sites and variable declarations for comprehensive Rust code analysis. Signed-off-by: Rithul Kamesh <[email protected]>
1 parent f497473 commit dd7e9ac

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

cldk/models/rust/models.py

+61-10
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ class UnsafeReason(Enum):
3434
CUSTOM = "custom"
3535

3636

37-
class UnsafeBlock(BaseModel):
38-
"""Represents an unsafe block within Rust code."""
39-
40-
start_line: int
41-
end_line: int
42-
reasons: List[UnsafeReason] = Field(default_factory=list)
43-
explanation: Optional[str] = None # Documentation explaining why unsafe is needed
44-
containing_function: Optional[str] = None
45-
46-
4737
class RustType(BaseModel):
4838
"""Represents a Rust type."""
4939

@@ -66,6 +56,67 @@ class RustAttribute(BaseModel):
6656
is_inner: bool = False # #![foo] vs #[foo]
6757

6858

59+
class RustGenericParam(BaseModel):
60+
"""Represents a generic type parameter in Rust."""
61+
62+
name: str
63+
bounds: List[str] = Field(default_factory=list) # Trait bounds
64+
default_type: Optional[str] = None
65+
is_const: bool = False # For const generics
66+
67+
68+
class RustLifetimeParam(BaseModel):
69+
"""Represents a lifetime parameter in Rust."""
70+
71+
name: str
72+
bounds: List[str] = Field(default_factory=list) # Lifetime bounds
73+
74+
75+
class RustParameter(BaseModel):
76+
"""Represents a function parameter in Rust."""
77+
78+
name: str
79+
type: RustType
80+
is_self: bool = False # For methods (self, &self, &mut self)
81+
is_mut: bool = False # For mutable bindings
82+
default_value: Optional[str] = None
83+
84+
85+
class RustCallSite(BaseModel):
86+
"""Represents a location where a function is called."""
87+
88+
line_number: int
89+
caller_function: Optional[str] = None
90+
caller_module: Optional[str] = None
91+
argument_types: List[RustType] = Field(default_factory=list)
92+
is_unsafe_context: bool = False
93+
94+
95+
class RustVariableDeclaration(BaseModel):
96+
"""Represents a variable declaration in Rust."""
97+
98+
name: str
99+
type: Optional[RustType] = None
100+
is_mut: bool = False
101+
is_static: bool = False
102+
is_const: bool = False
103+
initializer: Optional[str] = None
104+
visibility: RustVisibility = RustVisibility.PRIVATE
105+
doc_comment: Optional[str] = None
106+
attributes: List[RustAttribute] = Field(default_factory=list)
107+
line_number: int
108+
109+
110+
class UnsafeBlock(BaseModel):
111+
"""Represents an unsafe block within Rust code."""
112+
113+
start_line: int
114+
end_line: int
115+
reasons: List[UnsafeReason] = Field(default_factory=list)
116+
explanation: Optional[str] = None # Documentation explaining why unsafe is needed
117+
containing_function: Optional[str] = None
118+
119+
69120
class SafetyAnalysis(BaseModel):
70121
"""Analyzes and tracks safety-related information."""
71122

0 commit comments

Comments
 (0)