Search in sources :

Example 6 with TranslationContext

use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.

the class ArrayAccessTranslator method translateAsMethodCall.

@NotNull
private JsExpression translateAsMethodCall(@NotNull JsExpression arrayExpression, @Nullable JsExpression toSetTo) {
    boolean isGetter = toSetTo == null;
    TranslationContext context = context();
    ResolvedCall<FunctionDescriptor> resolvedCall = BindingUtils.getResolvedCallForArrayAccess(bindingContext(), expression, isGetter);
    if (!isGetter) {
        context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
    }
    return CallTranslator.translate(context, resolvedCall, arrayExpression);
}
Also used : TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext) FunctionDescriptor(org.jetbrains.kotlin.descriptors.FunctionDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with TranslationContext

use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.

the class K2JSTranslator method translate.

@NotNull
public TranslationResult translate(@NotNull List<KtFile> files, @NotNull MainCallParameters mainCallParameters, @Nullable JsAnalysisResult analysisResult) throws TranslationException {
    if (analysisResult == null) {
        analysisResult = TopDownAnalyzerFacadeForJS.analyzeFiles(files, config);
        ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    }
    BindingTrace bindingTrace = analysisResult.getBindingTrace();
    TopDownAnalyzerFacadeForJS.checkForErrors(files, bindingTrace.getBindingContext());
    ModuleDescriptor moduleDescriptor = analysisResult.getModuleDescriptor();
    Diagnostics diagnostics = bindingTrace.getBindingContext().getDiagnostics();
    TranslationContext context = Translation.generateAst(bindingTrace, files, mainCallParameters, moduleDescriptor, config);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    if (hasError(diagnostics))
        return new TranslationResult.Fail(diagnostics);
    JsProgram program = JsInliner.process(context);
    ResolveTemporaryNamesKt.resolveTemporaryNames(program);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    if (hasError(diagnostics))
        return new TranslationResult.Fail(diagnostics);
    CoroutineTransformer coroutineTransformer = new CoroutineTransformer(program);
    coroutineTransformer.accept(program);
    RemoveUnusedImportsKt.removeUnusedImports(program);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    if (hasError(diagnostics))
        return new TranslationResult.Fail(diagnostics);
    expandIsCalls(program, context);
    ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
    List<String> importedModules = new ArrayList<String>();
    for (StaticContext.ImportedModule module : context.getImportedModules()) {
        importedModules.add(module.getExternalName());
    }
    return new TranslationResult.Success(config, files, program, diagnostics, importedModules, moduleDescriptor, bindingTrace.getBindingContext());
}
Also used : BindingTrace(org.jetbrains.kotlin.resolve.BindingTrace) Diagnostics(org.jetbrains.kotlin.resolve.diagnostics.Diagnostics) CoroutineTransformer(org.jetbrains.kotlin.js.coroutine.CoroutineTransformer) ArrayList(java.util.ArrayList) JsProgram(org.jetbrains.kotlin.js.backend.ast.JsProgram) ModuleDescriptor(org.jetbrains.kotlin.descriptors.ModuleDescriptor) TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext) StaticContext(org.jetbrains.kotlin.js.translate.context.StaticContext) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with TranslationContext

use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.

the class ExpressionVisitor method translateClassOrObject.

private static void translateClassOrObject(@NotNull KtClassOrObject declaration, @NotNull ClassDescriptor descriptor, @NotNull TranslationContext context) {
    JsScope scope = context.getScopeForDescriptor(descriptor);
    TranslationContext classContext = context.innerWithUsageTracker(scope, descriptor);
    ClassTranslator.translate(declaration, classContext);
}
Also used : TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext)

Example 9 with TranslationContext

use of org.jetbrains.kotlin.js.translate.context.TranslationContext in project kotlin by JetBrains.

the class AccessTranslationUtils method getArrayAccessTranslator.

@NotNull
private static AccessTranslator getArrayAccessTranslator(@NotNull KtArrayAccessExpression expression, @NotNull TranslationContext context, boolean forceOrderOfEvaluation) {
    TranslationContext accessArrayContext;
    if (forceOrderOfEvaluation) {
        Map<KtExpression, JsExpression> indexesMap = new LinkedHashMap<KtExpression, JsExpression>();
        for (KtExpression indexExpression : expression.getIndexExpressions()) {
            JsExpression jsIndexExpression = context.cacheExpressionIfNeeded(Translation.translateAsExpression(indexExpression, context));
            indexesMap.put(indexExpression, jsIndexExpression);
        }
        accessArrayContext = context.innerContextWithAliasesForExpressions(indexesMap);
    } else {
        accessArrayContext = context;
    }
    return ArrayAccessTranslator.newInstance(expression, accessArrayContext);
}
Also used : JsExpression(org.jetbrains.kotlin.js.backend.ast.JsExpression) TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext) LinkedHashMap(java.util.LinkedHashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TranslationContext (org.jetbrains.kotlin.js.translate.context.TranslationContext)9 NotNull (org.jetbrains.annotations.NotNull)8 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JsExpression (org.jetbrains.kotlin.js.backend.ast.JsExpression)2 StaticContext (org.jetbrains.kotlin.js.translate.context.StaticContext)2 LinkedHashMap (java.util.LinkedHashMap)1 FunctionDescriptor (org.jetbrains.kotlin.descriptors.FunctionDescriptor)1 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)1 JsBlock (org.jetbrains.kotlin.js.backend.ast.JsBlock)1 JsProgram (org.jetbrains.kotlin.js.backend.ast.JsProgram)1 CoroutineTransformer (org.jetbrains.kotlin.js.coroutine.CoroutineTransformer)1 InOperationTranslator (org.jetbrains.kotlin.js.translate.operation.InOperationTranslator)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 KtUnaryExpression (org.jetbrains.kotlin.psi.KtUnaryExpression)1 BindingTrace (org.jetbrains.kotlin.resolve.BindingTrace)1 Diagnostics (org.jetbrains.kotlin.resolve.diagnostics.Diagnostics)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1