aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/NameOps.scala
diff options
context:
space:
mode:
authorNicolas Stucki <nicolas.stucki@gmail.com>2017-02-09 14:45:42 +0100
committerNicolas Stucki <nicolas.stucki@gmail.com>2017-02-13 18:29:02 +0100
commit93a2d0653e6b74a0f88825ac8a522da87e474f2a (patch)
tree7a97d30544f09083ec0561478bf49b78fb44f2ab /compiler/src/dotty/tools/dotc/core/NameOps.scala
parentb29783237c03ade1dd19cc564170c7a87d7b8b84 (diff)
downloaddotty-93a2d0653e6b74a0f88825ac8a522da87e474f2a.tar.gz
dotty-93a2d0653e6b74a0f88825ac8a522da87e474f2a.tar.bz2
dotty-93a2d0653e6b74a0f88825ac8a522da87e474f2a.zip
Add checks for synthetic functions and erased functions.
* Add `isSyntheticFunction` checks for synthetic functions such as FuntionN for N > 22 and ImplicitFunctionN for N >= 0. * Add `erasedFunctionClass` to get the erased verion of synthetic functions. * Change the semantics of `isFunctionClass` to return true if it is any kind of FunctionN or ImplicitFunctionN.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/NameOps.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameOps.scala45
1 files changed, 38 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala
index c037d1ce7..cd3ae2a25 100644
--- a/compiler/src/dotty/tools/dotc/core/NameOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala
@@ -8,6 +8,7 @@ import Names._, StdNames._, Contexts._, Symbols._, Flags._
import Decorators.StringDecorator
import util.{Chars, NameTransformer}
import Chars.isOperatorPart
+import Definitions._
object NameOps {
@@ -231,13 +232,43 @@ object NameOps {
}
}
- def functionArity: Int = {
- def test(prefix: Name): Int =
- if (name.startsWith(prefix))
- try name.drop(prefix.length).toString.toInt
- catch { case ex: NumberFormatException => -1 }
- else -1
- test(tpnme.Function) max test(tpnme.ImplicitFunction)
+ /** Is a synthetic function name
+ * - N for FunctionN
+ * - N for ImplicitFunctionN
+ * - (-1) otherwise
+ */
+ def functionArity: Int =
+ functionArityFor(tpnme.Function) max functionArityFor(tpnme.ImplicitFunction)
+
+ /** Is a function name
+ * - FunctionN for N >= 0
+ * - ImplicitFunctionN for N >= 0
+ * - false otherwise
+ */
+ def isFunction: Boolean = functionArity >= 0
+
+ /** Is a implicit function name
+ * - ImplicitFunctionN for N >= 0
+ * - false otherwise
+ */
+ def isImplicitFunction: Boolean = functionArityFor(tpnme.ImplicitFunction) >= 0
+
+ /** Is a synthetic function name
+ * - FunctionN for N > 22
+ * - ImplicitFunctionN for N >= 0
+ * - false otherwise
+ */
+ def isSyntheticFunction: Boolean = {
+ functionArityFor(tpnme.Function) > MaxImplementedFunctionArity ||
+ functionArityFor(tpnme.ImplicitFunction) >= 0
+ }
+
+ /** Parsed function arity for function with some specific prefix */
+ private def functionArityFor(prefix: Name): Int = {
+ if (name.startsWith(prefix))
+ try name.toString.substring(prefix.length).toInt
+ catch { case _: NumberFormatException => -1 }
+ else -1
}
/** The name of the generic runtime operation corresponding to an array operation */