diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-06-30 18:13:45 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-06-30 18:13:45 +0200 |
| commit | 97957d3e3670988e755e77c0cb18a7b0368de6bf (patch) | |
| tree | 227fbd0546521d11ef4674bdae6919b006c8e3a2 /src/common | |
| parent | 28f666c77352734ee720b3b56e34f7261d3a86b2 (diff) | |
Working on generic issues.
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/ast.odin | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin index 29d3e6c..b215eb8 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -207,6 +207,35 @@ unwrap_pointer_expr :: proc(expr: ^ast.Expr) -> (^ast.Expr, int, bool) { return expr, n, true } +expr_contains_poly :: proc(expr: ^ast.Expr) -> bool { + if expr == nil { + return false + } + + visit :: proc(visitor: ^ast.Visitor, node: ^ast.Node) -> ^ast.Visitor { + if node == nil { + return nil + } + if _, ok := node.derived.(^ast.Poly_Type); ok { + b := cast(^bool)visitor.data + b^ = true + return nil + } + return visitor + } + + found := false + + visitor := ast.Visitor { + visit = visit, + data = &found, + } + + ast.walk(&visitor, expr) + + return found +} + is_expr_basic_lit :: proc(expr: ^ast.Expr) -> bool { _, ok := expr.derived.(^ast.Basic_Lit) return ok |