From 31dcae4614071f8f99167918bd72fdb688b33661 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 16 Aug 2024 09:45:29 +0200 Subject: [PATCH] support `primitive type` expr --- Project.toml | 2 +- src/explore.jl | 10 +++++++++- test/ExpressionExplorer.jl | 9 +++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index f0ad769..cb2f7cc 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "ExpressionExplorer" uuid = "21656369-7473-754a-2065-74616d696c43" license = "MIT" authors = ["Paul Berg ", "Fons van der Plas "] -version = "1.0.2" +version = "1.0.3" [compat] julia = "1.6" diff --git a/src/explore.jl b/src/explore.jl index d66c688..5a30f4b 100644 --- a/src/explore.jl +++ b/src/explore.jl @@ -535,6 +535,12 @@ function explore_abstract!(ex::Expr, scopestate::ScopeState) explore_struct!(Expr(:struct, false, ex.args[1], Expr(:block, nothing)), scopestate) end +function explore_primitive!(ex::Expr, scopestate::ScopeState) + type_name, type_body = ex.args + symstate = explore_struct!(Expr(:struct, false, type_name, Expr(:block)), scopestate) + union!(symstate, explore!(type_body, scopestate)) +end + function explore_function_macro!(ex::Expr, scopestate::ScopeState) symstate = SymbolsState() # Creates local scope @@ -784,6 +790,8 @@ function explore!(ex::Expr, scopestate::ScopeState)::SymbolsState return explore!(ex.args[2], scopestate) elseif ex.head === :struct return explore_struct!(ex, scopestate) + elseif ex.head === :primitive + return explore_primitive!(ex, scopestate) elseif ex.head === :abstract return explore_abstract!(ex, scopestate) elseif ex.head === :function || ex.head === :macro @@ -966,7 +974,7 @@ function explore_funcdef!(ex::Expr, scopestate::ScopeState)::Tuple{FunctionName, return name, symstate elseif ex.head === :(<:) - # for use in `struct` and `abstract` + # for use in `struct`, `abstract` and `primitive` name, symstate = uncurly!(ex.args[1], scopestate) if length(ex.args) != 1 union!(symstate, explore!(ex.args[2], scopestate)) diff --git a/test/ExpressionExplorer.jl b/test/ExpressionExplorer.jl index 3df5c8b..92e3478 100644 --- a/test/ExpressionExplorer.jl +++ b/test/ExpressionExplorer.jl @@ -90,6 +90,15 @@ end @test testee(:(let abstract type a end end), [], [:a], [], [ :a => ([], [], [], []) ]) + @test testee(:(primitive type Int24 24 end), [], [:Int24], [], [ + :Int24 => ([], [], [], []) + ]) + @test testee(:(primitive type Int24 <: Integer 24 end), [], [:Int24], [], [ + :Int24 => ([:Integer], [], [], []) + ]) + @test testee(:(primitive type Int24 <: Integer size end), [:size], [:Int24], [], [ + :Int24 => ([:Integer], [], [], []) + ]) @test testee(:(module a; f(x) = x; z = r end), [], [:a], [], []) end