Skip to content
Open
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
21 changes: 21 additions & 0 deletions src/main/scala/singleton/ops/impl/GeneralMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,9 @@ trait GeneralMacros {
def buildWarningMsg(msg: String): String = s"Warning: $buildWarningMsgLoc $msg"
def buildWarningMsg(msg: Tree): Tree = q""" "Warning: " + $buildWarningMsgLoc + " " + $msg """

def buildInfoMsg(msg: String): String = s"Info: $buildWarningMsgLoc $msg"
def buildInfoMsg(msg: Tree): Tree = q""" "Info: " + $buildWarningMsgLoc + " " + $msg """

def constantTreeOf(t : Any) : Tree = Literal(Constant(t))

def constantTypeOf(t: Any) : Type = c.internal.constantType(Constant(t))
Expand Down Expand Up @@ -1048,6 +1051,13 @@ trait GeneralMacros {
case CalcLit.String(msg) =>
if (cArg.tpe.typeSymbol == symbolOf[Warn]) {
println(buildWarningMsg(msg))
c.warning(c.enclosingPosition, msg)

CalcLit(false)
} else if (cArg.tpe.typeSymbol == symbolOf[Info]) {
println(buildInfoMsg(msg))
c.info(c.enclosingPosition, msg, force = true)

CalcLit(false)
} else if (cArg.tpe.typeSymbol == symbolOf[NoSym]) {
abort(msg)
Expand All @@ -1059,6 +1069,8 @@ trait GeneralMacros {
case CalcNLit(Primitive.String, msg, _) => cArg match {
case CalcUnknown(t, _) if t.typeSymbol == symbolOf[Warn] =>
CalcNLit(Primitive.Boolean, q"""{println(${buildWarningMsg(msg)}); false}""")
case CalcUnknown(t, _) if t.typeSymbol == symbolOf[Info] =>
CalcNLit(Primitive.Boolean, q"""{println(${buildInfoMsg(msg)}); false}""")
case _ =>
CalcNLit(Primitive.Boolean, q"{_root_.singleton.ops.impl._require(false, $msg); false}")
}
Expand All @@ -1076,6 +1088,15 @@ trait GeneralMacros {
false
}
}""")
case CalcUnknown(t, _) if t == symbolOf[Info] =>
CalcNLit(Primitive.Boolean,
q"""{
if ($cond) true
else {
println(${buildInfoMsg(msgt)})
false
}
}""")
case _ =>
CalcNLit(Primitive.Boolean, q"{_root_.singleton.ops.impl._require($cond, $msgt); true}")
}
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/singleton/ops/impl/OpId.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package singleton.ops.impl

sealed trait Warn
sealed trait Info
sealed trait NoSym
sealed trait OpId
object OpId {
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/singleton/ops/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ package object ops {
type RequireMsg[Cond,Msg] = OpMacro[OpId.Require, Cond, Msg, NoSym]
type RequireMsgSym[Cond,Msg,Sym] = OpMacro[OpId.Require, Cond, Msg, GetType[Sym]]
type Warn = impl.Warn
type Info = impl.Info
type ToNat[P1] = OpMacro[OpId.ToNat, P1, NP, NP]
type ToChar[P1] = OpMacro[OpId.ToChar, P1, NP, NP]
type ToInt[P1] = OpMacro[OpId.ToInt, P1, NP, NP]
Expand Down