From c1d65ffedeb59911089fd5f57c07b7e399681704 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 22 Jun 2017 13:53:03 +0300 Subject: [PATCH] Fix warnings (#690) --- runtime/src/main/cpp/Memory.cpp | 2 +- .../main/kotlin/konan/internal/Coroutines.kt | 3 +- .../konan/internal/FloatingPointParser.kt | 25 +++--- .../kotlin/konan/internal/HexStringParser.kt | 8 +- .../kotlin/konan/internal/KPropertyImpl.kt | 16 ++-- .../kotlin/konan/internal/NumberConverter.kt | 4 +- .../src/main/kotlin/konan/worker/Worker.kt | 22 ++--- .../experimental/CoroutinesLibrary.kt | 2 +- .../experimental/intrinsics/Intrinsics.kt | 4 +- .../main/kotlin/kotlin/reflect/KProperty.kt | 8 +- .../src/main/kotlin/kotlin/text/Strings.kt | 4 +- .../main/kotlin/kotlin/text/regex/Pattern.kt | 2 +- .../regex/sets/HangulDecomposedCharSet.kt | 4 +- samples/androidNativeActivity/android.def | 3 +- .../androidNativeActivity/androidLauncher.h | 85 +++++++++++++++++++ samples/androidNativeActivity/build.gradle | 8 +- 16 files changed, 142 insertions(+), 58 deletions(-) create mode 100644 samples/androidNativeActivity/androidLauncher.h diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index f3a36c8e0d2..6cb9177a1c5 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -131,7 +131,7 @@ inline ObjHeader** asArenaSlot(ObjHeader** slot) { inline uint32_t hashOf(ContainerHeader* container) { uintptr_t value = reinterpret_cast(container); - return static_cast(value >> 3) ^ static_cast(value >> 32); + return static_cast(value >> 3) ^ static_cast(static_cast(value) >> 32); } inline uint32_t freeableSize(MemoryState* state) { diff --git a/runtime/src/main/kotlin/konan/internal/Coroutines.kt b/runtime/src/main/kotlin/konan/internal/Coroutines.kt index 8a0e944a8d7..0593917096a 100644 --- a/runtime/src/main/kotlin/konan/internal/Coroutines.kt +++ b/runtime/src/main/kotlin/konan/internal/Coroutines.kt @@ -9,7 +9,8 @@ internal fun getContinuation(): Continuation = throw AssertionError("Call @Intrinsic @PublishedApi -internal suspend fun returnIfSuspended(value: Any?): T = throw AssertionError("Call to returnIfSuspended should've been lowered") +internal suspend fun returnIfSuspended(@Suppress("UNUSED_PARAMETER") argument: Any?): T + = throw AssertionError("Call to returnIfSuspended should've been lowered") // Single-threaded continuation. class SafeContinuation diff --git a/runtime/src/main/kotlin/konan/internal/FloatingPointParser.kt b/runtime/src/main/kotlin/konan/internal/FloatingPointParser.kt index 65ae41d3f23..214dab99731 100644 --- a/runtime/src/main/kotlin/konan/internal/FloatingPointParser.kt +++ b/runtime/src/main/kotlin/konan/internal/FloatingPointParser.kt @@ -89,21 +89,18 @@ object FloatingPointParser { * taking the positive integer the String represents and multiplying by 10 * raised to the power of the exponent. - * @param s + * @param string * * the String that will be parsed to a floating point * * - * @param length - * * the length of s - * * * @return a StringExponentPair with necessary values * * * * * @exception NumberFormatException * * if the String doesn't pass basic tests */ - private fun initialParse(s: String, length: Int): StringExponentPair { - var s = s - var length = length + private fun initialParse(string: String): StringExponentPair { + var s = string + var length = s.length var negative = false var c: Char var start: Int @@ -310,7 +307,7 @@ object FloatingPointParser { /** * Returns the closest double value to the real number in the string. - * @param s + * @param string * * the String that will be parsed to a floating point * * * @return the double closest to the real number @@ -319,8 +316,8 @@ object FloatingPointParser { * @exception NumberFormatException * * if the String doesn't represent a double */ - fun parseDouble(s: String): Double { - var s = s + fun parseDouble(string: String): Double { + var s = string s = s.trim { it <= ' ' } val length = s.length @@ -339,7 +336,7 @@ object FloatingPointParser { return HexStringParser.parseDouble(s) } - val info = initialParse(s, length) + val info = initialParse(s) // Two kinds of situation will directly return 0.0: // 1. info.s is 0; @@ -371,8 +368,8 @@ object FloatingPointParser { * @exception NumberFormatException * * if the String doesn't represent a float */ - fun parseFloat(s: String): Float { - var s = s + fun parseFloat(string: String): Float { + var s = string s = s.trim { it <= ' ' } val length = s.length @@ -391,7 +388,7 @@ object FloatingPointParser { return HexStringParser.parseFloat(s) } - val info = initialParse(s, length) + val info = initialParse(s) // Two kinds of situation will directly return 0.0f. // 1. info.s is 0; diff --git a/runtime/src/main/kotlin/konan/internal/HexStringParser.kt b/runtime/src/main/kotlin/konan/internal/HexStringParser.kt index 942235ae7a3..74c4914a4b6 100644 --- a/runtime/src/main/kotlin/konan/internal/HexStringParser.kt +++ b/runtime/src/main/kotlin/konan/internal/HexStringParser.kt @@ -78,8 +78,8 @@ internal class HexStringParser(private val EXPONENT_WIDTH: Int, private val MANT /* * Parses the exponent field. */ - private fun parseExponent(exponentStr: String) { - var exponentStr = exponentStr + private fun parseExponent(exponentString: String) { + var exponentStr = exponentString val leadingChar = exponentStr[0] val expSign = if (leadingChar == '-') -1 else 1 if (!leadingChar.isDigit()) { @@ -247,8 +247,8 @@ internal class HexStringParser(private val EXPONENT_WIDTH: Int, private val MANT * characters "0x1." followed by a lowercase hexadecimal representation of * the rest of the significand as a fraction. */ - private fun getOffset(strIntegerPart: String, strDecimalPart: String): Int { - var strIntegerPart = strIntegerPart + private fun getOffset(strIntegerPartParam: String, strDecimalPart: String): Int { + var strIntegerPart = strIntegerPartParam strIntegerPart = strIntegerPart.replaceFirst("^0+".toRegex(), "") //$NON-NLS-1$ //$NON-NLS-2$ // If the Integer part is a nonzero number. diff --git a/runtime/src/main/kotlin/konan/internal/KPropertyImpl.kt b/runtime/src/main/kotlin/konan/internal/KPropertyImpl.kt index ed38053a25e..487ddda7b00 100644 --- a/runtime/src/main/kotlin/konan/internal/KPropertyImpl.kt +++ b/runtime/src/main/kotlin/konan/internal/KPropertyImpl.kt @@ -50,11 +50,11 @@ open class KProperty0Impl(override val name: String, val getter: () -> R) @FixmeReflection open class KProperty1Impl(override val name: String, val getter: (T) -> R): KProperty1 { - override fun get(receiver: T): R { - return getter(receiver) + override fun get(p1: T): R { + return getter(p1) } - override fun invoke(receiver: T): R { - return getter(receiver) + override fun invoke(p1: T): R { + return getter(p1) } override fun equals(other: Any?): Boolean { @@ -74,11 +74,11 @@ open class KProperty1Impl(override val name: String, val getter: (T) - @FixmeReflection open class KProperty2Impl(override val name: String, val getter: (T1, T2) -> R): KProperty2 { - override fun get(receiver1: T1, receiver2: T2): R { - return getter(receiver1, receiver2) + override fun get(p1: T1, p2: T2): R { + return getter(p1, p2) } - override fun invoke(receiver1: T1, receiver2: T2): R { - return getter(receiver1, receiver2) + override fun invoke(p1: T1, p2: T2): R { + return getter(p1, p2) } override fun equals(other: Any?): Boolean { diff --git a/runtime/src/main/kotlin/konan/internal/NumberConverter.kt b/runtime/src/main/kotlin/konan/internal/NumberConverter.kt index 067e5e38d26..0a039984428 100644 --- a/runtime/src/main/kotlin/konan/internal/NumberConverter.kt +++ b/runtime/src/main/kotlin/konan/internal/NumberConverter.kt @@ -50,7 +50,7 @@ class NumberConverter { // The value of the 'significand bits' of the inputNumber. var f = inputNumberBits and fMask val mantissaIsZero = f == 0L - var pow = 0 + var pow: Int var numBits = 52 if (e == 2047) @@ -100,7 +100,7 @@ class NumberConverter { // The value of the 'significand bits' of the inputNumber. var f = inputNumberBits and fMask val mantissaIsZero = f == 0 - var pow = 0 + var pow: Int var numBits = 23 if (e == 255) diff --git a/runtime/src/main/kotlin/konan/worker/Worker.kt b/runtime/src/main/kotlin/konan/worker/Worker.kt index 8e0a2f04691..6c4ff3613c7 100644 --- a/runtime/src/main/kotlin/konan/worker/Worker.kt +++ b/runtime/src/main/kotlin/konan/worker/Worker.kt @@ -92,7 +92,7 @@ class Future internal constructor(val id: FutureId) { fun consume(code: (T) -> Unit) { when (state) { FutureState.SCHEDULED, FutureState.COMPUTED -> { - val value = consumeFuture(id) as T + val value = @Suppress("UNCHECKED_CAST") (consumeFuture(id) as T) code(value) } FutureState.INVALID -> @@ -103,7 +103,7 @@ class Future internal constructor(val id: FutureId) { } val state: FutureState - get() = FutureState.values()[stateOfFuture(id)] + get() = FutureState.values()[stateOfFuture(id)] override fun equals(other: Any?): Boolean { return (other is Future<*>) && (id == other.id) @@ -136,8 +136,8 @@ class Worker(val id: WorkerId) { * and result of such a execution is being disconnected from worker's object graph. Whoever will consume * the future, can use result of worker's computations. */ - fun schedule(mode: TransferMode, producer: () -> T1, - @VolatileLambda job: (T1) -> T2): Future = + @Suppress("UNUSED_PARAMETER") + fun schedule(mode: TransferMode, producer: () -> T1, @VolatileLambda job: (T1) -> T2): Future = /** * This function is a magical operation, handled by lowering in the compiler, and replaced with call to * scheduleImpl(worker, mode, producer, job) @@ -159,13 +159,13 @@ class Worker(val id: WorkerId) { * Typically new worker may be needed for computations offload to another core, for IO it may be * better to use non-blocking IO combined with more lightweight coroutines. */ -fun startWorker() : Worker = Worker(startInternal()) +fun startWorker(): Worker = Worker(startInternal()) /** * Wait for availability of futures in the collection. Returns set with all futures which have * value available for the consumption. */ -fun Collection>.waitForMultipleFutures(millis: Int) : Set> { +fun Collection>.waitForMultipleFutures(millis: Int): Set> { val result = mutableSetOf>() while (true) { @@ -192,7 +192,7 @@ fun Collection>.waitForMultipleFutures(millis: Int) : Set T.shallowCopy(): T = shallowCopyInternal(this) as T +fun T.shallowCopy(): T = @Suppress("UNCHECKED_CAST") (shallowCopyInternal(this) as T) /** * Creates verbatim *deep* copy of passed object's graph, use *VERY* carefully to create disjoint object graph. @@ -203,21 +203,21 @@ fun T.deepCopy(): T = TODO() // Implementation details. @konan.internal.ExportForCompiler internal fun scheduleImpl(worker: Worker, mode: TransferMode, producer: () -> Any?, - job: CPointer>) : Future = + job: CPointer>): Future = Future(scheduleInternal(worker.id, mode.value, producer, job)) @SymbolName("Kotlin_Worker_startInternal") -external internal fun startInternal() : WorkerId +external internal fun startInternal(): WorkerId @SymbolName("Kotlin_Worker_requestTerminationWorkerInternal") external internal fun requestTerminationInternal(id: WorkerId, processScheduledJobs: Boolean): FutureId @SymbolName("Kotlin_Worker_scheduleInternal") external internal fun scheduleInternal( - id: WorkerId, mode: Int, producer: () -> Any?, job: CPointer>) : FutureId + id: WorkerId, mode: Int, producer: () -> Any?, job: CPointer>): FutureId @SymbolName("Kotlin_Worker_shallowCopyInternal") -external internal fun shallowCopyInternal(value: Any?) : Any? +external internal fun shallowCopyInternal(value: Any?): Any? @SymbolName("Kotlin_Worker_stateOfFuture") external internal fun stateOfFuture(id: FutureId): Int diff --git a/runtime/src/main/kotlin/kotlin/coroutines/experimental/CoroutinesLibrary.kt b/runtime/src/main/kotlin/kotlin/coroutines/experimental/CoroutinesLibrary.kt index c5860db8cea..c85bfbbb0f4 100644 --- a/runtime/src/main/kotlin/kotlin/coroutines/experimental/CoroutinesLibrary.kt +++ b/runtime/src/main/kotlin/kotlin/coroutines/experimental/CoroutinesLibrary.kt @@ -95,7 +95,7 @@ internal inline fun processBareContinuationResume(completion: Continuation<*>, b try { val result = block() if (result !== COROUTINE_SUSPENDED) { - (completion as Continuation).resume(result) + @Suppress("UNCHECKED_CAST") (completion as Continuation).resume(result) } } catch (t: Throwable) { completion.resumeWithException(t) diff --git a/runtime/src/main/kotlin/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt b/runtime/src/main/kotlin/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt index 9e6f726d246..77a8c96ca00 100644 --- a/runtime/src/main/kotlin/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt +++ b/runtime/src/main/kotlin/kotlin/coroutines/experimental/intrinsics/Intrinsics.kt @@ -63,7 +63,7 @@ public fun (suspend () -> T).createCoroutineUnchecked( ): Continuation = if (this !is CoroutineImpl) buildContinuationByInvokeCall(completion) { - (this as Function1, Any?>).invoke(completion) + @Suppress("UNCHECKED_CAST") (this as Function1, Any?>).invoke(completion) } else (this.create(completion) as CoroutineImpl).facade @@ -84,7 +84,7 @@ public fun (suspend R.() -> T).createCoroutineUnchecked( ): Continuation = if (this !is CoroutineImpl) buildContinuationByInvokeCall(completion) { - (this as Function2, Any?>).invoke(receiver, completion) + @Suppress("UNCHECKED_CAST") (this as Function2, Any?>).invoke(receiver, completion) } else (this.create(receiver, completion) as CoroutineImpl).facade diff --git a/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt b/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt index 267d91a956c..571f9181755 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt @@ -81,8 +81,8 @@ public interface KProperty0 : kotlin.reflect.KProperty, () -> R { public interface KProperty1 : kotlin.reflect.KProperty, (T) -> R { // public abstract val getter: kotlin.reflect.KProperty1.Getter - public abstract fun get(receiver: T): R - public override abstract operator fun invoke(receiver: T): R + public abstract fun get(p1: T): R + public override abstract operator fun invoke(p1: T): R // @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any? // @@ -94,8 +94,8 @@ public interface KProperty1 : kotlin.reflect.KProperty, (T) -> R { public interface KProperty2 : kotlin.reflect.KProperty, (T1, T2) -> R { // public abstract val getter: kotlin.reflect.KProperty1.Getter - public abstract fun get(receiver1: T1, receiver2: T2): R - public override abstract operator fun invoke(receiver1: T1, receiver2: T2): R + public abstract fun get(p1: T1, p2: T2): R + public override abstract operator fun invoke(p1: T1, p2: T2): R // @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any? // diff --git a/runtime/src/main/kotlin/kotlin/text/Strings.kt b/runtime/src/main/kotlin/kotlin/text/Strings.kt index da96a7585c0..79b9d858d33 100644 --- a/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -1089,7 +1089,7 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v private fun CharSequence.rangesDelimitedBy(delimiters: CharArray, startIndex: Int = 0, ignoreCase: Boolean = false, limit: Int = 0): Sequence { require(limit >= 0, { "Limit must be non-negative, but was $limit." }) - return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> findAnyOf(delimiters, startIndex, ignoreCase = ignoreCase, last = false)?.let { it.first to 1 } }) + return DelimitedRangesSequence(this, startIndex, limit, { index -> findAnyOf(delimiters, index, ignoreCase = ignoreCase, last = false)?.let { it.first to 1 } }) } @@ -1111,7 +1111,7 @@ private fun CharSequence.rangesDelimitedBy(delimiters: Array, startI require(limit >= 0, { "Limit must be non-negative, but was $limit." } ) val delimitersList = delimiters.asList() - return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> findAnyOf(delimitersList, startIndex, ignoreCase = ignoreCase, last = false)?.let { it.first to it.second.length } }) + return DelimitedRangesSequence(this, startIndex, limit, { index -> findAnyOf(delimitersList, index, ignoreCase = ignoreCase, last = false)?.let { it.first to it.second.length } }) } diff --git a/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt b/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt index fe7aee0ccc3..18fff30dda4 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt @@ -254,7 +254,7 @@ internal class Pattern(val pattern: String, flags: Int = 0) { curSymb = lexemes.currentChar curSymbIndex = curSymb - Lexer.TBase if (curSymbIndex >= 0 && curSymbIndex < Lexer.TCount) { - codePointsHangul[readCodePoints++] = curSymb.toChar() + codePointsHangul[@Suppress("UNUSED_CHANGED_VALUE")readCodePoints++] = curSymb.toChar() lexemes.next() //LVT syllable diff --git a/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt b/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt index 3ab55584c6a..dc704cdc9be 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt @@ -77,7 +77,7 @@ internal class HangulDecomposedCharSet( * http://www.unicode.org/versions/Unicode4.0.0/ch03.pdf * "3.12 Conjoining Jamo Behavior" */ - var LIndex = -1 + var LIndex: Int var VIndex = -1 var TIndex = -1 @@ -139,7 +139,7 @@ internal class HangulDecomposedCharSet( -1 } index++ - decompSyllable[SyllIndex++] = curSymb.toInt() + decompSyllable[@Suppress("UNUSED_CHANGED_VALUE")SyllIndex++] = curSymb.toInt() /* * We deal with LVT syllable at testString, so diff --git a/samples/androidNativeActivity/android.def b/samples/androidNativeActivity/android.def index d81fd536871..519f3eccc9a 100644 --- a/samples/androidNativeActivity/android.def +++ b/samples/androidNativeActivity/android.def @@ -1,6 +1,5 @@ +// TODO: androidLauncher.h will become part of the platform library. headers = stdio.h stdlib.h string.h math.h time.h android/log.h androidLauncher.h EGL/egl.h GLES/gl.h -excludeDependentModules.osx = true - --- static int interop_errno() { diff --git a/samples/androidNativeActivity/androidLauncher.h b/samples/androidNativeActivity/androidLauncher.h new file mode 100644 index 00000000000..d1a3cb359ff --- /dev/null +++ b/samples/androidNativeActivity/androidLauncher.h @@ -0,0 +1,85 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_LAUNCHER_H +#define ANDROID_LAUNCHER_H + +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct NativeActivityState { + struct ANativeActivity* activity; + void* savedState; + size_t savedStateSize; + struct ALooper* looper; +}; + +void getNativeActivityState(struct NativeActivityState* state); + +void notifySysEventProcessed(); + +#define LOOPER_ID_SYS 1 + +typedef enum NativeActivityEventKind { + UNKNOWN, + DESTROY, + START, + RESUME, + SAVE_INSTANCE_STATE, + PAUSE, + STOP, + CONFIGURATION_CHANGED, + LOW_MEMORY, + WINDOW_GAINED_FOCUS, + WINDOW_LOST_FOCUS, + NATIVE_WINDOW_CREATED, + NATIVE_WINDOW_DESTROYED, + INPUT_QUEUE_CREATED, + INPUT_QUEUE_DESTROYED +} NativeActivityEventKind; + +struct NativeActivityEvent { + NativeActivityEventKind eventKind; +}; + +struct NativeActivitySaveStateEvent { + NativeActivityEventKind eventKind; + void* savedState; + size_t savedStateSize; +}; + +struct NativeActivityWindowEvent { + NativeActivityEventKind eventKind; + struct ANativeWindow* window; +}; + +struct NativeActivityQueueEvent { + NativeActivityEventKind eventKind; + struct AInputQueue* queue; +}; + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_LAUNCHER_H \ No newline at end of file diff --git a/samples/androidNativeActivity/build.gradle b/samples/androidNativeActivity/build.gradle index d2ab9d65c28..4c1b9586f32 100644 --- a/samples/androidNativeActivity/build.gradle +++ b/samples/androidNativeActivity/build.gradle @@ -29,13 +29,15 @@ konanInterop { arm32 { defFile "android.def" pkg "android" - includeDirs "../../runtime/src/launcher/cpp" + // TODO: launcher header will be part of the platform library. + includeDirs "." target "android_arm32" } arm64 { defFile "android.def" pkg "android" - includeDirs "../../runtime/src/launcher/cpp" + // TODO: launcher header will be part of the platform library. + includeDirs "." target "android_arm64" } } @@ -125,4 +127,4 @@ task buildApk(type: DefaultTask) { dependsOn "compileKonanPolyhedronArm64" dependsOn "renameArtifacts" dependsOn "assembleDebug" -} \ No newline at end of file +}