diff --git a/TeamCityBuild.xml b/TeamCityBuild.xml
index 1d48a1a3d3b..337877a8f23 100644
--- a/TeamCityBuild.xml
+++ b/TeamCityBuild.xml
@@ -94,12 +94,13 @@
-
-
+
-
+
+
+
diff --git a/build.xml b/build.xml
index 5ae5de6105d..7c6d6c4cf23 100644
--- a/build.xml
+++ b/build.xml
@@ -636,7 +636,9 @@
-
+
+
+
diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java
index 129348a6203..d941f9c1cc0 100644
--- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java
+++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/CommonCompilerArguments.java
@@ -18,22 +18,30 @@ package org.jetbrains.jet.cli.common.arguments;
import com.intellij.util.SmartList;
import com.sampullara.cli.Argument;
+import org.jetbrains.annotations.NotNull;
import java.util.List;
+
import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS;
public abstract class CommonCompilerArguments {
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
public boolean tags;
+
@Argument(value = "verbose", description = "Enable verbose logging output")
public boolean verbose;
+
@Argument(value = "version", description = "Display compiler version")
public boolean version;
- @Argument(value = "help", alias = "h", description = "Show help")
+
+ @Argument(value = "help", alias = "h", description = "Print a synopsis of standard options")
public boolean help;
- @Argument(value = "suppress", description = "Suppress compiler messages by severity (" + SUPPRESS_WARNINGS + ")")
+
+ @Argument(value = "suppress", description = "Suppress all compiler warnings")
+ @ValueDescription(SUPPRESS_WARNINGS)
public String suppress;
- @Argument(value = "printArgs", description = "Print commandline arguments")
+
+ @Argument(value = "printArgs", description = "Print command line arguments")
public boolean printArgs;
public List freeArgs = new SmartList();
@@ -42,6 +50,11 @@ public abstract class CommonCompilerArguments {
return SUPPRESS_WARNINGS.equalsIgnoreCase(suppress);
}
+ @NotNull
+ public String executableScriptFileName() {
+ return "kotlinc";
+ }
+
// Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments {}
}
diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java
index bcf0c91fbbf..f7a01cecdbd 100644
--- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java
+++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JSCompilerArguments.java
@@ -17,6 +17,7 @@
package org.jetbrains.jet.cli.common.arguments;
import com.sampullara.cli.Argument;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants.CALL;
@@ -27,28 +28,40 @@ import static org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants.NO_CA
*/
public class K2JSCompilerArguments extends CommonCompilerArguments {
@Argument(value = "output", description = "Output file path")
+ @ValueDescription("")
public String outputFile;
- @Argument(value = "libraryFiles", description = "Path to zipped lib sources or kotlin files")
+ @Argument(value = "libraryFiles", description = "Path to zipped library sources or kotlin files separated by commas")
+ @ValueDescription("")
public String[] libraryFiles;
- @Argument(value = "sourceFiles", description = "Source files (dir or file)")
+ @Argument(value = "sourceFiles", description = "Source files or directories separated by commas")
+ @ValueDescription("")
public String[] sourceFiles;
@Argument(value = "sourcemap", description = "Generate SourceMap")
public boolean sourcemap;
- @Argument(value = "target", description = "Generate js files for specific ECMA version (now support only ECMA 5)")
+ @Argument(value = "target", description = "Generate JS files for specific ECMA version (only ECMA 5 is supported)")
+ @ValueDescription("")
public String target;
@Nullable
- @Argument(value = "main", description = "Whether a main function should be called; either '" + CALL +
- "' or '" + NO_CALL + "', default '" + CALL + "' (main function will be auto detected)")
+ @Argument(value = "main", description = "Whether a main function should be called; default '" + CALL + "' (main function will be auto detected)")
+ @ValueDescription("{" + CALL + "," + NO_CALL + "}")
public String main;
- @Argument(value = "outputPrefix", description = "Path to file which will be added to the begin of output file")
+ @Argument(value = "outputPrefix", description = "Path to file which will be added to the beginning of output file")
+ @ValueDescription("")
public String outputPrefix;
@Argument(value = "outputPostfix", description = "Path to file which will be added to the end of output file")
+ @ValueDescription("")
public String outputPostfix;
+
+ @Override
+ @NotNull
+ public String executableScriptFileName() {
+ return "kotlinc-js";
+ }
}
diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java
index 6366490a492..6b2d162d64b 100644
--- a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java
+++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/K2JVMCompilerArguments.java
@@ -15,57 +15,73 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.jetbrains.jet.cli.common.arguments;
import com.sampullara.cli.Argument;
+import org.jetbrains.annotations.NotNull;
/**
- * Command line arguments for the {@link K2JVMCompiler}
+ * Command line arguments for K2JVMCompiler
*/
@SuppressWarnings("UnusedDeclaration")
public class K2JVMCompilerArguments extends CommonCompilerArguments {
- @Argument(value = "jar", description = "jar file name")
- public String jar;
-
- @Argument(value = "src", description = "source file or directory (allows many paths separated by the system path separator)")
+ @Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)")
+ @ValueDescription("")
public String src;
- @Argument(value = "classpath", description = "classpath to use when compiling")
- public String classpath;
+ @Argument(value = "jar", description = "Resulting .jar file path")
+ @ValueDescription("")
+ public String jar;
- @Argument(value = "annotations", description = "paths to external annotations")
- public String annotations;
-
- @Argument(value = "includeRuntime", description = "include Kotlin runtime in to resulting jar")
- public boolean includeRuntime;
-
- @Argument(value = "noJdk", description = "don't include Java runtime into classpath")
- public boolean noJdk;
-
- @Argument(value = "noStdlib", description = "don't include Kotlin runtime into classpath")
- public boolean noStdlib;
-
- @Argument(value = "noJdkAnnotations", description = "don't include JDK external annotations into classpath")
- public boolean noJdkAnnotations;
-
- @Argument(value = "notNullAssertions", description = "generate not-null assertion after each invocation of method returning not-null")
- public boolean notNullAssertions;
-
- @Argument(value = "notNullParamAssertions", description = "generate not-null assertions on parameters of methods accessible from Java")
- public boolean notNullParamAssertions;
-
- @Argument(value = "output", description = "output directory")
+ @Argument(value = "output", description = "Output directory path for .class files")
+ @ValueDescription("")
public String outputDir;
- @Argument(value = "module", description = "module to compile")
+ @Argument(value = "classpath", description = "Paths where to find user class files")
+ @ValueDescription("")
+ public String classpath;
+
+ @Argument(value = "annotations", description = "Paths to external annotations")
+ @ValueDescription("")
+ public String annotations;
+
+ @Argument(value = "includeRuntime", description = "Include Kotlin runtime in to resulting .jar")
+ public boolean includeRuntime;
+
+ @Argument(value = "noJdk", description = "Don't include Java runtime into classpath")
+ public boolean noJdk;
+
+ @Argument(value = "noStdlib", description = "Don't include Kotlin runtime into classpath")
+ public boolean noStdlib;
+
+ @Argument(value = "noJdkAnnotations", description = "Don't include JDK external annotations into classpath")
+ public boolean noJdkAnnotations;
+
+ @Argument(value = "notNullAssertions", description = "Generate not-null assertion after each invocation of method returning not-null")
+ public boolean notNullAssertions;
+
+ @Argument(value = "notNullParamAssertions", description = "Generate not-null assertions on parameters of methods accessible from Java")
+ public boolean notNullParamAssertions;
+
+ @Argument(value = "module", description = "Path to the module file to compile")
+ @ValueDescription("")
public String module;
- @Argument(value = "script", description = "evaluate script")
+ @Argument(value = "script", description = "Evaluate the script file")
public boolean script;
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
+ @ValueDescription("")
public String kotlinHome;
- @Argument(value = "inline", description = "Inlining mode: on/off or true/false (default is on)")
+ @Argument(value = "inline", description = "Inlining mode (default is on)")
+ @ValueDescription("{on,off}")
public String inline;
+
+ @Override
+ @NotNull
+ public String executableScriptFileName() {
+ return "kotlinc-jvm";
+ }
}
diff --git a/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/ValueDescription.java b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/ValueDescription.java
new file mode 100644
index 00000000000..f0e6480129d
--- /dev/null
+++ b/compiler/cli/cli-common/src/org/jetbrains/jet/cli/common/arguments/ValueDescription.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010-2014 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.
+ */
+
+package org.jetbrains.jet.cli.common.arguments;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ValueDescription {
+ @NotNull
+ String value();
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java
index c1ed663dc05..c1ffd14788a 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java
@@ -85,20 +85,7 @@ public abstract class CLICompiler {
* Allow derived classes to add additional command line arguments
*/
protected void usage(@NotNull PrintStream target) {
- // We should say something like
- // Args.usage(target, K2JVMCompilerArguments.class);
- // but currently cli-parser we are using does not support that
- // a corresponding patch has been sent to the authors
- // For now, we are using this:
- PrintStream oldErr = System.err;
- System.setErr(target);
- try {
- // TODO: use proper argv0
- Args.usage(createArguments());
- }
- finally {
- System.setErr(oldErr);
- }
+ Usage.print(target, createArguments());
}
/**
@@ -200,7 +187,7 @@ public abstract class CLICompiler {
String argumentsAsString = StringUtil.join(argumentsAsList, " ");
String printArgsMessage = messageRenderer.render(CompilerMessageSeverity.INFO,
- "Invoking compiler " + getClass().getName() +
+ "Invoking " + getClass().getSimpleName() +
" with arguments " + argumentsAsString + freeArgs,
CompilerMessageLocation.NO_LOCATION);
errStream.println(printArgsMessage);
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/Usage.java b/compiler/cli/src/org/jetbrains/jet/cli/common/Usage.java
new file mode 100644
index 00000000000..d6d53997bce
--- /dev/null
+++ b/compiler/cli/src/org/jetbrains/jet/cli/common/Usage.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2010-2014 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.
+ */
+
+package org.jetbrains.jet.cli.common;
+
+import com.sampullara.cli.Argument;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
+import org.jetbrains.jet.cli.common.arguments.ValueDescription;
+
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+
+class Usage {
+ // The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
+ private static final int OPTION_NAME_PADDING_WIDTH = 29;
+
+ public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments) {
+ target.println("Usage: " + arguments.executableScriptFileName() + " ");
+ target.println("where possible options include:");
+ for (Class> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
+ for (Field field : clazz.getDeclaredFields()) {
+ String usage = fieldUsage(field);
+ if (usage != null) {
+ target.println(usage);
+ }
+ }
+ }
+ }
+
+ @Nullable
+ private static String fieldUsage(@NotNull Field field) {
+ Argument argument = field.getAnnotation(Argument.class);
+ if (argument == null) return null;
+ ValueDescription description = field.getAnnotation(ValueDescription.class);
+
+ String prefix = argument.prefix();
+
+ StringBuilder sb = new StringBuilder(" ");
+ sb.append(prefix);
+ if (argument.value().isEmpty()) {
+ sb.append(field.getName());
+ }
+ else {
+ sb.append(argument.value());
+ }
+ if (!argument.alias().isEmpty()) {
+ sb.append(" (");
+ sb.append(prefix);
+ sb.append(argument.alias());
+ sb.append(")");
+ }
+ if (description != null) {
+ sb.append(" ");
+ sb.append(description.value());
+ }
+ while (sb.length() < OPTION_NAME_PADDING_WIDTH) {
+ sb.append(" ");
+ }
+ sb.append(argument.description());
+ return sb.toString();
+ }
+}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java
index 67a98a0b7a4..0faf2ed84e6 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentUtil.java
@@ -278,11 +278,8 @@ public class CompileEnvironmentUtil {
if (jar != null) {
writeToJar(jar, includeRuntime, mainClass, outputFiles);
}
- else if (outputDir != null) {
- OutputUtilsPackage.writeAll(outputFiles, outputDir, messageCollector);
- }
else {
- throw new CompileEnvironmentException("Output directory or jar file is not specified - no files will be saved to the disk");
+ OutputUtilsPackage.writeAll(outputFiles, outputDir == null ? new File(".") : outputDir, messageCollector);
}
}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java
index 1053bd84883..fa78cac7e1d 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java
@@ -22,6 +22,7 @@ import com.google.common.collect.Maps;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.PsiFile;
+import com.intellij.util.ArrayUtil;
import kotlin.Function0;
import kotlin.Function1;
import kotlin.Unit;
@@ -91,12 +92,12 @@ public class KotlinToJVMBytecodeCompiler {
}
private static void writeOutput(
- CompilerConfiguration configuration,
- ClassFileFactory outputFiles,
- File outputDir,
- File jarPath,
+ @NotNull CompilerConfiguration configuration,
+ @NotNull ClassFileFactory outputFiles,
+ @Nullable File outputDir,
+ @Nullable File jarPath,
boolean jarRuntime,
- FqName mainClass
+ @Nullable FqName mainClass
) {
MessageCollector messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE);
CompileEnvironmentUtil.writeOutputToDirOrJar(jarPath, outputDir, jarRuntime, mainClass, outputFiles, messageCollector);
@@ -192,7 +193,7 @@ public class KotlinToJVMBytecodeCompiler {
}
public static boolean compileBunchOfSources(
- JetCoreEnvironment environment,
+ @NotNull JetCoreEnvironment environment,
@Nullable File jar,
@Nullable File outputDir,
boolean includeRuntime
@@ -223,7 +224,7 @@ public class KotlinToJVMBytecodeCompiler {
if (scriptClass == null) return;
try {
- scriptClass.getConstructor(String[].class).newInstance(new Object[]{scriptArgs.toArray(new String[scriptArgs.size()])});
+ scriptClass.getConstructor(String[].class).newInstance(new Object[] {ArrayUtil.toStringArray(scriptArgs)});
}
catch (RuntimeException e) {
throw e;
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java
index 5abdb9058f1..bdc9a8ed052 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java
@@ -295,7 +295,7 @@ public class JetControlFlowProcessor {
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
generateCall(expression, variableAsFunctionResolvedCall.getVariableCall());
}
- else if (!generateCall(expression, true) && !(expression.getParent() instanceof JetCallExpression)) {
+ else if (!generateCall(expression) && !(expression.getParent() instanceof JetCallExpression)) {
createNonSyntheticValue(expression, generateAndGetReceiverIfAny(expression));
}
}
@@ -353,7 +353,7 @@ public class JetControlFlowProcessor {
mergeValues(Arrays.asList(left, right), expression);
}
else {
- if (!generateCall(operationReference, true)) {
+ if (!generateCall(operationReference)) {
generateBothArgumentsAndMark(expression);
}
}
@@ -535,7 +535,7 @@ public class JetControlFlowProcessor {
private void generateArrayAccess(JetArrayAccessExpression arrayAccessExpression, @Nullable ResolvedCall> resolvedCall) {
mark(arrayAccessExpression);
- if (!checkAndGenerateCall(arrayAccessExpression, resolvedCall, true)) {
+ if (!checkAndGenerateCall(arrayAccessExpression, resolvedCall)) {
generateArrayAccessWithoutCall(arrayAccessExpression);
}
}
@@ -1070,7 +1070,7 @@ public class JetControlFlowProcessor {
@Override
public void visitCallExpression(@NotNull JetCallExpression expression) {
JetExpression calleeExpression = expression.getCalleeExpression();
- if (!generateCall(calleeExpression, true)) {
+ if (!generateCall(calleeExpression)) {
List inputExpressions = new ArrayList();
for (ValueArgument argument : expression.getValueArguments()) {
JetExpression argumentExpression = argument.getArgumentExpression();
@@ -1197,7 +1197,7 @@ public class JetControlFlowProcessor {
public void visitArrayAccessExpression(@NotNull JetArrayAccessExpression expression) {
mark(expression);
ResolvedCall getMethodResolvedCall = trace.get(BindingContext.INDEXED_LVALUE_GET, expression);
- if (!checkAndGenerateCall(expression, getMethodResolvedCall, true)) {
+ if (!checkAndGenerateCall(expression, getMethodResolvedCall)) {
generateArrayAccess(expression, getMethodResolvedCall);
}
}
@@ -1378,12 +1378,15 @@ public class JetControlFlowProcessor {
return trace.get(BindingContext.RESOLVED_CALL, expression);
}
- private boolean generateCall(@Nullable JetExpression calleeExpression, boolean bindResultValue) {
+ private boolean generateCall(@Nullable JetExpression calleeExpression) {
if (calleeExpression == null) return false;
- return checkAndGenerateCall(calleeExpression, getResolvedCall(calleeExpression), bindResultValue);
+ return checkAndGenerateCall(calleeExpression, getResolvedCall(calleeExpression));
}
- private boolean checkAndGenerateCall(JetExpression calleeExpression, @Nullable ResolvedCall> resolvedCall, boolean bindResultValue) {
+ private boolean checkAndGenerateCall(
+ JetExpression calleeExpression,
+ @Nullable ResolvedCall> resolvedCall
+ ) {
if (resolvedCall == null) {
builder.compilationError(calleeExpression, "No resolved call");
return false;
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt
index 04b8eb99a64..da985950d5e 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt
@@ -41,13 +41,13 @@ public data class AllSubtypes(val upperBound: JetType): TypePredicate {
public data class ForAllTypes(val typeSets: List): TypePredicate {
override fun invoke(typeToCheck: JetType): Boolean = typeSets.all { it(typeToCheck) }
- override fun toString(): String = "AND{${typeSets.makeString(", ")}}"
+ override fun toString(): String = "AND{${typeSets.joinToString(", ")}}"
}
public data class ForSomeType(val typeSets: List): TypePredicate {
override fun invoke(typeToCheck: JetType): Boolean = typeSets.any { it(typeToCheck) }
- override fun toString(): String = "OR{${typeSets.makeString(", ")}}"
+ override fun toString(): String = "OR{${typeSets.joinToString(", ")}}"
}
public object AllTypes : TypePredicate {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/AccessValueInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/AccessValueInstruction.kt
deleted file mode 100644
index 4a23137e339..00000000000
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/AccessValueInstruction.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2010-2014 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.
- */
-
-package org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval
-
-import org.jetbrains.jet.lang.psi.JetElement
-import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
-import org.jetbrains.jet.lang.cfg.pseudocode.instructions.LexicalScope
-import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionWithNext
-import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
-import org.jetbrains.jet.lang.descriptors.VariableDescriptor
-import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
-import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind
-import java.util.Collections
-
-public trait AccessTarget {
- public data class Declaration(val descriptor: VariableDescriptor): AccessTarget
- public data class Call(val resolvedCall: ResolvedCall<*>): AccessTarget
- public object BlackBox: AccessTarget
-}
-
-public abstract class AccessValueInstruction protected (
- element: JetElement,
- lexicalScope: LexicalScope,
- public val target: AccessTarget,
- public override val receiverValues: Map
-) : InstructionWithNext(element, lexicalScope), InstructionWithReceivers
\ No newline at end of file
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt
deleted file mode 100644
index 43beda2653a..00000000000
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2010-2014 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.
- */
-
-package org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval
-
-import org.jetbrains.jet.lang.psi.JetElement
-import org.jetbrains.jet.lang.psi.JetNamedDeclaration
-import java.util.Collections
-import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
-import org.jetbrains.jet.lang.cfg.pseudocode.instructions.LexicalScope
-import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitor
-import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitorWithResult
-import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionImpl
-import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
-
-public class WriteValueInstruction(
- assignment: JetElement,
- lexicalScope: LexicalScope,
- target: AccessTarget,
- receiverValues: Map,
- public val lValue: JetElement,
- public val rValue: PseudoValue
-) : AccessValueInstruction(assignment, lexicalScope, target, receiverValues) {
- override val inputValues: List
- get() = receiverValues.keySet() + rValue
-
- override fun accept(visitor: InstructionVisitor) {
- visitor.visitWriteValue(this)
- }
-
- override fun accept(visitor: InstructionVisitorWithResult): R {
- return visitor.visitWriteValue(this)
- }
-
- override fun toString(): String {
- val lhs = (lValue as? JetNamedDeclaration)?.getName() ?: render(lValue)
- return "w($lhs|${inputValues.makeString(", ")})"
- }
-
- override fun createCopy(): InstructionImpl =
- WriteValueInstruction(element, lexicalScope, target, receiverValues, lValue, rValue)
-}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/accessInstructions.kt
similarity index 62%
rename from compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt
rename to compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/accessInstructions.kt
index 4cb533a4ce8..750faa6131d 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/accessInstructions.kt
@@ -17,13 +17,30 @@
package org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval
import org.jetbrains.jet.lang.psi.JetElement
-import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValueFactory
import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.LexicalScope
+import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionWithNext
+import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
+import org.jetbrains.jet.lang.descriptors.VariableDescriptor
+import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
+import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValueFactory
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitor
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitorWithResult
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionImpl
-import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
+import org.jetbrains.jet.lang.psi.JetNamedDeclaration
+
+public trait AccessTarget {
+ public data class Declaration(val descriptor: VariableDescriptor): AccessTarget
+ public data class Call(val resolvedCall: ResolvedCall<*>): AccessTarget
+ public object BlackBox: AccessTarget
+}
+
+public abstract class AccessValueInstruction protected (
+ element: JetElement,
+ lexicalScope: LexicalScope,
+ public val target: AccessTarget,
+ public override val receiverValues: Map
+) : InstructionWithNext(element, lexicalScope), InstructionWithReceivers
public class ReadValueInstruction private (
element: JetElement,
@@ -51,7 +68,7 @@ public class ReadValueInstruction private (
}
override fun toString(): String {
- val inVal = if (receiverValues.empty) "" else "|${receiverValues.keySet().makeString()}"
+ val inVal = if (receiverValues.empty) "" else "|${receiverValues.keySet().joinToString()}"
return "r(${render(element)}$inVal) -> $outputValue"
}
@@ -74,3 +91,31 @@ public class ReadValueInstruction private (
}
}
}
+
+public class WriteValueInstruction(
+ assignment: JetElement,
+ lexicalScope: LexicalScope,
+ target: AccessTarget,
+ receiverValues: Map,
+ public val lValue: JetElement,
+ public val rValue: PseudoValue
+) : AccessValueInstruction(assignment, lexicalScope, target, receiverValues) {
+ override val inputValues: List
+ get() = receiverValues.keySet() + rValue
+
+ override fun accept(visitor: InstructionVisitor) {
+ visitor.visitWriteValue(this)
+ }
+
+ override fun accept(visitor: InstructionVisitorWithResult): R {
+ return visitor.visitWriteValue(this)
+ }
+
+ override fun toString(): String {
+ val lhs = (lValue as? JetNamedDeclaration)?.getName() ?: render(lValue)
+ return "w($lhs|${inputValues.joinToString(", ")})"
+ }
+
+ override fun createCopy(): InstructionImpl =
+ WriteValueInstruction(element, lexicalScope, target, receiverValues, lValue, rValue)
+}
\ No newline at end of file
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt
index a53a8dad35b..b77374e9eb4 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt
@@ -40,7 +40,7 @@ public abstract class OperationInstruction protected(
protected fun renderInstruction(name: String, desc: String): String =
"$name($desc" +
- (if (inputValues.notEmpty) "|${inputValues.makeString(", ")})" else ")") +
+ (if (inputValues.notEmpty) "|${inputValues.joinToString(", ")})" else ")") +
(if (resultValue != null) " -> $resultValue" else "")
protected fun setResult(value: PseudoValue?): OperationInstruction {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/jumps/NondeterministicJumpInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/jumps/NondeterministicJumpInstruction.kt
index 0166c5b463a..6d66d843bd7 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/jumps/NondeterministicJumpInstruction.kt
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/jumps/NondeterministicJumpInstruction.kt
@@ -72,7 +72,7 @@ public class NondeterministicJumpInstruction(
override fun toString(): String {
val inVal = if (inputValue != null) "|$inputValue" else ""
- val labels = targetLabels.map { it.getName() }.makeString(", ")
+ val labels = targetLabels.map { it.getName() }.joinToString(", ")
return "jmp?($labels$inVal)"
}
diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightMethodForDeclaration.kt b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightMethodForDeclaration.kt
index 8e15f922e40..152147f86dd 100644
--- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightMethodForDeclaration.kt
+++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightMethodForDeclaration.kt
@@ -110,4 +110,9 @@ public class KotlinLightMethodForDeclaration(
}
override fun getUseScope(): SearchScope = origin.getUseScope()
+
+ override fun equals(other: Any?): Boolean =
+ other is KotlinLightMethodForDeclaration && getName() == other.getName() && origin == other.origin
+
+ override fun hashCode(): Int = getName().hashCode() * 31 + origin.hashCode()
}
diff --git a/compiler/testData/cfg-variables/basic/IfWithUninitialized.values b/compiler/testData/cfg-variables/basic/IfWithUninitialized.values
index 9e8d37ccb96..0e88483632f 100644
--- a/compiler/testData/cfg-variables/basic/IfWithUninitialized.values
+++ b/compiler/testData/cfg-variables/basic/IfWithUninitialized.values
@@ -9,18 +9,19 @@ fun foo() {
}
}
---------------------
-1 : {<: Comparable} NEW()
-2 : Int NEW()
-1 < 2 : Boolean NEW(, )
-b : {<: Any?} NEW()
-use(b) : * NEW()
-{ use(b) } : * COPY
-true : Boolean NEW()
-if (1 < 2) { use(b) } else { b = true } : * COPY
-{ val b: Boolean if (1 < 2) { use(b) } else { b = true } } : * COPY
+1 : {<: Comparable} NEW: r(1) ->
+2 : Int NEW: r(2) ->
+1 < 2 : Boolean NEW: call(<, compareTo|, ) ->
+b : {<: Any?} NEW: r(b) ->
+use(b) : * NEW: call(use, use|) ->
+{ use(b) } : * COPY
+true : Boolean NEW: r(true) ->
+if (1 < 2) { use(b) } else { b = true } : * COPY
+{ val b: Boolean if (1 < 2) { use(b) } else { b = true } } : * COPY
=====================
== use ==
fun use(vararg a: Any?) = a
---------------------
-a : {<: Array} NEW()
+ : {<: Array} NEW: magic(vararg a: Any?) ->
+a : {<: Array} NEW: r(a) ->
=====================
diff --git a/compiler/testData/cfg-variables/basic/InitializedNotDeclared.values b/compiler/testData/cfg-variables/basic/InitializedNotDeclared.values
index 6b99c7aaf59..f89bb34317c 100644
--- a/compiler/testData/cfg-variables/basic/InitializedNotDeclared.values
+++ b/compiler/testData/cfg-variables/basic/InitializedNotDeclared.values
@@ -6,5 +6,6 @@ class A {
val x: Int
}
---------------------
-1 : Int NEW()
+ : A NEW: magic(x) ->
+1 : Int NEW: r(1) ->
=====================
diff --git a/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values b/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values
index 4c2009adf92..ef1e6a6e02e 100644
--- a/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values
+++ b/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values
@@ -7,8 +7,8 @@ fun foo() {
}
}
---------------------
-1 : Int NEW()
-{ (x: Int) -> val y = x + a use(a) } : {<: (Int) -> Array} NEW()
+1 : Int NEW: r(1) ->
+{ (x: Int) -> val y = x + a use(a) } : {<: (Int) -> Array} NEW: r({ (x: Int) -> val y = x + a use(a) }) ->
=====================
== anonymous_0 ==
{ (x: Int) ->
@@ -16,15 +16,17 @@ fun foo() {
use(a)
}
---------------------
-x : Int NEW()
-a : Int NEW()
-x + a : Int NEW(, )
-a : {<: Any?} NEW()
-use(a) : {<: Array} NEW()
-val y = x + a use(a) : {<: Array} COPY
+ : Int NEW: magic(x: Int) ->
+x : Int NEW: r(x) ->
+a : Int NEW: r(a) ->
+x + a : Int NEW: call(+, plus|, ) ->
+a : {<: Any?} NEW: r(a) ->
+use(a) : {<: Array} NEW: call(use, use|) ->
+val y = x + a use(a) : {<: Array} COPY
=====================
== use ==
fun use(vararg a: Any?) = a
---------------------
-a : {<: Array} NEW()
+ : {<: Array} NEW: magic(vararg a: Any?) ->
+a : {<: Array} NEW: r(a) ->
=====================
diff --git a/compiler/testData/cfg-variables/basic/VariablesInitialization.values b/compiler/testData/cfg-variables/basic/VariablesInitialization.values
index 99f30cf9766..1e348df8e2c 100644
--- a/compiler/testData/cfg-variables/basic/VariablesInitialization.values
+++ b/compiler/testData/cfg-variables/basic/VariablesInitialization.values
@@ -6,10 +6,10 @@ fun foo() {
42
}
---------------------
-1 : Int NEW()
-2 : Int NEW()
-42 : * NEW()
-{ val a = 1 val b: Int b = 2 42 } : * COPY
+1 : Int NEW: r(1) ->
+2 : Int NEW: r(2) ->
+42 : * NEW: r(42) ->
+{ val a = 1 val b: Int b = 2 42 } : * COPY
=====================
== bar ==
fun bar(foo: Foo) {
@@ -18,13 +18,14 @@ fun bar(foo: Foo) {
42
}
---------------------
-foo : {<: Foo} NEW()
-c : * NEW()
-foo.c : * COPY
-foo : {<: Foo} NEW()
-2 : Int NEW()
-42 : * NEW()
-{ foo.c foo.c = 2 42 } : * COPY
+ : {<: Foo} NEW: magic(foo: Foo) ->
+foo : {<: Foo} NEW: r(foo) ->
+c : * NEW: r(c|) ->
+foo.c : * COPY
+foo : {<: Foo} NEW: r(foo) ->
+2 : Int NEW: r(2) ->
+42 : * NEW: r(42) ->
+{ foo.c foo.c = 2 42 } : * COPY
=====================
== Foo ==
trait Foo {
diff --git a/compiler/testData/cfg-variables/basic/VariablesUsage.values b/compiler/testData/cfg-variables/basic/VariablesUsage.values
index 99496514298..92570f6a36e 100644
--- a/compiler/testData/cfg-variables/basic/VariablesUsage.values
+++ b/compiler/testData/cfg-variables/basic/VariablesUsage.values
@@ -6,13 +6,13 @@ fun foo() {
use(a)
}
---------------------
-1 : Int NEW()
-a : Int NEW()
-use(a) : * NEW()
-2 : Int NEW()
-a : Int NEW()
-use(a) : * NEW()
-{ var a = 1 use(a) a = 2 use(a) } : * COPY
+1 : Int NEW: r(1) ->
+a : Int NEW: r(a) ->
+use(a) : * NEW: call(use, use|) ->
+2 : Int NEW: r(2) ->
+a : Int NEW: r(a) ->
+use(a) : * NEW: call(use, use|) ->
+{ var a = 1 use(a) a = 2 use(a) } : * COPY
=====================
== bar ==
fun bar() {
@@ -20,10 +20,11 @@ fun bar() {
b = 3
}
---------------------
-3 : Int NEW()
+3 : Int NEW: r(3) ->
=====================
== use ==
fun use(a: Int) = a
---------------------
-a : Int NEW()
+ : Int NEW: magic(a: Int) ->
+a : Int NEW: r(a) ->
=====================
diff --git a/compiler/testData/cfg-variables/bugs/referenceToPropertyInitializer.values b/compiler/testData/cfg-variables/bugs/referenceToPropertyInitializer.values
index 2c25e090ff8..c877aa87b51 100644
--- a/compiler/testData/cfg-variables/bugs/referenceToPropertyInitializer.values
+++ b/compiler/testData/cfg-variables/bugs/referenceToPropertyInitializer.values
@@ -5,25 +5,28 @@ class TestFunctionLiteral {
}
}
---------------------
-{ (x: Int) -> sum(x - 1) + x } : {<: (Int) -> Int} NEW()
+{ (x: Int) -> sum(x - 1) + x } : {<: (Int) -> Int} NEW: r({ (x: Int) -> sum(x - 1) + x }) ->
=====================
== anonymous_0 ==
{ (x: Int) ->
sum(x - 1) + x
}
---------------------
-sum : {<: (Int) -> Int} NEW()
-x : Int NEW()
-1 : Int NEW()
-x - 1 : Int NEW(, )
-sum(x - 1) : Int NEW(, )
-x : Int NEW()
-sum(x - 1) + x : Int NEW(, )
-sum(x - 1) + x : Int COPY
+ : Int NEW: magic(x: Int) ->
+ : TestFunctionLiteral NEW: magic(sum) ->
+sum : {<: (Int) -> Int} NEW: r(sum|) ->
+x : Int NEW: r(x) ->
+1 : Int NEW: r(1) ->
+x - 1 : Int NEW: call(-, minus|, ) ->
+sum(x - 1) : Int NEW: call(sum, invoke|, ) ->
+x : Int NEW: r(x) ->
+sum(x - 1) + x : Int NEW: call(+, plus|, ) ->
+sum(x - 1) + x : Int COPY
=====================
== A ==
open class A(val a: A)
---------------------
+ : {<: A} NEW: magic(val a: A) ->
=====================
== TestObjectLiteral ==
class TestObjectLiteral {
@@ -37,23 +40,27 @@ class TestObjectLiteral {
}
}
---------------------
-obj : * NEW()
-obj : {<: A} NEW()
-object: A(obj) { { val x = obj } fun foo() { val y = obj } } : {<: A} NEW()
+ : TestObjectLiteral NEW: magic(obj) ->
+ : TestObjectLiteral NEW: magic(obj) ->
+obj : * NEW: r(obj|) ->
+obj : {<: A} NEW: r(obj|) ->
+object: A(obj) { { val x = obj } fun foo() { val y = obj } } : {<: A} NEW: r(object: A(obj) { { val x = obj } fun foo() { val y = obj } }) ->
=====================
== foo ==
fun foo() {
val y = obj
}
---------------------
-obj : {<: A} NEW()
+