From ae4910485511c12cda0c110b6563610041070b5d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 1 Nov 2010 20:31:12 +0000 Subject: Created @strictfp annotation in scala.annotation. your fp with no tolerance for tomfoolery, this is the commit for you. Closes #1708, review by community. --- src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 3 +++ src/compiler/scala/tools/nsc/symtab/Definitions.scala | 4 ++-- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 1 + src/library/scala/annotation/strictfp.scala | 18 ++++++++++++++++++ test/files/pos/FPTest.scala | 11 +++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/library/scala/annotation/strictfp.scala create mode 100644 test/files/pos/FPTest.scala diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 5a02de0907..230dea2f3b 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -635,6 +635,9 @@ abstract class GenJVM extends SubComponent { if (jclass.isInterface()) flags |= ACC_ABSTRACT + if (m.symbol.isStrictFP) + flags |= ACC_STRICT + // native methods of objects are generated in mirror classes if (method.native) flags |= ACC_NATIVE diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 4e16f06566..08cbab7933 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -142,8 +142,7 @@ trait Definitions extends reflect.generic.StandardDefinitions { lazy val ParamTargetClass = getClass("scala.annotation.target.param") lazy val ScalaInlineClass = getClass("scala.inline") lazy val ScalaNoInlineClass = getClass("scala.noinline") - lazy val SpecializedClass = definitions.getClass("scala.specialized") - + lazy val SpecializedClass = getClass("scala.specialized") // fundamental reference classes lazy val ScalaObjectClass = getClass("scala.ScalaObject") @@ -472,6 +471,7 @@ trait Definitions extends reflect.generic.StandardDefinitions { lazy val NativeAttr: Symbol = getClass("scala.native") lazy val RemoteAttr: Symbol = getClass("scala.remote") lazy val ScalaNumberClass: Symbol = getClass("scala.math.ScalaNumber") + lazy val ScalaStrictFPAttr: Symbol = getClass("scala.annotation.strictfp") lazy val SerialVersionUIDAttr: Symbol = getClass("scala.SerialVersionUID") lazy val SerializableAttr: Symbol = getClass("scala.serializable") lazy val TraitSetterAnnotationClass: Symbol = getClass("scala.runtime.TraitSetter") diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index e0a1b13fdf..1d795d669f 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -396,6 +396,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => } } + def isStrictFP = hasAnnotation(ScalaStrictFPAttr) || (enclClass hasAnnotation ScalaStrictFPAttr) def isSerializable = hasAnnotation(SerializableAttr) def isDeprecated = hasAnnotation(DeprecatedAttr) def deprecationMessage = getAnnotation(DeprecatedAttr) flatMap { _.stringArg(0) } diff --git a/src/library/scala/annotation/strictfp.scala b/src/library/scala/annotation/strictfp.scala new file mode 100644 index 0000000000..b6852c69ef --- /dev/null +++ b/src/library/scala/annotation/strictfp.scala @@ -0,0 +1,18 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.annotation + +/** If this annotation is present on a method or its enclosing class, + * the strictfp flag will be emitted. + * + * @author Paul Phillips + * @version 2.9 + * @since 2.9 + */ +class strictfp extends StaticAnnotation diff --git a/test/files/pos/FPTest.scala b/test/files/pos/FPTest.scala new file mode 100644 index 0000000000..b351b7bb9c --- /dev/null +++ b/test/files/pos/FPTest.scala @@ -0,0 +1,11 @@ +// On some hypothetical future day when we can test the emitted bytecode, +// should look for the fp bit. Until then, just a pos test. +import annotation.strictfp + +@strictfp class FPTest { + def main(args: Array[String]): Unit = { + val d: Double = 8e+307 + println(4.0 * d * 0.5); + println(2.0 * d); + } +} -- cgit v1.2.3