Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing macro substitution for label statements #793

Merged
merged 1 commit into from
May 10, 2024
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
13 changes: 13 additions & 0 deletions src/main/scala/viper/silver/parser/MacroExpander.scala
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,19 @@ object MacroExpander {
freeVars += varUse.name
(varUse, ctx)
}
case (label@PLabel(lbl, lName, invs), ctx) if !ctx.c.boundVars.contains(lName.name) =>
if (ctx.c.paramToArgMap.contains(lName.name)) {
val replacement = ctx.c.paramToArgMap(lName.name).deepCopyAll
val replaced = replacement match {
case r: PIdnUseExp => PIdnDef(r.name)(r.pos)
case r =>
throw MacroException(s"macro expansion cannot substitute expression `${replacement.pretty}` at ${replacement.pos._1} in non-expression position at ${lName.pos._1}.", replacement.pos)
}
(PLabel(lbl, replaced, invs)(label.pos), ctx.updateContext(ctx.c.copy(paramToArgMap = ctx.c.paramToArgMap.empty)))
} else {
freeVars += lName.name
(label, ctx)
}
}, ReplaceContext())
(replacer, freeVars)
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/resources/all/issues/silver/0787a.vpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/


method main()
{
m(some_name)
}

define m(label_name)
{
goto label_name
label label_name
}
14 changes: 14 additions & 0 deletions src/test/resources/all/issues/silver/0787b.vpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/


method main()
{
//:: ExpectedOutput(parser.error)
m(3)
}

define m(label_name)
{
label label_name
}
Loading