Skip to content

Commit 3007816

Browse files
authored
Merge pull request #600 from viperproject/meilers_noglobalstate
Removing global state
2 parents 452c47c + fdcaed3 commit 3007816

15 files changed

Lines changed: 284 additions & 253 deletions

File tree

src/main/scala/viper/silver/ast/Position.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ class IdentifierPosition(val file: Path, val start: HasLineColumn, val end: Opti
8989
file :: start :: end :: id :: Nil
9090
}
9191

92-
object LineCol {
93-
def apply(index: Int): (Int, Int) = {
92+
class LineCol(fp: FastParser) {
93+
def getPos(index: Int): (Int, Int) = {
9494
// val Array(line, col) = ctx.input.prettyIndex(index).split(":").map(_.toInt)
95-
val line_offset = FastParser._line_offset
95+
val line_offset = fp._line_offset
9696
val result = java.util.Arrays.binarySearch(line_offset, index)
9797
if (result >= 0) {
9898
// Exact match

src/main/scala/viper/silver/ast/utility/Consistency.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package viper.silver.ast.utility
88

99
import viper.silver.ast._
1010
import viper.silver.ast.utility.rewriter.Traverse
11-
import viper.silver.parser.FastParser
11+
import viper.silver.parser.{FastParser, FastParserCompanion}
1212
import viper.silver.verifier.ConsistencyError
1313
import viper.silver.{FastMessage, FastMessaging}
1414

@@ -29,7 +29,7 @@ object Consistency {
2929
recordIfNot(suspect, !property, message)
3030

3131
/** Names that are not allowed for use in programs. */
32-
def reservedNames: Seq[String] = FastParser.keywords.toSeq
32+
def reservedNames: Set[String] = FastParserCompanion.basicKeywords
3333

3434
/** Returns true iff the string `name` is a valid identifier. */
3535
val identFirstLetter = "[a-zA-Z$_]"

src/main/scala/viper/silver/cfg/CfgTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object CfgTest {
3636
}
3737

3838
private def parse[_: P](input: String, file: Path): Option[PProgram] = {
39-
val result = FastParser.parse(input, file)
39+
val result = new FastParser().parse(input, file)
4040
result match {
4141
case Parsed.Success(program@PProgram(_, _, _, _, _, _, _,_, errors), _) =>
4242
if (errors.isEmpty || errors.forall(_.isInstanceOf[ParseWarning])) Some(program)

src/main/scala/viper/silver/frontend/SilFrontend.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ trait SilFrontend extends DefaultFrontend {
8989
/** For testing of plugin import feature */
9090
def defaultPluginCount: Int = defaultPlugins.size
9191

92+
protected val fp = new FastParser()
9293

9394
protected var _plugins: SilverPluginManager = SilverPluginManager(defaultPlugins match {
9495
case Seq() => None
9596
case s => Some(s.mkString(":"))
96-
})(reporter, logger, _config)
97+
})(reporter, logger, _config, fp)
9798

9899
def plugins: SilverPluginManager = _plugins
99100

@@ -187,7 +188,7 @@ trait SilFrontend extends DefaultFrontend {
187188
val list = _config.plugin.toOption ++ defaultPlugins
188189
if (list.isEmpty) { None } else { Some(list.mkString(":")) }
189190
}
190-
_plugins = SilverPluginManager(plugins)(reporter, logger, _config)
191+
_plugins = SilverPluginManager(plugins)(reporter, logger, _config, fp)
191192
}
192193
}
193194

@@ -233,7 +234,7 @@ trait SilFrontend extends DefaultFrontend {
233234
val file = _inputFile.get
234235
_plugins.beforeParse(input, isImported = false) match {
235236
case Some(inputPlugin) =>
236-
val result = FastParser.parse(inputPlugin, file, Some(_plugins))
237+
val result = fp.parse(inputPlugin, file, Some(_plugins))
237238
result match {
238239
case Parsed.Success(e@ PProgram(_, _, _, _, _, _, _, _, err_list), _) =>
239240
if (err_list.isEmpty || err_list.forall(p => p.isInstanceOf[ParseWarning])) {
@@ -243,7 +244,7 @@ trait SilFrontend extends DefaultFrontend {
243244
else Fail(err_list)
244245
case fail @ Parsed.Failure(_, index, extra) =>
245246
val msg = fail.trace().longAggregateMsg
246-
val (line, col) = LineCol(index)
247+
val (line, col) = fp.lineCol.getPos(index)
247248
Fail(List(ParseError(s"Expected $msg", SourcePosition(file, line, col))))
248249
//? val pos = extra.input.prettyIndex(index).split(":").map(_.toInt)
249250
//? Fail(List(ParseError(s"Expected $msg", SourcePosition(file, pos(0), pos(1)))))

0 commit comments

Comments
 (0)