Skip to content

Commit

Permalink
Fixing macro substitution for label statements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed May 10, 2024
1 parent c7a4e60 commit e68a37c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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
}

0 comments on commit e68a37c

Please sign in to comment.