Skip to content

Commit

Permalink
Brace reduction and remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Nov 23, 2021
1 parent 8a34dc8 commit 1392f66
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 854 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Compiler {
new ExplicitOuter, // Add accessors to outer classes from nested ones.
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
new ElimByName, // Expand by-name parameter references
new StringInterpolatorOpt) :: // Optimizes raw and s string interpolators by rewriting them to string concatenations
new StringInterpolatorOpt) :: // Optimizes raw and s and f string interpolators by rewriting them to string concatenations or formats
List(new PruneErasedDefs, // Drop erased definitions from scopes and simplify erased expressions
new UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`
new InlinePatterns, // Remove placeholders of inlined patterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import scala.util.matching.Regex.Match

import java.util.{Calendar, Date, Formattable}

import StringContextChecker.InterpolationReporter

/** Formatter string checker. */
abstract class FormatChecker(using reporter: InterpolationReporter):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,7 @@ import scala.util.matching.Regex.Match

object FormatInterpolatorTransform:
import tpd._
import StringContextChecker.InterpolationReporter

/*
/** This trait defines a tool to report errors/warnings that do not depend on Position. */
trait InterpolationReporter:
/** Reports error/warning of size 1 linked with a part of the StringContext.
*
* @param message the message to report as error/warning
* @param index the index of the part inside the list of parts of the StringContext
* @param offset the index in the part String where the error is
* @return an error/warning depending on the function
*/
def partError(message: String, index: Int, offset: Int): Unit
def partWarning(message: String, index: Int, offset: Int): Unit
/** Reports error linked with an argument to format.
*
* @param message the message to report as error/warning
* @param index the index of the argument inside the list of arguments of the format function
* @return an error depending on the function
*/
def argError(message: String, index: Int): Unit
/** Reports error linked with the list of arguments or the StringContext.
*
* @param message the message to report in the error
* @return an error
*/
def strCtxError(message: String): Unit
def argsError(message: String): Unit
/** Claims whether an error or a warning has been reported
*
* @return true if an error/warning has been reported, false
*/
def hasReported: Boolean
/** Stores the old value of the reported and reset it to false */
def resetReported(): Unit
/** Restores the value of the reported boolean that has been reset */
def restoreReported(): Unit
end InterpolationReporter
*/
class PartsReporter(fun: Tree, args0: Tree, parts: List[Tree], args: List[Tree])(using Context) extends InterpolationReporter:
private var reported = false
private var oldReported = false
Expand Down Expand Up @@ -193,3 +149,45 @@ object FormatInterpolatorTransform:
(literally(checked.mkString), tpd.SeqLiteral(checker.actuals.toList, elemtpt))
end checked
end FormatInterpolatorTransform

/** This trait defines a tool to report errors/warnings that do not depend on Position. */
trait InterpolationReporter:

/** Reports error/warning of size 1 linked with a part of the StringContext.
*
* @param message the message to report as error/warning
* @param index the index of the part inside the list of parts of the StringContext
* @param offset the index in the part String where the error is
* @return an error/warning depending on the function
*/
def partError(message: String, index: Int, offset: Int): Unit
def partWarning(message: String, index: Int, offset: Int): Unit

/** Reports error linked with an argument to format.
*
* @param message the message to report as error/warning
* @param index the index of the argument inside the list of arguments of the format function
* @return an error depending on the function
*/
def argError(message: String, index: Int): Unit

/** Reports error linked with the list of arguments or the StringContext.
*
* @param message the message to report in the error
* @return an error
*/
def strCtxError(message: String): Unit
def argsError(message: String): Unit

/** Claims whether an error or a warning has been reported
*
* @return true if an error/warning has been reported, false
*/
def hasReported: Boolean

/** Stores the old value of the reported and reset it to false */
def resetReported(): Unit

/** Restores the value of the reported boolean that has been reset */
def restoreReported(): Unit
end InterpolationReporter
Loading

0 comments on commit 1392f66

Please sign in to comment.