JS: prepare all necessary abstractions for new pipeline
This commit is contained in:
@@ -731,11 +731,6 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
||||
p.print("<JsProgram>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitProgramFragment(@NotNull JsProgramFragment x) {
|
||||
p.print("<JsProgramFragment>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitRegExp(@NotNull JsRegExp x) {
|
||||
slash();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.js.backend.ast
|
||||
|
||||
class JsClassModel(val name: JsName, val superName: JsName?)
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.js.backend.ast
|
||||
|
||||
class JsImportedModule(val externalName: String, val internalName: JsName, val plainReference: JsExpression?) {
|
||||
val key = JsImportedModuleKey(externalName, plainReference?.toString())
|
||||
}
|
||||
|
||||
data class JsImportedModuleKey(val baseName: String, val plainName: String?)
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.kotlin.js.backend.ast
|
||||
|
||||
class JsNameBinding(val key: String, val name: JsName)
|
||||
@@ -17,8 +17,7 @@ import java.util.Map;
|
||||
* A JavaScript program.
|
||||
*/
|
||||
public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
|
||||
private JsProgramFragment[] fragments;
|
||||
private final JsGlobalBlock globalBlock = new JsGlobalBlock();
|
||||
|
||||
private final TDoubleObjectHashMap<JsDoubleLiteral> doubleLiteralMap = new TDoubleObjectHashMap<JsDoubleLiteral>();
|
||||
private final TIntObjectHashMap<JsIntLiteral> intLiteralMap = new TIntObjectHashMap<JsIntLiteral>();
|
||||
@@ -30,18 +29,10 @@ public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
public JsProgram() {
|
||||
rootScope = new JsRootScope(this);
|
||||
topScope = new JsObjectScope(rootScope, "Global");
|
||||
setFragmentCount(1);
|
||||
}
|
||||
|
||||
public JsBlock getFragmentBlock(int fragment) {
|
||||
if (fragment < 0 || fragment >= fragments.length) {
|
||||
throw new IllegalArgumentException("Invalid fragment: " + fragment);
|
||||
}
|
||||
return fragments[fragment].getGlobalBlock();
|
||||
}
|
||||
|
||||
public JsBlock getGlobalBlock() {
|
||||
return getFragmentBlock(0);
|
||||
public JsGlobalBlock getGlobalBlock() {
|
||||
return globalBlock;
|
||||
}
|
||||
|
||||
public JsNumberLiteral getNumberLiteral(double value) {
|
||||
@@ -94,13 +85,6 @@ public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
return literal;
|
||||
}
|
||||
|
||||
public void setFragmentCount(int fragments) {
|
||||
this.fragments = new JsProgramFragment[fragments];
|
||||
for (int i = 0; i < fragments; i++) {
|
||||
this.fragments[i] = new JsProgramFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JsVisitor v) {
|
||||
v.visitProgram(this);
|
||||
@@ -108,17 +92,13 @@ public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
|
||||
@Override
|
||||
public void acceptChildren(JsVisitor visitor) {
|
||||
for (JsProgramFragment fragment : fragments) {
|
||||
visitor.accept(fragment);
|
||||
}
|
||||
visitor.accept(globalBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traverse(JsVisitorWithContext v, JsContext ctx) {
|
||||
if (v.visit(this, ctx)) {
|
||||
for (JsProgramFragment fragment : fragments) {
|
||||
v.accept(fragment);
|
||||
}
|
||||
v.accept(globalBlock);
|
||||
}
|
||||
v.endVisit(this, ctx);
|
||||
}
|
||||
|
||||
@@ -6,41 +6,59 @@ package org.jetbrains.kotlin.js.backend.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* One independently loadable fragment of a {@link JsProgram}.
|
||||
*/
|
||||
public class JsProgramFragment extends SourceInfoAwareJsNode {
|
||||
private final JsGlobalBlock globalBlock;
|
||||
import java.util.*;
|
||||
|
||||
public JsProgramFragment() {
|
||||
globalBlock = new JsGlobalBlock();
|
||||
}
|
||||
public class JsProgramFragment {
|
||||
private final JsScope scope;
|
||||
private final List<JsImportedModule> importedModules = new ArrayList<JsImportedModule>();
|
||||
private final Map<String, JsExpression> imports = new LinkedHashMap<String, JsExpression>();
|
||||
private final JsGlobalBlock declarationBlock = new JsGlobalBlock();
|
||||
private final JsGlobalBlock exportBlock = new JsGlobalBlock();
|
||||
private final JsGlobalBlock initializerBlock = new JsGlobalBlock();
|
||||
private final List<JsNameBinding> nameBindings = new ArrayList<JsNameBinding>();
|
||||
private final Map<JsName, JsClassModel> classes = new LinkedHashMap<JsName, JsClassModel>();
|
||||
|
||||
public JsBlock getGlobalBlock() {
|
||||
return globalBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JsVisitor v) {
|
||||
v.visitProgramFragment(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptChildren(JsVisitor visitor) {
|
||||
visitor.accept(globalBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traverse(JsVisitorWithContext v, JsContext ctx) {
|
||||
if (v.visit(this, ctx)) {
|
||||
v.acceptStatement(globalBlock);
|
||||
}
|
||||
v.endVisit(this, ctx);
|
||||
public JsProgramFragment(@NotNull JsScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsProgramFragment deepCopy() {
|
||||
throw new UnsupportedOperationException();
|
||||
public JsScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JsImportedModule> getImportedModules() {
|
||||
return importedModules;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, JsExpression> getImports() {
|
||||
return imports;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsBlock getDeclarationBlock() {
|
||||
return declarationBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsGlobalBlock getExportBlock() {
|
||||
return exportBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsGlobalBlock getInitializerBlock() {
|
||||
return initializerBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JsNameBinding> getNameBindings() {
|
||||
return nameBindings;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<JsName, JsClassModel> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +120,6 @@ abstract class JsVisitor {
|
||||
open fun visitProgram(x: JsProgram): Unit =
|
||||
visitElement(x)
|
||||
|
||||
open fun visitProgramFragment(x: JsProgramFragment): Unit =
|
||||
visitElement(x)
|
||||
|
||||
open fun visitPropertyInitializer(x: JsPropertyInitializer): Unit =
|
||||
visitElement(x)
|
||||
|
||||
|
||||
@@ -152,9 +152,6 @@ public abstract class JsVisitorWithContext {
|
||||
public void endVisit(@NotNull JsProgram x, @NotNull JsContext ctx) {
|
||||
}
|
||||
|
||||
public void endVisit(@NotNull JsProgramFragment x, @NotNull JsContext ctx) {
|
||||
}
|
||||
|
||||
public void endVisit(@NotNull JsPropertyInitializer x, @NotNull JsContext ctx) {
|
||||
}
|
||||
|
||||
@@ -312,10 +309,6 @@ public abstract class JsVisitorWithContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean visit(@NotNull JsProgramFragment x, @NotNull JsContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean visit(@NotNull JsPropertyInitializer x, @NotNull JsContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user