File tree Expand file tree Collapse file tree 6 files changed +55
-24
lines changed Expand file tree Collapse file tree 6 files changed +55
-24
lines changed Original file line number Diff line number Diff line change 3
3
package inox
4
4
5
5
import utils ._
6
+ import Position .smartPos
6
7
7
8
abstract class DebugSection (val name : String )
8
9
@@ -166,20 +167,6 @@ class DefaultReporter(debugSections: Set[DebugSection]) extends Reporter(debugSe
166
167
case DEBUG (_) => " [" + Console .MAGENTA + " Debug " + Console .RESET + " ]"
167
168
}
168
169
169
- def smartPos (p : Position ): String = {
170
- if (p == NoPosition ) {
171
- " "
172
- } else {
173
- val target = p.file.getAbsolutePath()
174
- val here = new java.io.File (" ." ).getAbsolutePath().stripSuffix(" ." )
175
- val diff = target.stripPrefix(here)
176
-
177
- val filePos = diff+ " :"
178
-
179
- filePos + p + " : "
180
- }
181
- }
182
-
183
170
def emit (msg : Message ) = synchronized {
184
171
println(reline(severityToPrefix(msg.severity), smartPos(msg.position) + msg.msg.toString))
185
172
printLineContent(msg.position, false )
Original file line number Diff line number Diff line change @@ -58,11 +58,7 @@ trait PortfolioSolver extends Solver { self =>
58
58
}
59
59
}
60
60
61
- tasks = Future .sequence(fs).map(_ => ())
62
-
63
- val result = Future .find(fs.toList)(_._2 != Unknown )
64
-
65
- val res = Await .result(result, Duration .Inf ) match {
61
+ inox.utils.FutureUtils .findFirst(fs)(_._2 != Unknown ) match {
66
62
case Some ((s, r)) =>
67
63
resultSolver = s.getResultSolver
68
64
resultSolver.foreach { solv =>
@@ -72,14 +68,13 @@ trait PortfolioSolver extends Solver { self =>
72
68
r
73
69
case None =>
74
70
reporter.debug(" No solver succeeded" )
75
- // fs.foreach(f => println(f.value))
76
71
config.cast(Unknown )
77
72
}
78
73
79
74
// TODO: Decide if we really want to wait for all the solvers.
80
75
// I understand we interrupt them, but what if one gets stuck
81
76
// fs foreach { Await.ready(_, Duration.Inf) }
82
- res
77
+ // res
83
78
}
84
79
85
80
Original file line number Diff line number Diff line change
1
+ /* Copyright 2009-2021 EPFL, Lausanne */
2
+
3
+ package inox .utils
4
+
5
+ import scala .util ._
6
+ import scala .concurrent ._
7
+ import scala .concurrent .duration ._
8
+ import scala .concurrent .ExecutionContext .Implicits .global
9
+ import java .util .concurrent .atomic .AtomicInteger
10
+
11
+ object FutureUtils {
12
+
13
+ def findFirst [T ](futures : Seq [Future [T ]])(cond : T => Boolean ): Option [T ] = {
14
+ val p = Promise [Option [T ]]()
15
+ val n = futures.length
16
+ val i = new AtomicInteger (0 )
17
+
18
+ for (future <- futures) {
19
+ future.onComplete((result : Try [T ]) => result match {
20
+ case Success (res) if cond(res) =>
21
+ p.trySuccess(Some (res))
22
+ case _ =>
23
+ val finished = i.incrementAndGet()
24
+ if (finished == n) p.trySuccess(None )
25
+ })
26
+ }
27
+ Await .result(p.future, Duration .Inf )
28
+ }
29
+
30
+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,21 @@ abstract class Position extends Ordered[Position] {
35
35
}
36
36
37
37
object Position {
38
+
39
+ def smartPos (p : Position ): String = {
40
+ if (p == NoPosition ) {
41
+ " "
42
+ } else {
43
+ val target = p.file.getAbsolutePath()
44
+ val here = new java.io.File (" ." ).getAbsolutePath().stripSuffix(" ." )
45
+ val diff = target.stripPrefix(here)
46
+
47
+ val filePos = diff+ " :"
48
+
49
+ filePos + p + " : "
50
+ }
51
+ }
52
+
38
53
def between (a : Position , b : Position ): Position = {
39
54
if (a.file == b.file) {
40
55
if (a.line == b.line && a.col == b.col) {
Original file line number Diff line number Diff line change @@ -17,15 +17,17 @@ object StringUtils {
17
17
}
18
18
19
19
def encodeByte (b : Byte ): String = " \\ x" + toHex((b >> 4 ) & 0xF ) + toHex(b & 0xF )
20
- def decodeHex (s : String ): Byte = ((fromHex(s.charAt(2 )) << 4 ) + fromHex(s.charAt(3 ))).toByte
20
+ def decodeHex (s : String ): Byte = ((fromHex(s.charAt(0 )) << 4 ) + fromHex(s.charAt(1 ))).toByte
21
21
22
22
private val hex = """ ^\\ x[0-9A-Fa-f]{2}""" .r
23
+ private val uhex1 = """ (?s)^\\ u\{([0-9A-Fa-f])\}(.*)""" .r
24
+ private val uhex2 = """ (?s)^\\ u\{([0-9A-Fa-f]{2})\}(.*)""" .r
23
25
24
26
object Hex {
25
27
def unapply (s : String ): Option [(Byte , String )] = {
26
28
if (hex.findFirstIn(s).isDefined) {
27
29
val (head, s2) = s.splitAt(4 )
28
- Some ((decodeHex(head), s2))
30
+ Some ((decodeHex(head.drop( 2 ) ), s2))
29
31
} else {
30
32
None
31
33
}
@@ -44,6 +46,8 @@ object StringUtils {
44
46
}
45
47
46
48
def decode (s : String ): String = if (s.isEmpty) s else (s match {
49
+ case uhex1(head, s2) => (fromHex(head.charAt(0 )) & 0xF ).toChar + decode(s2)
50
+ case uhex2(head, s2) => (decodeHex(head) & 0xFF ).toChar + decode(s2)
47
51
case JavaEncoded (b, s2) => (b & 0xFF ).toChar + decode(s2)
48
52
case _ => s.head + decode(s.tail)
49
53
})
Original file line number Diff line number Diff line change 1
- /* Copyright 2009-2018 EPFL, Lausanne */
1
+ /* Copyright 2009-2021 EPFL, Lausanne */
2
2
3
3
package inox
4
4
You can’t perform that action at this time.
0 commit comments