public void leaveTemps() { FrameMap frameMap = codegen.getFrameMap(); List<ParameterInfo> infos = invocationParamBuilder.listAllParams(); for (ListIterator<? extends ParameterInfo> iterator = infos.listIterator(infos.size()); iterator.hasPrevious(); ) { ParameterInfo param = iterator.previous(); if (!param.isSkippedOrRemapped()) { frameMap.leaveTemp(param.type); } } }
@NotNull private static List<String> getAbsolutePaths(@NotNull File directory, @NotNull Module module) { List<String> result = Lists.newArrayList(); for (String sourceFile : module.getSourceFiles()) { File source = new File(sourceFile); if (!source.isAbsolute()) { source = new File(directory, sourceFile); } result.add(source.getAbsolutePath()); } return result; }
@Override public void putHiddenParams() { List<JvmMethodParameterSignature> valueParameters = jvmSignature.getValueParameters(); if (!isStaticMethod(functionDescriptor, context)) { invocationParamBuilder.addNextParameter(AsmTypes.OBJECT_TYPE, false, null); } for (JvmMethodParameterSignature param : valueParameters) { if (param.getKind() == JvmMethodParameterKind.VALUE) { break; } invocationParamBuilder.addNextParameter(param.getAsmType(), false, null); } List<ParameterInfo> infos = invocationParamBuilder.listNotCaptured(); putParameterOnStack(infos.toArray(new ParameterInfo[infos.size()])); }
@Nullable public static Class<?> compileScript( @NotNull CompilerConfiguration configuration, @NotNull KotlinPaths paths, @NotNull KotlinCoreEnvironment environment) { List<AnalyzerScriptParameter> scriptParameters = environment.getConfiguration().getList(JVMConfigurationKeys.SCRIPT_PARAMETERS); if (!scriptParameters.isEmpty()) { KotlinScriptDefinitionProvider.getInstance(environment.getProject()) .addScriptDefinition(new KotlinScriptDefinition(".kts", scriptParameters)); } GenerationState state = analyzeAndGenerate(environment); if (state == null) { return null; } GeneratedClassLoader classLoader; try { List<URL> classPaths = Lists.newArrayList(paths.getRuntimePath().toURI().toURL()); for (File file : JvmContentRootsKt.getJvmClasspathRoots(configuration)) { classPaths.add(file.toURI().toURL()); } //noinspection UnnecessaryFullyQualifiedName classLoader = new GeneratedClassLoader( state.getFactory(), new URLClassLoader(classPaths.toArray(new URL[classPaths.size()]), null)); FqName nameForScript = ScriptNameUtil.classNameForScript(environment.getSourceFiles().get(0).getScript()); return classLoader.loadClass(nameForScript.asString()); } catch (Exception e) { throw new RuntimeException("Failed to evaluate script: " + e, e); } }
@NotNull private static GenerationState generate( @NotNull KotlinCoreEnvironment environment, @NotNull AnalysisResult result, @NotNull List<KtFile> sourceFiles, @Nullable Module module, File outputDirectory, String moduleName) { CompilerConfiguration configuration = environment.getConfiguration(); IncrementalCompilationComponents incrementalCompilationComponents = configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS); Collection<FqName> packagesWithObsoleteParts; List<FqName> obsoleteMultifileClasses; TargetId targetId = null; if (module == null || incrementalCompilationComponents == null) { packagesWithObsoleteParts = Collections.emptySet(); obsoleteMultifileClasses = Collections.emptyList(); } else { targetId = TargetIdKt.TargetId(module); IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId); packagesWithObsoleteParts = new HashSet<FqName>(); for (String internalName : incrementalCache.getObsoletePackageParts()) { packagesWithObsoleteParts.add(JvmClassName.byInternalName(internalName).getPackageFqName()); } obsoleteMultifileClasses = new ArrayList<FqName>(); for (String obsoleteFacadeInternalName : incrementalCache.getObsoleteMultifileClasses()) { obsoleteMultifileClasses.add( JvmClassName.byInternalName(obsoleteFacadeInternalName) .getFqNameForClassNameWithoutDollars()); } } BindingTraceContext diagnosticHolder = new BindingTraceContext(); GenerationState generationState = new GenerationState( environment.getProject(), ClassBuilderFactories.BINARIES, result.getModuleDescriptor(), result.getBindingContext(), sourceFiles, configuration.get(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, false), configuration.get(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, false), GenerationState.GenerateClassFilter.GENERATE_ALL, configuration.get(JVMConfigurationKeys.DISABLE_INLINE, false), configuration.get(JVMConfigurationKeys.DISABLE_OPTIMIZATION, false), /* useTypeTableInSerializer = */ false, diagnosticHolder, packagesWithObsoleteParts, obsoleteMultifileClasses, targetId, moduleName, outputDirectory, incrementalCompilationComponents); ProgressIndicatorAndCompilationCanceledStatus.checkCanceled(); long generationStart = PerformanceCounter.Companion.currentTime(); KotlinCodegenFacade.compileCorrectFiles( generationState, CompilationErrorHandler.THROW_EXCEPTION); long generationNanos = PerformanceCounter.Companion.currentTime() - generationStart; String desc = module != null ? "target " + module.getModuleName() + "-" + module.getModuleType() + " " : ""; String message = "GENERATE: " + sourceFiles.size() + " files (" + environment.countLinesOfCode(sourceFiles) + " lines) " + desc + "in " + TimeUnit.NANOSECONDS.toMillis(generationNanos) + " ms"; K2JVMCompiler.Companion.reportPerf(environment.getConfiguration(), message); ProgressIndicatorAndCompilationCanceledStatus.checkCanceled(); AnalyzerWithCompilerReport.reportDiagnostics( new FilteredJvmDiagnostics( diagnosticHolder.getBindingContext().getDiagnostics(), result.getBindingContext().getDiagnostics()), environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)); ProgressIndicatorAndCompilationCanceledStatus.checkCanceled(); return generationState; }