diff options
| author | Jack | 2016-11-11 13:54:37 -0800 |
|---|---|---|
| committer | Jack Koenig | 2016-11-14 11:11:02 -0800 |
| commit | e60761cf72ba572da0bb8387a4506f5c3e211ac9 (patch) | |
| tree | 1ab359bd6884f49520a1e5ddcf9a3bc40ee89a6b /chiselFrontend | |
| parent | b2b80ce24881782b82b545e0e3cb2a0e4ef83557 (diff) | |
Add SourceInfo.makeMessage to better use SourceInfo in error messages
Diffstat (limited to 'chiselFrontend')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala index 5e3bf33e..f1130db4 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala @@ -19,9 +19,17 @@ import scala.reflect.macros.blackbox.Context /** Abstract base class for generalized source information. */ -sealed trait SourceInfo +sealed trait SourceInfo { + /** A prettier toString + * + * Make a useful message if SourceInfo is available, nothing otherwise + */ + def makeMessage(f: String => String): String +} -sealed trait NoSourceInfo extends SourceInfo +sealed trait NoSourceInfo extends SourceInfo { + def makeMessage(f: String => String): String = "" +} /** For when source info can't be generated because of a technical limitation, like for Reg because * Scala macros don't support named or default arguments. @@ -34,7 +42,9 @@ case object DeprecatedSourceInfo extends NoSourceInfo /** For FIRRTL lines from a Scala source line. */ -case class SourceLine(filename: String, line: Int, col: Int) extends SourceInfo +case class SourceLine(filename: String, line: Int, col: Int) extends SourceInfo { + def makeMessage(f: String => String): String = f(s"@[$filename $line:$col]") +} /** Provides a macro that returns the source information at the invocation point. */ |
