| Index: compiler/java/com/google/dart/compiler/backend/js/JavascriptBackend.java
|
| diff --git a/compiler/java/com/google/dart/compiler/backend/js/JavascriptBackend.java b/compiler/java/com/google/dart/compiler/backend/js/JavascriptBackend.java
|
| deleted file mode 100644
|
| index c33143c38c5a61ca2b6d785ed998d6865e5e44d7..0000000000000000000000000000000000000000
|
| --- a/compiler/java/com/google/dart/compiler/backend/js/JavascriptBackend.java
|
| +++ /dev/null
|
| @@ -1,181 +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 com.google.dart.compiler.backend.js;
|
| -
|
| -import com.google.common.io.CharStreams;
|
| -import com.google.common.io.Closeables;
|
| -import com.google.dart.compiler.DartCompilerContext;
|
| -import com.google.dart.compiler.DartSource;
|
| -import com.google.dart.compiler.LibrarySource;
|
| -import com.google.dart.compiler.ast.LibraryNode;
|
| -import com.google.dart.compiler.ast.LibraryUnit;
|
| -import com.google.dart.compiler.backend.js.analysis.TreeShaker;
|
| -import com.google.dart.compiler.metrics.CompilerMetrics;
|
| -import com.google.dart.compiler.resolver.CoreTypeProvider;
|
| -
|
| -import java.io.IOException;
|
| -import java.io.Reader;
|
| -import java.io.Writer;
|
| -import java.util.Collection;
|
| -
|
| -/**
|
| - * A compiler backend that produces raw Javascript.
|
| - */
|
| -public class JavascriptBackend extends AbstractJsBackend {
|
| -
|
| - public static final String EXTENSION_APP_JS_COMPLETE = EXTENSION_APP_JS + ".complete";
|
| -
|
| - /**
|
| - * Wraps an Appendable and keeps track of the current offset as line/columns.
|
| - */
|
| - static class CountingAppendable implements Appendable {
|
| -
|
| - private int line = 0;
|
| - private int column = 0;
|
| - private Appendable out;
|
| - private long charCount = 0;
|
| -
|
| - CountingAppendable(Appendable out) {
|
| - this.out = out;
|
| - }
|
| -
|
| - @Override
|
| - public Appendable append(CharSequence csq) throws IOException {
|
| - incCount(csq, 0, csq.length());
|
| - return out.append(csq);
|
| - }
|
| -
|
| - @Override
|
| - public Appendable append(char c) throws IOException {
|
| - incCount(c);
|
| - return out.append(c);
|
| - }
|
| -
|
| - @Override
|
| - public Appendable append(CharSequence csq, int start, int end)
|
| - throws IOException {
|
| - incCount(csq, start, end);
|
| - return out.append(csq, start, end);
|
| - }
|
| -
|
| - private void incCount(CharSequence cs, int start, int end) {
|
| - for (int i = 0; i < cs.length(); i++) {
|
| - incCount(cs.charAt(i));
|
| - }
|
| - }
|
| -
|
| - private void incCount(char c) {
|
| - ++charCount;
|
| - if (c == '\n') {
|
| - line++;
|
| - column = 0;
|
| - } else {
|
| - column++;
|
| - }
|
| - }
|
| - }
|
| -
|
| - private static class DepsWritingCallback implements DepsCallback {
|
| - private final DartCompilerContext context;
|
| - private CountingAppendable out;
|
| - DepsWritingCallback(
|
| - DartCompilerContext context,
|
| - CountingAppendable out) {
|
| - this.out = out;
|
| - this.context = context;
|
| - }
|
| -
|
| - @Override
|
| - public void visitNative(LibraryUnit libUnit, LibraryNode node)
|
| - throws IOException {
|
| - DartSource nativeSrc = libUnit.getSource().getSourceFor(node.getText());
|
| - Reader r = nativeSrc.getSourceReader();
|
| - long charsWrittenForFile = CharStreams.copy(r, out);
|
| - }
|
| -
|
| - @Override
|
| - public void visitPart(Part part) throws IOException {
|
| - DartSource src = part.unit.getSource();
|
| - assert(src != null);
|
| - Reader r = context.getArtifactReader(src, part.part, EXTENSION_JS);
|
| - if (r == null) {
|
| - return;
|
| - }
|
| -
|
| - long partSize = 0;
|
| - boolean failed = true;
|
| - try {
|
| - partSize = CharStreams.copy(r, out);
|
| - failed = false;
|
| - } finally {
|
| - Closeables.close(r, failed);
|
| - }
|
| - }
|
| -
|
| - public long getCharsWritten() {
|
| - return out.charCount;
|
| - }
|
| - }
|
| -
|
| - private static long packageLibs(Writer w,
|
| - DartCompilerContext context) throws IOException {
|
| - final CountingAppendable out = new CountingAppendable(w);
|
| -
|
| - DepsWritingCallback callback = new DepsWritingCallback(context, out);
|
| - DependencyBuilder.build(context.getAppLibraryUnit(), callback);
|
| - return callback.getCharsWritten();
|
| - }
|
| -
|
| - @Override
|
| - public void packageApp(LibrarySource app,
|
| - Collection<LibraryUnit> libraries,
|
| - DartCompilerContext context,
|
| - CoreTypeProvider typeProvider)
|
| - throws IOException {
|
| -
|
| - LibraryUnit appLibraryUnit = context.getAppLibraryUnit();
|
| - boolean hasEntryPoint = appLibraryUnit.getElement().getEntryPoint() != null;
|
| -
|
| - String completeArtifactName = EXTENSION_APP_JS;
|
| - if (hasEntryPoint) {
|
| - // Apps with entry points will be reduced so we write into a different file name
|
| - completeArtifactName = EXTENSION_APP_JS_COMPLETE;
|
| - }
|
| -
|
| - Writer out = context.getArtifactWriter(app, "", completeArtifactName);
|
| - long outputFileSize = 0;
|
| - boolean failed = true;
|
| - try {
|
| - // Emit the concatenated Javascript sources in dependency order.
|
| - outputFileSize = packageLibs(out, context);
|
| - outputFileSize += writeEntryPointCall(getMangledEntryPoint(context), out);
|
| - failed = false;
|
| - } finally {
|
| - Closeables.close(out, failed);
|
| - }
|
| -
|
| -
|
| - if (hasEntryPoint) {
|
| - Writer artifactWriter = context.getArtifactWriter(app, "", EXTENSION_APP_JS);
|
| - try {
|
| - failed = true;
|
| - outputFileSize = TreeShaker.reduce(app, context, completeArtifactName, artifactWriter);
|
| - failed = false;
|
| - } finally {
|
| - Closeables.close(artifactWriter, failed);
|
| - }
|
| - }
|
| -
|
| - CompilerMetrics compilerMetrics = context.getCompilerMetrics();
|
| - if (compilerMetrics != null) {
|
| - compilerMetrics.packagedJsApplication(outputFileSize, -1);
|
| - }
|
| - }
|
| -
|
| - @Override
|
| - public String getAppExtension() {
|
| - return EXTENSION_APP_JS;
|
| - }
|
| -}
|
|
|