Pseudocode: converted to Kotlin
This commit is contained in:
@@ -208,7 +208,7 @@ fun Pseudocode.getStartInstruction(traversalOrder: TraversalOrder): Instruction
|
||||
fun Pseudocode.getLastInstruction(traversalOrder: TraversalOrder): Instruction =
|
||||
if (traversalOrder == FORWARD) sinkInstruction else enterInstruction
|
||||
|
||||
fun Pseudocode.getInstructions(traversalOrder: TraversalOrder): MutableList<Instruction> =
|
||||
fun Pseudocode.getInstructions(traversalOrder: TraversalOrder): List<Instruction> =
|
||||
if (traversalOrder == FORWARD) instructions else reversedInstructions
|
||||
|
||||
fun Instruction.getNextInstructions(traversalOrder: TraversalOrder): Collection<Instruction> =
|
||||
|
||||
@@ -14,58 +14,41 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cfg.pseudocode;
|
||||
package org.jetbrains.kotlin.cfg.pseudocode
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
interface Pseudocode {
|
||||
val correspondingElement: KtElement
|
||||
|
||||
public interface Pseudocode {
|
||||
@NotNull
|
||||
KtElement getCorrespondingElement();
|
||||
val parent: Pseudocode?
|
||||
|
||||
@Nullable
|
||||
Pseudocode getParent();
|
||||
val localDeclarations: Set<LocalFunctionDeclarationInstruction>
|
||||
|
||||
@NotNull
|
||||
Set<LocalFunctionDeclarationInstruction> getLocalDeclarations();
|
||||
val instructions: List<Instruction>
|
||||
|
||||
@NotNull
|
||||
List<Instruction> getInstructions();
|
||||
val reversedInstructions: List<Instruction>
|
||||
|
||||
@NotNull
|
||||
List<Instruction> getReversedInstructions();
|
||||
val instructionsIncludingDeadCode: List<Instruction>
|
||||
|
||||
@NotNull
|
||||
List<Instruction> getInstructionsIncludingDeadCode();
|
||||
val exitInstruction: SubroutineExitInstruction
|
||||
|
||||
@NotNull
|
||||
SubroutineExitInstruction getExitInstruction();
|
||||
val sinkInstruction: SubroutineSinkInstruction
|
||||
|
||||
@NotNull
|
||||
SubroutineSinkInstruction getSinkInstruction();
|
||||
val enterInstruction: SubroutineEnterInstruction
|
||||
|
||||
@NotNull
|
||||
SubroutineEnterInstruction getEnterInstruction();
|
||||
fun getElementValue(element: KtElement?): PseudoValue?
|
||||
|
||||
@Nullable
|
||||
PseudoValue getElementValue(@Nullable KtElement element);
|
||||
fun getValueElements(value: PseudoValue?): List<KtElement>
|
||||
|
||||
@NotNull
|
||||
List<? extends KtElement> getValueElements(@Nullable PseudoValue value);
|
||||
fun getUsages(value: PseudoValue?): List<Instruction>
|
||||
|
||||
@NotNull
|
||||
List<? extends Instruction> getUsages(@Nullable PseudoValue value);
|
||||
fun isSideEffectFree(instruction: Instruction): Boolean
|
||||
|
||||
boolean isSideEffectFree(@NotNull Instruction instruction);
|
||||
|
||||
Pseudocode copy();
|
||||
fun copy(): Pseudocode
|
||||
}
|
||||
|
||||
@@ -278,15 +278,15 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends KtElement> getValueElements(@Nullable PseudoValue value) {
|
||||
List<? extends KtElement> result = elementsToValues.getKeysByValue(value);
|
||||
public List<KtElement> getValueElements(@Nullable PseudoValue value) {
|
||||
List<KtElement> result = elementsToValues.getKeysByValue(value);
|
||||
return result != null ? result : Collections.<KtElement>emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends Instruction> getUsages(@Nullable PseudoValue value) {
|
||||
List<? extends Instruction> result = valueUsages.get(value);
|
||||
public List<Instruction> getUsages(@Nullable PseudoValue value) {
|
||||
List<Instruction> result = valueUsages.get(value);
|
||||
return result != null ? result : Collections.<Instruction>emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ fun getExpectedTypePredicate(
|
||||
val returnElement = it.element
|
||||
val functionDescriptor = when(returnElement) {
|
||||
is KtReturnExpression -> returnElement.getTargetFunctionDescriptor(bindingContext)
|
||||
else -> bindingContext[DECLARATION_TO_DESCRIPTOR, pseudocode.getCorrespondingElement()]
|
||||
else -> bindingContext[DECLARATION_TO_DESCRIPTOR, pseudocode.correspondingElement]
|
||||
}
|
||||
addSubtypesOf((functionDescriptor as? CallableDescriptor)?.getReturnType())
|
||||
}
|
||||
@@ -278,7 +278,7 @@ fun Pseudocode.getElementValuesRecursively(element: KtElement): List<PseudoValue
|
||||
|
||||
fun Pseudocode.collectValues() {
|
||||
getElementValue(element)?.let { results.add(it) }
|
||||
for (localFunction in getLocalDeclarations()) {
|
||||
for (localFunction in localDeclarations) {
|
||||
localFunction.body.collectValues()
|
||||
}
|
||||
}
|
||||
@@ -303,8 +303,8 @@ fun KtElement.getContainingPseudocode(context: BindingContext): Pseudocode? {
|
||||
}
|
||||
|
||||
fun Pseudocode.getPseudocodeByElement(element: KtElement): Pseudocode? {
|
||||
if (getCorrespondingElement() == element) return this
|
||||
if (correspondingElement == element) return this
|
||||
|
||||
getLocalDeclarations().forEach { decl -> decl.body.getPseudocodeByElement(element)?.let { return it } }
|
||||
localDeclarations.forEach { decl -> decl.body.getPseudocodeByElement(element)?.let { return it } }
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user