From 93a2d0653e6b74a0f88825ac8a522da87e474f2a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 9 Feb 2017 14:45:42 +0100 Subject: 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. --- compiler/src/dotty/tools/dotc/core/NameOps.scala | 45 ++++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/core/NameOps.scala') 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 */ -- cgit v1.2.3