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

Support hovering over macro usages (lsp) #826

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/main/scala/viper/silver/ast/pretty/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ object FastPrettyPrinter extends FastPrettyPrinterBase with BracketPrettyPrinter
} else {
n.info.getUniqueInfo[AnnotationInfo] match {
case Some(ai) if ai.values.nonEmpty =>
val docs = ai.values.map(v => char('@') <> v._1 <> parens(ssep(v._2.map(v => text(s"\"${v}\"")), text(", ")))).toSeq
val docs = ai.values.filter(v => v._1 != "expandedMacro").map(v => char('@') <> v._1 <> parens(ssep(v._2.map(v => text(s"\"${v}\"")), text(", ")))).toSeq
Some(ssep(docs, if (breakLines) line else space))
case _ => None
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/viper/silver/parser/MacroExpander.scala
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,11 @@ object MacroExpander {
var bodyWithReplacedParams = replacer.execute[PNode](bodyWithRenamedVars, context)
bodyWithReplacedParams = adaptPositions(bodyWithReplacedParams, pos)

// Return expanded macro's body
bodyWithReplacedParams
// Return expanded macro's body wrapped inside annotation
bodyWithReplacedParams match {
case b: PExp => PAnnotatedExp(PAnnotation(new PSym.At(PSym.At)(pos),PRawString("expandedMacro")(pos),PGrouped.impliedParen(PDelimited.empty))(pos),b)(pos)
case b: PStmt => PAnnotatedStmt(PAnnotation(new PSym.At(PSym.At)(pos),PRawString("expandedMacro")(pos),PGrouped.impliedParen(PDelimited.empty))(pos),b)(pos)
}
}

def ExpandMacroIfValid(macroCall: PNode, ctx: ContextA[PNode]): PNode = {
Expand Down
19 changes: 17 additions & 2 deletions src/main/scala/viper/silver/verifier/VerificationError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ trait PartialVerificationError {
def withReasonNodeTransformed(t : errors.ErrorNode => errors.ErrorNode) = {
PartialVerificationError(
(r:ErrorReason) =>
f(r.withNode(t(r.offendingNode)).asInstanceOf[ErrorReason])
f(r.withNode(t(r.offendingNode)).asInstanceOf[ErrorReason])
)
}

Expand Down Expand Up @@ -429,6 +429,14 @@ object errors {
def PostconditionViolated(offendingNode: Exp, member: Contracted): PartialVerificationError =
PartialVerificationError((reason: ErrorReason) => PostconditionViolated(offendingNode, member, reason))

case class PostconditionViolatedBranch(offendingNode: Exp, reason: ErrorReason, leftIsFatal: Boolean, rightIsFatal: Boolean, override val cached: Boolean = false) extends AbstractVerificationError {
val id = "postcondition.violated.branch"
val text = s"Branch fails."

def withNode(offendingNode: errors.ErrorNode = this.offendingNode) = PostconditionViolatedBranch(offendingNode.asInstanceOf[Exp], this.reason, leftIsFatal, rightIsFatal, this.cached)
def withReason(r: ErrorReason) = PostconditionViolatedBranch(offendingNode, r, leftIsFatal, rightIsFatal, cached)
}

case class FoldFailed(offendingNode: Fold, reason: ErrorReason, override val cached: Boolean = false) extends AbstractVerificationError {
val id = "fold.failed"
val text = s"Folding ${offendingNode.acc.loc} might fail."
Expand Down Expand Up @@ -610,7 +618,7 @@ object reasons {
}

case class UnexpectedNode(offendingNode: ErrorNode, explanation: String, stackTrace: Seq[StackTraceElement])
extends AbstractErrorReason {
extends AbstractErrorReason {

val id = "unexpected.node"
def readableMessage = s"$offendingNode occurred unexpectedly. $explanation"
Expand All @@ -625,6 +633,13 @@ object reasons {
def withNode(offendingNode: errors.ErrorNode = this.offendingNode) = AssertionFalse(offendingNode.asInstanceOf[Exp])
}

case class AssertionFalseAtBranch(offendingNode: Exp, treeString: String) extends AbstractErrorReason {
val id = "assertion.false.branch"
def readableMessage = "\n" + treeString

def withNode(offendingNode: errors.ErrorNode = this.offendingNode) = AssertionFalseAtBranch(offendingNode.asInstanceOf[Exp], treeString)
}

// Note: this class should be deprecated/removed - we no longer support epsilon permissions in the language
case class EpsilonAsParam(offendingNode: Exp) extends AbstractErrorReason {
val id = "epsilon.as.param"
Expand Down
Loading