forked from NetLogo/NetLogo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindbadmath.scala
executable file
·59 lines (51 loc) · 2.47 KB
/
findbadmath.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
exec scala -classpath bin -deprecation -nocompdaemon -Dfile.encoding=UTF-8 "$0" "$@"
!#
// The purpose of all this is to make sure that every class and interface is declared strictfp, and
// that we never ever use Math, only StrictMath.
import sys.process.Process
def withoutComments(lines: Seq[String]): Seq[String] = {
def helper(lines: Seq[String]): Seq[String] =
if(lines.isEmpty)
lines
else {
val (nonComment, rest) = lines.span(!_.containsSlice("/*"))
nonComment ++ helper(rest.dropWhile(!_.containsSlice("*/")).drop(1))
}
helper(lines.filter(!_.matches("""^//.*""")))
}
// first do the strictfp check
val okDeclarations =
List("strictfp class","public strictfp class","public abstract strictfp","public final strictfp",
"public strictfp class", "final strictfp class", "strictfp class", "strictfp final class",
"abstract strictfp class", "strictfp abstract class", "public strictfp final class",
"public enum","interface", "public interface",
"class AbstractEditorArea", "class TokenLexer", "class ImportLexer") // let's not bother making JFlex emit "strictfp"
for {
path <- Process("find netlogo-core/src netlogo-gui/src -name *.java").lineStream
if !path.containsSlice("/gl/render/") // we don't care if OpenGL stuff is strictfp
} {
val lines = for{line <- withoutComments(io.Source.fromFile(path).getLines.toSeq)
if !line.matches("""\s*""")
if !line.matches("""package.*""")
if !line.matches("""import.*""")}
yield line
if(!lines.exists(line => okDeclarations.exists(ok => line.startsWith(ok + " ") ||
line.endsWith(ok))))
println("needs strictfp: " + path)
}
// now do the StrictMath check
for{path <- Process("find netlogo-core/src netlogo-gui/src -name *.java").lineStream
if !path.containsSlice("/gl/render/") // we don't care if OpenGL stuff is strictfp
if path != "src/org/nlogo/headless/TestCommands.java"}
// this isn't the absolutely correct check to be doing, but it seems like a good enough heuristic
// for now - ST 5/8/03
if(io.Source.fromFile(path).getLines
.filter(!_.containsSlice("Mathematica"))
.filter(!_.containsSlice("DummyMath"))
.filter(!_.containsSlice("Activation.java")) // Activation uses Math.max, on "safe" data
.exists(_.matches(""".*[^t]Math.*""")))
println("needs StrictMath: " + path)
// Local Variables:
// mode: scala
// End: