chore: use CompositeBlock instead of GlobalBlock.
This commit is contained in:
@@ -97,7 +97,7 @@ private fun mergeStdlibParts(outputFile: File, wrapperFile: File, baseDir: File,
|
||||
}
|
||||
|
||||
private fun List<JsStatement>.createInsertionPlace(): JsBlock {
|
||||
val block = JsGlobalBlock()
|
||||
val block = JsCompositeBlock()
|
||||
|
||||
val visitor = object : JsVisitorWithContextImpl() {
|
||||
override fun visit(x: JsExpressionStatement, ctx: JsContext<in JsStatement>): Boolean {
|
||||
|
||||
@@ -172,8 +172,8 @@ class IrToJs(
|
||||
it.accept(IrFileToJsTransformer(), staticContext).statements
|
||||
}
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
processClassModels(staticContext.classModels, preDeclarationBlock, postDeclarationBlock)
|
||||
|
||||
val statements = mutableListOf<JsStatement>()
|
||||
@@ -421,7 +421,7 @@ private val IrModuleFragment.jsModuleName: String
|
||||
get() = name.asString().dropWhile { it == '<' }.dropLastWhile { it == '>' }
|
||||
|
||||
private fun List<JsStatement>.toJsCodeString(): String =
|
||||
JsGlobalBlock().also { it.statements += this }.toString()
|
||||
JsCompositeBlock().also { it.statements += this }.toString()
|
||||
|
||||
enum class JsGenerationGranularity {
|
||||
WHOLE_PROGRAM,
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ class IrDeclarationToJsTransformer : BaseIrElementToJsNodeTransformer<JsStatemen
|
||||
}
|
||||
|
||||
override fun visitScript(irScript: IrScript, context: JsGenerationContext): JsStatement {
|
||||
return JsGlobalBlock().apply {
|
||||
return JsCompositeBlock().apply {
|
||||
irScript.statements.forEach {
|
||||
statements +=
|
||||
if (it is IrDeclaration) it.accept(this@IrDeclarationToJsTransformer, context)
|
||||
|
||||
+1
-2
@@ -50,7 +50,7 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
|
||||
if (label != null) {
|
||||
JsLabel(label, JsBlock(wrappedStatements))
|
||||
} else {
|
||||
JsVirtualBlock(wrappedStatements)
|
||||
JsCompositeBlock(wrappedStatements)
|
||||
}
|
||||
} else {
|
||||
JsBlock(statements)
|
||||
@@ -67,7 +67,6 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
|
||||
}
|
||||
|
||||
override fun visitComposite(expression: IrComposite, context: JsGenerationContext): JsStatement {
|
||||
// TODO introduce JsCompositeBlock?
|
||||
return JsBlock(expression.statements.map { it.accept(this, context) })
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -8,9 +8,8 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.JsStaticContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsCompositeBlock
|
||||
|
||||
class IrFileToJsTransformer(private val useBareParameterNames: Boolean = false) : BaseIrElementToJsNodeTransformer<JsBlock, JsStaticContext> {
|
||||
override fun visitFile(declaration: IrFile, data: JsStaticContext): JsBlock {
|
||||
@@ -20,7 +19,7 @@ class IrFileToJsTransformer(private val useBareParameterNames: Boolean = false)
|
||||
staticContext = data,
|
||||
useBareParameterNames = useBareParameterNames
|
||||
)
|
||||
val block = JsGlobalBlock()
|
||||
val block = JsCompositeBlock()
|
||||
|
||||
declaration.declarations.forEach {
|
||||
block.statements.add(it.accept(IrDeclarationToJsTransformer(), fileContext))
|
||||
|
||||
+2
-2
@@ -293,8 +293,8 @@ class IrModuleToJsTransformer(
|
||||
private fun generateModuleBody(modules: Iterable<IrModuleFragment>, staticContext: JsStaticContext): List<JsStatement> {
|
||||
val statements = mutableListOf<JsStatement>()
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
|
||||
statements.addWithComment("block: pre-declaration", preDeclarationBlock)
|
||||
|
||||
|
||||
+5
-5
@@ -34,7 +34,7 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
|
||||
if (baseClass != null && !baseClass.isAny()) baseClass.getClassRef(context) else null
|
||||
}
|
||||
private val classPrototypeRef = prototypeOf(classNameRef)
|
||||
private val classBlock = JsGlobalBlock()
|
||||
private val classBlock = JsCompositeBlock()
|
||||
private val classModel = JsIrClassModel(irClass)
|
||||
|
||||
private val es6mode = context.staticContext.backendContext.es6mode
|
||||
@@ -434,11 +434,11 @@ private val IrClassifierSymbol.isEffectivelyExternal get() = (owner as? IrDeclar
|
||||
class JsIrClassModel(val klass: IrClass) {
|
||||
val superClasses = klass.superTypes.map { it.classifierOrFail as IrClassSymbol }
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
}
|
||||
|
||||
class JsIrIcClassModel(val superClasses: List<JsName>) {
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
}
|
||||
+4
-4
@@ -10,18 +10,18 @@ import org.jetbrains.kotlin.js.backend.ast.*
|
||||
|
||||
class JsIrProgramFragment(val packageFqn: String) {
|
||||
val nameBindings = mutableMapOf<String, JsName>()
|
||||
val declarations = JsGlobalBlock()
|
||||
val exports = JsGlobalBlock()
|
||||
val declarations = JsCompositeBlock()
|
||||
val exports = JsCompositeBlock()
|
||||
val importedModules = mutableListOf<JsImportedModule>()
|
||||
val imports = mutableMapOf<String, JsExpression>()
|
||||
var dts: String? = null
|
||||
val classes = mutableMapOf<JsName, JsIrIcClassModel>()
|
||||
val initializers = JsGlobalBlock()
|
||||
val initializers = JsCompositeBlock()
|
||||
var mainFunction: JsStatement? = null
|
||||
var testFunInvocation: JsStatement? = null
|
||||
var suiteFn: JsName? = null
|
||||
val definitions = mutableSetOf<String>()
|
||||
val polyfills = JsGlobalBlock()
|
||||
val polyfills = JsCompositeBlock()
|
||||
}
|
||||
|
||||
class JsIrModule(
|
||||
|
||||
+4
-4
@@ -161,14 +161,14 @@ class Merger(
|
||||
|
||||
val moduleBody = mutableListOf<JsStatement>()
|
||||
|
||||
val preDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val polyfillDeclarationBlock = JsGlobalBlock()
|
||||
val preDeclarationBlock = JsCompositeBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
val polyfillDeclarationBlock = JsCompositeBlock()
|
||||
|
||||
moduleBody.addWithComment("block: pre-declaration", preDeclarationBlock)
|
||||
|
||||
val classModels = mutableMapOf<JsName, JsIrIcClassModel>()
|
||||
val initializerBlock = JsGlobalBlock()
|
||||
val initializerBlock = JsCompositeBlock()
|
||||
|
||||
fragments.forEach {
|
||||
moduleBody += it.declarations.statements
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIntrinsicTransfo
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIrClassModel
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsCompositeBlock
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class JsStaticContext(
|
||||
val classModels = mutableMapOf<IrClassSymbol, JsIrClassModel>()
|
||||
val coroutineImplDeclaration = backendContext.ir.symbols.coroutineImpl.owner
|
||||
|
||||
val initializerBlock = JsGlobalBlock()
|
||||
val initializerBlock = JsCompositeBlock()
|
||||
|
||||
val genSourcemaps = backendContext.configuration.getBoolean(JSConfigurationKeys.SOURCE_MAP)
|
||||
}
|
||||
|
||||
+6
-6
@@ -51,16 +51,16 @@ class JsIrAstDeserializer : JsAstDeserializerBase() {
|
||||
}
|
||||
|
||||
if (proto.hasDeclarationBlock()) {
|
||||
fragment.declarations.statements += deserializeGlobalBlock(proto.declarationBlock).statements
|
||||
fragment.declarations.statements += deserializeCompositeBlock(proto.declarationBlock).statements
|
||||
}
|
||||
if (proto.hasInitializerBlock()) {
|
||||
fragment.initializers.statements += deserializeGlobalBlock(proto.initializerBlock).statements
|
||||
fragment.initializers.statements += deserializeCompositeBlock(proto.initializerBlock).statements
|
||||
}
|
||||
if (proto.hasExportBlock()) {
|
||||
fragment.exports.statements += deserializeGlobalBlock(proto.exportBlock).statements
|
||||
fragment.exports.statements += deserializeCompositeBlock(proto.exportBlock).statements
|
||||
}
|
||||
if (proto.hasPolyfills()) {
|
||||
fragment.polyfills.statements += deserializeGlobalBlock(proto.polyfills).statements
|
||||
fragment.polyfills.statements += deserializeCompositeBlock(proto.polyfills).statements
|
||||
}
|
||||
|
||||
proto.nameBindingList.associateTo(fragment.nameBindings) { nameBindingProto ->
|
||||
@@ -90,10 +90,10 @@ class JsIrAstDeserializer : JsAstDeserializerBase() {
|
||||
private fun deserialize(proto: IrClassModel): Pair<JsName, JsIrIcClassModel> {
|
||||
return deserializeName(proto.nameId) to JsIrIcClassModel(proto.superClassesList.map { deserializeName(it) }).apply {
|
||||
if (proto.hasPreDeclarationBlock()) {
|
||||
preDeclarationBlock.statements += deserializeGlobalBlock(proto.preDeclarationBlock).statements
|
||||
preDeclarationBlock.statements += deserializeCompositeBlock(proto.preDeclarationBlock).statements
|
||||
}
|
||||
if (proto.hasPostDeclarationBlock()) {
|
||||
postDeclarationBlock.statements += deserializeGlobalBlock(proto.postDeclarationBlock).statements
|
||||
postDeclarationBlock.statements += deserializeCompositeBlock(proto.postDeclarationBlock).statements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1275,14 +1275,15 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
||||
|
||||
sourceLocationConsumer.pushSourceInfo(null);
|
||||
|
||||
boolean needBraces = !x.isGlobalBlock() && !x.isVirtualBlock();
|
||||
boolean needBraces = !x.isTransparent();
|
||||
|
||||
if (needBraces) {
|
||||
blockOpen();
|
||||
}
|
||||
|
||||
Iterator<JsStatement> iterator = x.getStatements().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
boolean isGlobal = x.isGlobalBlock() || globalBlocks.contains(x);
|
||||
boolean isGlobal = x.isTransparent() || globalBlocks.contains(x);
|
||||
|
||||
JsStatement statement = iterator.next();
|
||||
if (statement instanceof JsEmpty) {
|
||||
|
||||
@@ -43,12 +43,10 @@ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement {
|
||||
return statements.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isGlobalBlock() {
|
||||
public boolean isTransparent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isVirtualBlock() { return false; }
|
||||
|
||||
@Override
|
||||
public void accept(JsVisitor v) {
|
||||
v.visitBlock(this);
|
||||
|
||||
@@ -18,5 +18,5 @@ package org.jetbrains.kotlin.js.backend.ast
|
||||
|
||||
class JsClassModel(val name: JsName, val superName: JsName?) {
|
||||
val interfaces: MutableSet<JsName> = mutableSetOf()
|
||||
val postDeclarationBlock = JsGlobalBlock()
|
||||
val postDeclarationBlock = JsCompositeBlock()
|
||||
}
|
||||
|
||||
+5
-5
@@ -7,15 +7,15 @@ import org.jetbrains.kotlin.js.util.AstUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a JavaScript block in the global scope.
|
||||
* Represents a JavaScript block which could not be rendered into a material one.
|
||||
*/
|
||||
class JsVirtualBlock(statements: List<JsStatement> = emptyList()) : JsBlock(statements) {
|
||||
override fun isVirtualBlock(): Boolean {
|
||||
class JsCompositeBlock(statements: List<JsStatement> = mutableListOf()) : JsBlock(statements) {
|
||||
override fun isTransparent(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun deepCopy(): JsVirtualBlock {
|
||||
val globalBlockCopy = JsVirtualBlock()
|
||||
override fun deepCopy(): JsCompositeBlock {
|
||||
val globalBlockCopy = JsCompositeBlock()
|
||||
val statementscopy = AstUtil.deepCopy(statements);
|
||||
globalBlockCopy.statements.addAll(statementscopy);
|
||||
return globalBlockCopy.withMetadataFrom(this);
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
package org.jetbrains.kotlin.js.backend.ast;
|
||||
|
||||
import org.jetbrains.kotlin.js.util.AstUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a JavaScript block in the global scope.
|
||||
*/
|
||||
public class JsGlobalBlock extends JsBlock {
|
||||
@Override
|
||||
public boolean isGlobalBlock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsGlobalBlock deepCopy() {
|
||||
JsGlobalBlock globalBlockCopy = new JsGlobalBlock();
|
||||
List<JsStatement> statementscopy = AstUtil.deepCopy(getStatements());
|
||||
globalBlockCopy.getStatements().addAll(statementscopy);
|
||||
return globalBlockCopy.withMetadataFrom(this);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* A JavaScript program.
|
||||
*/
|
||||
public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
private final JsGlobalBlock globalBlock = new JsGlobalBlock();
|
||||
private final JsCompositeBlock globalBlock = new JsCompositeBlock();
|
||||
|
||||
private final JsRootScope rootScope;
|
||||
private final JsObjectScope topScope;
|
||||
@@ -20,7 +20,7 @@ public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
topScope = new JsObjectScope(rootScope, "Global");
|
||||
}
|
||||
|
||||
public JsGlobalBlock getGlobalBlock() {
|
||||
public JsCompositeBlock getGlobalBlock() {
|
||||
return globalBlock;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import java.util.*
|
||||
class JsProgramFragment(val scope: JsScope, val packageFqn: String) {
|
||||
val importedModules = mutableListOf<JsImportedModule>()
|
||||
val imports: MutableMap<String, JsExpression> = LinkedHashMap()
|
||||
val declarationBlock = JsGlobalBlock()
|
||||
val exportBlock = JsGlobalBlock()
|
||||
val initializerBlock = JsGlobalBlock()
|
||||
val declarationBlock = JsCompositeBlock()
|
||||
val exportBlock = JsCompositeBlock()
|
||||
val initializerBlock = JsCompositeBlock()
|
||||
val nameBindings = mutableListOf<JsNameBinding>()
|
||||
val classes: MutableMap<JsName, JsClassModel> = LinkedHashMap()
|
||||
val inlineModuleMap: MutableMap<String, JsExpression> = LinkedHashMap()
|
||||
var tests: JsStatement? = null
|
||||
var mainFunction: JsStatement? = null
|
||||
val inlinedLocalDeclarations = mutableMapOf<String, JsGlobalBlock>()
|
||||
val inlinedLocalDeclarations = mutableMapOf<String, JsCompositeBlock>()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.google.gwt.dev.js.rhino.CodePosition
|
||||
import com.google.gwt.dev.js.rhino.ErrorReporter
|
||||
import org.jetbrains.kotlin.js.backend.JsToStringGenerationVisitor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsCompositeBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNode
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsProgram
|
||||
import org.jetbrains.kotlin.js.dce.Context.Node
|
||||
@@ -78,7 +78,7 @@ class DeadCodeElimination(
|
||||
|
||||
var hasErrors = false
|
||||
val blocks = inputFiles.map { file ->
|
||||
val block = JsGlobalBlock()
|
||||
val block = JsCompositeBlock()
|
||||
val code = file.resource.reader().let { InputStreamReader(it, "UTF-8") }.use { it.readText() }
|
||||
val statements = parse(code, Reporter(file.resource.name, logConsumer), program.scope, file.resource.name) ?: run {
|
||||
hasErrors = true
|
||||
|
||||
@@ -177,7 +177,7 @@ class ImportIntoFragmentInliningScope private constructor(
|
||||
|
||||
override fun addInlinedDeclaration(tag: String?, declaration: JsStatement) {
|
||||
if (tag != null) {
|
||||
fragment.inlinedLocalDeclarations.computeIfAbsent(tag) { JsGlobalBlock() }.statements.add(declaration)
|
||||
fragment.inlinedLocalDeclarations.computeIfAbsent(tag) { JsCompositeBlock() }.statements.add(declaration)
|
||||
} else {
|
||||
additionalDeclarations.add(declaration)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ message Statement {
|
||||
ExpressionStatement expression = 26;
|
||||
Vars vars = 27;
|
||||
Block block = 28;
|
||||
GlobalBlock global_block = 29;
|
||||
CompositeBlock composite_block = 29;
|
||||
Label label = 30;
|
||||
If if_statement = 31;
|
||||
Switch switch_statement = 32;
|
||||
@@ -254,7 +254,6 @@ message Statement {
|
||||
Try try_statement = 37;
|
||||
Empty empty = 38;
|
||||
SingleLineComment single_line_comment = 39;
|
||||
VirtualBlock virtual_block = 40;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,11 +298,7 @@ message Block {
|
||||
repeated Statement statement = 1;
|
||||
}
|
||||
|
||||
message GlobalBlock {
|
||||
repeated Statement statement = 1;
|
||||
}
|
||||
|
||||
message VirtualBlock {
|
||||
message CompositeBlock {
|
||||
repeated Statement statement = 1;
|
||||
}
|
||||
|
||||
@@ -394,9 +389,9 @@ enum InlineStrategy {
|
||||
message Fragment {
|
||||
repeated ImportedModule imported_module = 1;
|
||||
repeated Import import_entry = 2;
|
||||
optional GlobalBlock declaration_block = 3;
|
||||
optional GlobalBlock export_block = 4;
|
||||
optional GlobalBlock initializer_block = 5;
|
||||
optional CompositeBlock declaration_block = 3;
|
||||
optional CompositeBlock export_block = 4;
|
||||
optional CompositeBlock initializer_block = 5;
|
||||
repeated NameBinding name_binding = 6;
|
||||
repeated ClassModel class_model = 7;
|
||||
repeated Expression module_expression = 8;
|
||||
@@ -409,12 +404,12 @@ message Fragment {
|
||||
optional string dts = 15;
|
||||
optional int32 suite_function = 16;
|
||||
repeated int32 definitions = 17;
|
||||
optional GlobalBlock polyfills = 18;
|
||||
optional CompositeBlock polyfills = 18;
|
||||
}
|
||||
|
||||
message InlinedLocalDeclarations {
|
||||
required int32 tag = 1;
|
||||
required GlobalBlock block = 2;
|
||||
required CompositeBlock block = 2;
|
||||
}
|
||||
|
||||
message ImportedModule {
|
||||
@@ -437,14 +432,14 @@ message ClassModel {
|
||||
required int32 name_id = 1;
|
||||
optional int32 super_name_id = 2;
|
||||
repeated int32 interface_name_id = 4;
|
||||
optional GlobalBlock post_declaration_block = 3;
|
||||
optional CompositeBlock post_declaration_block = 3;
|
||||
}
|
||||
|
||||
message IrClassModel {
|
||||
required int32 name_id = 1;
|
||||
repeated int32 super_classes = 2;
|
||||
optional GlobalBlock pre_declaration_block = 3;
|
||||
optional GlobalBlock post_declaration_block = 4;
|
||||
optional CompositeBlock pre_declaration_block = 3;
|
||||
optional CompositeBlock post_declaration_block = 4;
|
||||
}
|
||||
|
||||
message InlineModule {
|
||||
|
||||
+5
-10
@@ -19,17 +19,12 @@ package org.jetbrains.kotlin.serialization.js.ast
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsImportedModule
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.LocalAlias
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.SpecialFunction
|
||||
import org.jetbrains.kotlin.protobuf.CodedInputStream
|
||||
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.*
|
||||
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.Expression.ExpressionCase
|
||||
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.Statement.StatementCase
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import java.io.InputStreamReader
|
||||
import java.util.*
|
||||
|
||||
class JsAstDeserializer(program: JsProgram, private val sourceRoots: Iterable<File>) : JsAstDeserializerBase() {
|
||||
|
||||
@@ -68,13 +63,13 @@ class JsAstDeserializer(program: JsProgram, private val sourceRoots: Iterable<Fi
|
||||
}
|
||||
|
||||
if (proto.hasDeclarationBlock()) {
|
||||
fragment.declarationBlock.statements += deserializeGlobalBlock(proto.declarationBlock).statements
|
||||
fragment.declarationBlock.statements += deserializeCompositeBlock(proto.declarationBlock).statements
|
||||
}
|
||||
if (proto.hasInitializerBlock()) {
|
||||
fragment.initializerBlock.statements += deserializeGlobalBlock(proto.initializerBlock).statements
|
||||
fragment.initializerBlock.statements += deserializeCompositeBlock(proto.initializerBlock).statements
|
||||
}
|
||||
if (proto.hasExportBlock()) {
|
||||
fragment.exportBlock.statements += deserializeGlobalBlock(proto.exportBlock).statements
|
||||
fragment.exportBlock.statements += deserializeCompositeBlock(proto.exportBlock).statements
|
||||
}
|
||||
|
||||
fragment.nameBindings += proto.nameBindingList.map { nameBindingProto ->
|
||||
@@ -103,7 +98,7 @@ class JsAstDeserializer(program: JsProgram, private val sourceRoots: Iterable<Fi
|
||||
}
|
||||
|
||||
proto.inlinedLocalDeclarationsList.forEach {
|
||||
fragment.inlinedLocalDeclarations[deserializeString(it.tag)] = deserializeGlobalBlock(it.block)
|
||||
fragment.inlinedLocalDeclarations[deserializeString(it.tag)] = deserializeCompositeBlock(it.block)
|
||||
}
|
||||
|
||||
return fragment
|
||||
@@ -114,7 +109,7 @@ class JsAstDeserializer(program: JsProgram, private val sourceRoots: Iterable<Fi
|
||||
return JsClassModel(deserializeName(proto.nameId), superName).apply {
|
||||
proto.interfaceNameIdList.mapTo(interfaces) { deserializeName(it) }
|
||||
if (proto.hasPostDeclarationBlock()) {
|
||||
postDeclarationBlock.statements += deserializeGlobalBlock(proto.postDeclarationBlock).statements
|
||||
postDeclarationBlock.statements += deserializeCompositeBlock(proto.postDeclarationBlock).statements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -73,12 +73,8 @@ abstract class JsAstDeserializerBase {
|
||||
block
|
||||
}
|
||||
|
||||
JsAstProtoBuf.Statement.StatementCase.VIRTUAL_BLOCK -> {
|
||||
JsVirtualBlock(proto.virtualBlock.statementList.map { deserialize(it) })
|
||||
}
|
||||
|
||||
JsAstProtoBuf.Statement.StatementCase.GLOBAL_BLOCK -> {
|
||||
deserializeGlobalBlock(proto.globalBlock)
|
||||
JsAstProtoBuf.Statement.StatementCase.COMPOSITE_BLOCK -> {
|
||||
deserializeCompositeBlock(proto.compositeBlock)
|
||||
}
|
||||
|
||||
JsAstProtoBuf.Statement.StatementCase.LABEL -> {
|
||||
@@ -340,8 +336,9 @@ abstract class JsAstDeserializerBase {
|
||||
return vars
|
||||
}
|
||||
|
||||
protected fun deserializeGlobalBlock(proto: JsAstProtoBuf.GlobalBlock): JsGlobalBlock {
|
||||
return JsGlobalBlock().apply { statements += proto.statementList.map { deserialize(it) } }
|
||||
protected fun deserializeCompositeBlock(proto: JsAstProtoBuf.CompositeBlock): JsCompositeBlock {
|
||||
return JsCompositeBlock()
|
||||
.apply { statements += proto.statementList.map { deserialize(it) } }
|
||||
}
|
||||
|
||||
protected fun deserializeParameter(proto: JsAstProtoBuf.Parameter): JsParameter {
|
||||
|
||||
+289
-913
File diff suppressed because it is too large
Load Diff
+3
-11
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.serialization.js.ast
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
abstract class JsAstSerializerBase {
|
||||
@@ -68,14 +67,7 @@ abstract class JsAstSerializerBase {
|
||||
|
||||
override fun visitBlock(x: JsBlock) {
|
||||
when (x) {
|
||||
is JsGlobalBlock -> { builder.globalBlock = serializeBlock(x) }
|
||||
is JsVirtualBlock -> {
|
||||
val virtualBlockBuilder = JsAstProtoBuf.VirtualBlock.newBuilder()
|
||||
for (part in x.statements) {
|
||||
virtualBlockBuilder.addStatement(serialize(part))
|
||||
}
|
||||
builder.virtualBlock = virtualBlockBuilder.build()
|
||||
}
|
||||
is JsCompositeBlock -> { builder.compositeBlock = serializeBlock(x) }
|
||||
else -> {
|
||||
val blockBuilder = JsAstProtoBuf.Block.newBuilder()
|
||||
for (part in x.statements) {
|
||||
@@ -384,8 +376,8 @@ abstract class JsAstSerializerBase {
|
||||
return parameterBuilder.build()
|
||||
}
|
||||
|
||||
protected fun serializeBlock(block: JsGlobalBlock): JsAstProtoBuf.GlobalBlock {
|
||||
val blockBuilder = JsAstProtoBuf.GlobalBlock.newBuilder()
|
||||
protected fun serializeBlock(block: JsCompositeBlock): JsAstProtoBuf.CompositeBlock {
|
||||
val blockBuilder = JsAstProtoBuf.CompositeBlock.newBuilder()
|
||||
for (part in block.statements) {
|
||||
blockBuilder.addStatement(serialize(part))
|
||||
}
|
||||
|
||||
@@ -58,8 +58,10 @@ class NameResolutionTest {
|
||||
val expectedCode = FileUtil.loadFile(File(expectedName))
|
||||
|
||||
val parserScope = JsFunctionScope(JsRootScope(JsProgram()), "<js fun>")
|
||||
val originalAst = JsGlobalBlock().apply { statements += parse(originalCode, errorReporter, parserScope, originalName).orEmpty() }
|
||||
val expectedAst = JsGlobalBlock().apply { statements += parse(expectedCode, errorReporter, parserScope, expectedName).orEmpty() }
|
||||
val originalAst = JsCompositeBlock()
|
||||
.apply { statements += parse(originalCode, errorReporter, parserScope, originalName).orEmpty() }
|
||||
val expectedAst = JsCompositeBlock()
|
||||
.apply { statements += parse(expectedCode, errorReporter, parserScope, expectedName).orEmpty() }
|
||||
|
||||
originalAst.accept(object : RecursiveJsVisitor() {
|
||||
val cache = mutableMapOf<JsName, JsName>()
|
||||
|
||||
+4
-4
@@ -17,12 +17,12 @@
|
||||
package org.jetbrains.kotlin.js.translate.context
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsCompositeBlock
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsName
|
||||
|
||||
class InlineFunctionContext(val descriptor: CallableDescriptor) {
|
||||
val imports = mutableMapOf<String, JsName>()
|
||||
val importBlock = JsGlobalBlock()
|
||||
val prototypeBlock = JsGlobalBlock()
|
||||
val declarationsBlock = JsGlobalBlock()
|
||||
val importBlock = JsCompositeBlock()
|
||||
val prototypeBlock = JsCompositeBlock()
|
||||
val declarationsBlock = JsCompositeBlock()
|
||||
}
|
||||
@@ -43,12 +43,12 @@ class Merger(
|
||||
private val nameTable = mutableMapOf<String, JsName>()
|
||||
|
||||
private val importedModuleTable = mutableMapOf<JsImportedModuleKey, JsName>()
|
||||
private val importBlock = JsGlobalBlock()
|
||||
private val declarationBlock = JsGlobalBlock()
|
||||
private val initializerBlock = JsGlobalBlock()
|
||||
private val importBlock = JsCompositeBlock()
|
||||
private val declarationBlock = JsCompositeBlock()
|
||||
private val initializerBlock = JsCompositeBlock()
|
||||
private val testsMap = mutableMapOf<String, JsStatement>()
|
||||
private var mainFn: Pair<String, JsStatement>? = null
|
||||
private val exportBlock = JsGlobalBlock()
|
||||
private val exportBlock = JsCompositeBlock()
|
||||
private val declaredImports = mutableSetOf<String>()
|
||||
private val classes = mutableMapOf<JsName, JsClassModel>()
|
||||
private val importedModulesImpl = mutableListOf<JsImportedModule>()
|
||||
|
||||
Reference in New Issue
Block a user