Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,34 @@ PrecompileTools.@compile_workload begin
@variables x(ModelingToolkit.t_nounits)
@named sys = ODESystem([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true)
@mtkmodel __testmod__ begin
@constants begin
c = 1.0
end
@structural_parameters begin
structp = false
end
if structp
@variables begin
x(t) = 0.0, [description = "foo", guess = 1.0]
end
else
@variables begin
x(t) = 0.0, [description = "foo w/o structp", guess = 1.0]
end
end
@parameters begin
a = 1.0, [description = "bar"]
if structp
b = 2 * a, [description = "if"]
else
c
end
end
@equations begin
x ~ a + b
end
end
end

export AbstractTimeDependentSystem,
Expand Down
8 changes: 6 additions & 2 deletions src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ end
# The comments indicate the syntax matched by a block; either when parsed directly
# when it is called recursively for parsing a part of an expression.
# These variable definitions are part of test suite in `test/model_parsing.jl`
function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
Base.@nospecializeinfer function parse_variable_def!(
dict, mod, arg, varclass, kwargs, where_types;
def = nothing, type::Type = Real, meta = Dict{DataType, Expr}())
@nospecialize
arg isa LineNumberNode && return
MLStyle.@match arg begin
# Parses: `a`
Expand Down Expand Up @@ -1355,7 +1357,9 @@ push_something!(v, x...) = push_something!.(Ref(v), x)

define_blocks(branch) = [Expr(branch), Expr(branch), Expr(branch), Expr(branch)]

function parse_top_level_branch(condition, x, y = nothing, branch = :if)
Base.@nospecializeinfer function parse_top_level_branch(
condition, x, y = nothing, branch::Symbol = :if)
@nospecialize
blocks::Vector{Union{Expr, Nothing}} = component_blk, equations_blk, parameter_blk, variable_blk = define_blocks(branch)

for arg in x
Expand Down
Loading