diff options
author | odersky <odersky@gmail.com> | 2017-02-16 10:56:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 10:56:46 +0100 |
commit | 6df672c7e7be65d7be1cd6524c610aed4f35178c (patch) | |
tree | a1b709dc631f0891b6a2c7c628439443c75f14e2 /compiler/src/dotty/tools/dotc/core/NameOps.scala | |
parent | 39af2f595979c6bbeb3cfa52d401cf59be68126b (diff) | |
parent | 93a2d0653e6b74a0f88825ac8a522da87e474f2a (diff) | |
download | dotty-6df672c7e7be65d7be1cd6524c610aed4f35178c.tar.gz dotty-6df672c7e7be65d7be1cd6524c610aed4f35178c.tar.bz2 dotty-6df672c7e7be65d7be1cd6524c610aed4f35178c.zip |
Merge pull request #1962 from dotty-staging/centralize-function-logic
Factor out logic for scala functions.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/NameOps.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/NameOps.scala | 45 |
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 */ |