You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2013/03/05 20:22:09 UTC
svn commit: r1452955 [6/9] - in /flex/falcon/trunk:
compiler.jx.tests/src/org/apache/flex/compiler/internal/as/
compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/
compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/
compile...
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitterTokens.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitterTokens.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitterTokens.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitterTokens.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,203 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+
+/**
+ * @author Michael Schmalle
+ * @author Erik de Bruin
+ */
+public enum ASEmitterTokens implements IEmitterTokens
+{
+ DOUBLE_QUOTE("\""), INDENT("\t"), NEW_LINE("\n"), SINGLE_QUOTE("'"), SPACE(
+ " "),
+
+ INTERNAL("internal"), PRIVATE("private"), PROTECTED("protected"),
+
+ ANY_TYPE("*"), UNDEFINED("undefined"),
+
+ // int EOF = 1;
+ // int NULL_TREE_LOOKAHEAD = 3;
+ // int HIDDEN_TOKEN_COMMENT = 4;
+ // int HIDDEN_TOKEN_SINGLE_LINE_COMMENT = 5;
+ // int HIDDEN_TOKEN_STAR_ASSIGNMENT = 6;
+ // int HIDDEN_TOKEN_BUILTIN_NS = 7;
+ // int HIDDEN_TOKEN_MULTI_LINE_COMMENT = 8;
+ // int TOKEN_ASDOC_TAG = 9;
+ // int TOKEN_ASDOC_TEXT = 10;
+ EACH("each"),
+ // int TOKEN_RESERVED_WORD_CONFIG = 12;
+ // int TOKEN_KEYWORD_INCLUDE = 13;
+ // int TOKEN_RESERVED_WORD_GOTO = 14;
+ // int TOKEN_IDENTIFIER = 15;
+ FINALLY("finally"),
+ CATCH("catch"),
+ // int TOKEN_LITERAL_STRING = 18;
+ BLOCK_OPEN("{"),
+ BLOCK_CLOSE("}"),
+ // int TOKEN_NAMESPACE_NAME = 21;
+ // int TOKEN_OPERATOR_NS_QUALIFIER = 22;
+ // int TOKEN_NAMESPACE_ANNOTATION = 23;
+ COLON(":"),
+ IMPORT("import"),
+ // int TOKEN_KEYWORD_USE = 26;
+ NAMESPACE("namespace"),
+ // int TOKEN_ASDOC_COMMENT = 28;
+ FINAL("final"),
+ DYNAMIC("dynamic"),
+ OVERRIDE("override"),
+ // int TOKEN_MODIFIER_STATIC = 32;
+ // int TOKEN_MODIFIER_NATIVE = 33;
+ // int TOKEN_MODIFIER_VIRTUAL = 34;
+ MEMBER_ACCESS("."),
+ // int TOKEN_ATTRIBUTE = 36;
+ SQUARE_OPEN("["),
+ PACKAGE("package"),
+ INTERFACE("interface"),
+ EXTENDS("extends"),
+ COMMA(","),
+ CLASS("class"),
+ IMPLEMENTS("implements"),
+ FUNCTION("function"),
+ PAREN_CLOSE(")"),
+ PAREN_OPEN("("),
+ GET("get"),
+ SET("set"),
+ ELLIPSIS("..."),
+ VAR("var"),
+ CONST("const"),
+ // int TOKEN_OPERATOR_ASSIGNMENT = 52;
+ // int TOKEN_DIRECTIVE_DEFAULT_XML = 53;
+ SEMICOLON(";"),
+ RETURN("return"),
+ THROW("throw"),
+ FOR("for"),
+ // int TOKEN_KEYWORD_IN = 58;
+ DO("do"),
+ WHILE("while"),
+ // int TOKEN_KEYWORD_CONTINUE = 61;
+ // int TOKEN_KEYWORD_BREAK = 62;
+ WITH("with"),
+ TRY("try"),
+ IF("if"),
+ ELSE("else"),
+ SWITCH("switch"),
+ CASE("case"),
+ DEFAULT("default"),
+ SUPER("super"),
+ // int TOKEN_TYPED_COLLECTION_OPEN = 71;
+ // int TOKEN_TYPED_COLLECTION_CLOSE = 72;
+ GREATER_THAN(">"),
+ // int TOKEN_OPERATOR_LOGICAL_AND_ASSIGNMENT = 74;
+ // int TOKEN_OPERATOR_LOGICAL_OR_ASSIGNMENT = 75;
+ // int TOKEN_OPERATOR_PLUS_ASSIGNMENT = 76;
+ // int TOKEN_OPERATOR_MINUS_ASSIGNMENT = 77;
+ // int TOKEN_OPERATOR_MULTIPLICATION_ASSIGNMENT = 78;
+ // int TOKEN_OPERATOR_DIVISION_ASSIGNMENT = 79;
+ // int TOKEN_OPERATOR_MODULO_ASSIGNMENT = 80;
+ // int TOKEN_OPERATOR_BITWISE_AND_ASSIGNMENT = 81;
+ // int TOKEN_OPERATOR_BITWISE_OR_ASSIGNMENT = 82;
+ // int TOKEN_OPERATOR_BITWISE_XOR_ASSIGNMENT = 83;
+ // int TOKEN_OPERATOR_BITWISE_LEFT_SHIFT_ASSIGNMENT = 84;
+ // int TOKEN_OPERATOR_BITWISE_RIGHT_SHIFT_ASSIGNMENT = 85;
+ // int TOKEN_OPERATOR_BITWISE_UNSIGNED_RIGHT_SHIFT_ASSIGNMENT = 86;
+ TERNARY("?"),
+ LOGICAL_OR("||"),
+ LOGICAL_AND("&&"),
+ // int TOKEN_OPERATOR_BITWISE_OR = 90;
+ // int TOKEN_OPERATOR_BITWISE_XOR = 91;
+ // int TOKEN_OPERATOR_BITWISE_AND = 92;
+ EQUAL("="),
+ // int TOKEN_OPERATOR_NOT_EQUAL = 94;
+ // int TOKEN_OPERATOR_STRICT_EQUAL = 95;
+ STRICT_NOT_EQUAL("!=="),
+ // int TOKEN_OPERATOR_GREATER_THAN_EQUALS = 97;
+ LESS_THAN("<"),
+ // int TOKEN_OPERATOR_LESS_THAN_EQUALS = 99;
+ // int TOKEN_KEYWORD_INSTANCEOF = 100;
+ IS("is"),
+ AS("as"),
+ // int TOKEN_OPERATOR_BITWISE_LEFT_SHIFT = 103;
+ // int TOKEN_OPERATOR_BITWISE_RIGHT_SHIFT = 104;
+ // int TOKEN_OPERATOR_BITWISE_UNSIGNED_RIGHT_SHIFT = 105;
+ MINUS("-"),
+ // int TOKEN_OPERATOR_PLUS = 107;
+ // int TOKEN_OPERATOR_DIVISION = 108;
+ // int TOKEN_OPERATOR_MODULO = 109;
+ // int TOKEN_OPERATOR_STAR = 110;
+ // int TOKEN_KEYWORD_DELETE = 111;
+ // int TOKEN_OPERATOR_INCREMENT = 112;
+ // int TOKEN_OPERATOR_DECREMENT = 113;
+ VOID("void"),
+ TYPEOF("typeof"),
+ // int TOKEN_OPERATOR_BITWISE_NOT = 116;
+ // int TOKEN_OPERATOR_LOGICAL_NOT = 117;
+ NULL("null"),
+ TRUE("true"),
+ // int TOKEN_KEYWORD_FALSE = 120;
+ THIS("this"),
+ // int TOKEN_VOID_0 = 122;
+ // int TOKEN_LITERAL_REGEXP = 123;
+ // int TOKEN_LITERAL_NUMBER = 124;
+ // int TOKEN_LITERAL_HEX_NUMBER = 125;
+ SQUARE_CLOSE("]"),
+ // int TOKEN_TYPED_LITERAL_OPEN = 127;
+ // int TOKEN_TYPED_LITERAL_CLOSE = 128;
+ // int TOKEN_E4X_WHITESPACE = 129;
+ // int TOKEN_E4X_COMMENT = 130;
+ // int TOKEN_E4X_CDATA = 131;
+ // int TOKEN_E4X_PROCESSING_INSTRUCTION = 132;
+ // int TOKEN_E4X_ENTITY = 133;
+ // int TOKEN_E4X_DECIMAL_ENTITY = 134;
+ // int TOKEN_E4X_HEX_ENTITY = 135;
+ // int TOKEN_E4X_TEXT = 136;
+ // int TOKEN_E4X_STRING = 137;
+ // int TOKEN_E4X_OPEN_TAG_START = 138;
+ // int TOKEN_E4X_CLOSE_TAG_START = 139;
+ // int HIDDEN_TOKEN_E4X = 140;
+ // int TOKEN_E4X_NAME = 141;
+ // int TOKEN_E4X_TAG_END = 142;
+ // int TOKEN_E4X_EMPTY_TAG_END = 143;
+ // int TOKEN_E4X_XMLNS = 144;
+ // int TOKEN_E4X_NAME_DOT = 145;
+ // int TOKEN_E4X_DOTTED_NAME_PART = 146;
+ // int TOKEN_E4X_EQUALS = 147;
+ // int TOKEN_LITERAL_XMLLIST = 148;
+ // int TOKEN_E4X_XMLLIST_CLOSE = 149;
+ // int TOKEN_E4X_BINDING_OPEN = 150;
+ // int TOKEN_E4X_BINDING_CLOSE = 151;
+ NEW("new"),
+ ATSIGN("@"),
+ // int TOKEN_OPERATOR_DESCENDANT_ACCESS = 154;
+ ;
+
+ private String token;
+
+ private ASEmitterTokens(String value)
+ {
+ token = value;
+ }
+
+ public String getToken()
+ {
+ return token;
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitterTokens.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASFilterWriter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASFilterWriter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASFilterWriter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASFilterWriter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,42 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.as;
+
+import java.io.FilterWriter;
+import java.io.Writer;
+
+/**
+ * @author Michael Schmalle
+ */
+public class ASFilterWriter extends FilterWriter
+{
+
+ public ASFilterWriter(Writer out)
+ {
+ super(out);
+ }
+
+ @Override
+ public String toString()
+ {
+ return out.toString();
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASFilterWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASWriter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASWriter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASWriter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASWriter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,98 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.as;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.js.IJSWriter;
+import org.apache.flex.compiler.internal.codegen.js.JSSharedData;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.IASProject;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+
+public class ASWriter implements IJSWriter
+{
+ private IASProject project;
+
+ private List<ICompilerProblem> problems;
+
+ private ICompilationUnit compilationUnit;
+
+ @SuppressWarnings("unused")
+ private boolean enableDebug;
+
+ /**
+ * Create a JSApplication writer.
+ *
+ * @param application the JSApplication model to be encoded
+ * @param useCompression use ZLIB compression if true
+ */
+ public ASWriter(IASProject project, List<ICompilerProblem> problems,
+ ICompilationUnit compilationUnit, boolean enableDebug)
+ {
+ this.project = project;
+ this.problems = problems;
+ this.compilationUnit = compilationUnit;
+ this.enableDebug = enableDebug;
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ //outputBuffer.close();
+ }
+
+ @Override
+ public void writeTo(OutputStream out)
+ {
+ ASFilterWriter writer = JSSharedData.backend
+ .createWriterBuffer(project);
+ IASEmitter emitter = JSSharedData.backend.createEmitter(writer);
+ IASBlockWalker walker = JSSharedData.backend.createWalker(project,
+ problems, emitter);
+
+ walker.visitCompilationUnit(compilationUnit);
+
+ System.out.println(writer.toString());
+
+ try
+ {
+ out.write(writer.toString().getBytes());
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public int writeTo(File out) throws FileNotFoundException, IOException
+ {
+ return 0;
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,130 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js;
+
+import org.apache.flex.compiler.codegen.IDocEmitter;
+import org.apache.flex.compiler.codegen.IEmitter;
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+
+@SuppressWarnings("unused")
+public class JSDocEmitter implements IDocEmitter, IEmitter
+{
+
+ private int currentIndent = 0;
+
+ @Override
+ public void indentPush()
+ {
+ currentIndent++;
+ }
+
+ @Override
+ public void indentPop()
+ {
+ currentIndent--;
+ }
+
+ @Override
+ public void write(IEmitterTokens value)
+ {
+ write(value.getToken());
+ }
+
+ @Override
+ public void write(String value)
+ {
+ emitter.write(value);
+ }
+
+ @Override
+ public void writeNewline()
+ {
+ emitter.writeNewline();
+ }
+
+ @Override
+ public void writeNewline(String value)
+ {
+ emitter.writeNewline(value);
+ }
+
+ @Override
+ public void writeNewline(IEmitterTokens value)
+ {
+ emitter.writeNewline(value);
+ }
+
+ @Override
+ public void writeNewline(String value, boolean pushIndent)
+ {
+ emitter.writeNewline(value, pushIndent);
+ }
+
+ @Override
+ public void writeNewline(IEmitterTokens value, boolean pushIndent)
+ {
+ emitter.writeNewline(value, pushIndent);
+ }
+
+ @Override
+ public void writeToken(IEmitterTokens value)
+ {
+ emitter.writeToken(value);
+ }
+
+ @Override
+ public void writeToken(String value)
+ {
+ emitter.writeToken(value);
+ }
+
+ public void writeBlockClose()
+ {
+ emitter.write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+
+ public void writeBlockOpen()
+ {
+ emitter.write(ASEmitterTokens.BLOCK_OPEN);
+ }
+
+ private IEmitter emitter;
+
+ public JSDocEmitter(IJSEmitter emitter)
+ {
+ this.emitter = (IEmitter) emitter;
+ }
+
+ @Override
+ public void begin()
+ {
+ writeNewline(JSDocEmitterTokens.JSDOC_OPEN);
+ }
+
+ @Override
+ public void end()
+ {
+ write(ASEmitterTokens.SPACE);
+ writeNewline(JSDocEmitterTokens.JSDOC_CLOSE);
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitterTokens.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitterTokens.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitterTokens.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitterTokens.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,20 @@
+package org.apache.flex.compiler.internal.codegen.js;
+
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+
+public enum JSDocEmitterTokens implements IEmitterTokens
+{
+ JSDOC_CLOSE("*/"), JSDOC_OPEN("/**");
+
+ private String token;
+
+ private JSDocEmitterTokens(String value)
+ {
+ token = value;
+ }
+
+ public String getToken()
+ {
+ return token;
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSDocEmitterTokens.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,56 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js;
+
+import java.io.FilterWriter;
+
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.internal.tree.as.FunctionObjectNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+
+/**
+ * @author Michael Schmalle
+ */
+public class JSEmitter extends ASEmitter implements IJSEmitter
+{
+
+ public JSEmitter(FilterWriter out)
+ {
+ super(out);
+ }
+
+ @Override
+ public void emitFunctionObject(IExpressionNode node)
+ {
+ FunctionObjectNode f = (FunctionObjectNode) node;
+
+ FunctionNode fnode = f.getFunctionNode();
+
+ write(ASEmitterTokens.FUNCTION);
+
+ emitParamters(fnode.getParameterNodes());
+
+ emitFunctionScope(fnode.getScopedNode());
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitterTokens.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitterTokens.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitterTokens.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitterTokens.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,27 @@
+package org.apache.flex.compiler.internal.codegen.js;
+
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+
+public enum JSEmitterTokens implements IEmitterTokens
+{
+ ARGUMENTS("arguments"),
+ CALL("call"),
+ CONFIGURABLE("configurable"),
+ CONSTRUCTOR("constructor"),
+ DEFINE_PROPERTY("defineProperty"),
+ INTERFACE("interface"),
+ PROTOTYPE("prototype"),
+ SLICE("slice");
+
+ private String token;
+
+ private JSEmitterTokens(String value)
+ {
+ token = value;
+ }
+
+ public String getToken()
+ {
+ return token;
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitterTokens.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSFilterWriter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSFilterWriter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSFilterWriter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSFilterWriter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,43 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js;
+
+import java.io.Writer;
+
+import org.apache.flex.compiler.internal.codegen.as.ASFilterWriter;
+
+/**
+ * @author Michael Schmalle
+ */
+public class JSFilterWriter extends ASFilterWriter
+{
+
+ public JSFilterWriter(Writer out)
+ {
+ super(out);
+ }
+
+ @Override
+ public String toString()
+ {
+ return out.toString();
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSFilterWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSPublisher.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSPublisher.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSPublisher.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSPublisher.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,49 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.flex.compiler.codegen.js.IJSPublisher;
+import org.apache.flex.compiler.config.Configuration;
+
+public class JSPublisher implements IJSPublisher
+{
+
+ public JSPublisher(Configuration config)
+ {
+ this.configuration = config;
+ }
+
+ protected Configuration configuration;
+
+ public File getOutputFolder()
+ {
+ return null;
+ }
+
+ public void publish() throws IOException
+ {
+ System.out
+ .println("The project has been successfully compiled and optimized.");
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSPublisher.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSharedData.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSharedData.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSharedData.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSharedData.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,116 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js;
+
+import java.io.PrintStream;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+
+// TODO (mschmalle) This class sucks, figure out some other way instead of using
+// a static singleton class like this, change when implementing Configuration
+public class JSSharedData
+{
+
+ public static final String COMPILER_NAME = "MXMLJSC";
+ public static final boolean OUTPUT_TIMESTAMPS = true;
+ public static final String COMPILER_VERSION = "329449.1";
+
+ public final static JSSharedData instance = new JSSharedData();
+
+ public static IBackend backend;
+ public static String OUTPUT_EXTENSION;
+ public static Workspace workspace;
+
+ public static PrintStream STDOUT = System.out;
+ public static PrintStream STDERR = System.err;
+
+ @SuppressWarnings("unused")
+ private Boolean m_verbose = false;
+ private final ReadWriteLock m_verboseLock = new ReentrantReadWriteLock();
+
+ private Object m_codeGenMonitor = new Object();
+ private long m_codeGenCounter = 0;
+ private final ReadWriteLock m_codeGenCounterLock = new ReentrantReadWriteLock();
+
+ public static String now()
+ {
+ final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
+ Calendar cal = Calendar.getInstance();
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
+ return sdf.format(cal.getTime());
+ }
+
+ public void stdout(String s)
+ {
+ if (STDOUT != null)
+ {
+ m_verboseLock.writeLock().lock();
+ STDOUT.println(s);
+ m_verboseLock.writeLock().unlock();
+ }
+ }
+
+ public void stderr(String s)
+ {
+ if (STDERR != null)
+ {
+ m_verboseLock.writeLock().lock();
+ STDERR.println(s);
+ m_verboseLock.writeLock().unlock();
+ }
+ }
+
+ public void beginCodeGen()
+ {
+ m_codeGenCounterLock.writeLock().lock();
+ m_codeGenCounter++;
+ m_codeGenCounterLock.writeLock().unlock();
+ }
+
+ public void endCodeGen()
+ {
+ m_codeGenCounterLock.writeLock().lock();
+ final long currentCounter = --m_codeGenCounter;
+ m_codeGenCounterLock.writeLock().unlock();
+
+ if (currentCounter == 0)
+ {
+ synchronized (m_codeGenMonitor)
+ {
+ m_codeGenMonitor.notifyAll();
+ }
+ }
+ }
+
+ public static String getTimeStampString()
+ {
+ if (JSSharedData.OUTPUT_TIMESTAMPS)
+ return "CROSS-COMPILED BY " + JSSharedData.COMPILER_NAME + " ("
+ + JSSharedData.COMPILER_VERSION + ") ON "
+ + JSSharedData.now() + "\n";
+ else
+ return "CROSS-COMPILED BY " + JSSharedData.COMPILER_NAME + "\n";
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSharedData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSWriter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSWriter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSWriter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSWriter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,95 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.js.IJSWriter;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.IASProject;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+
+public class JSWriter implements IJSWriter
+{
+ private IASProject project;
+
+ private List<ICompilerProblem> problems;
+
+ private ICompilationUnit compilationUnit;
+
+ @SuppressWarnings("unused")
+ private boolean enableDebug;
+
+ /**
+ * Create a JSApplication writer.
+ *
+ * @param application the JSApplication model to be encoded
+ * @param useCompression use ZLIB compression if true
+ */
+ public JSWriter(IASProject project, List<ICompilerProblem> problems,
+ ICompilationUnit compilationUnit, boolean enableDebug)
+ {
+ this.project = project;
+ this.problems = problems;
+ this.compilationUnit = compilationUnit;
+ this.enableDebug = enableDebug;
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ //outputBuffer.close();
+ }
+
+ @Override
+ public void writeTo(OutputStream out)
+ {
+ JSFilterWriter writer = (JSFilterWriter) JSSharedData.backend
+ .createWriterBuffer(project);
+ IASEmitter emitter = JSSharedData.backend.createEmitter(writer);
+ IASBlockWalker walker = JSSharedData.backend.createWalker(project,
+ problems, emitter);
+
+ walker.visitCompilationUnit(compilationUnit);
+
+ try
+ {
+ out.write(writer.toString().getBytes());
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public int writeTo(File out) throws FileNotFoundException, IOException
+ {
+ return 0;
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/ExportWriter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/ExportWriter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/ExportWriter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/ExportWriter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,230 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js.amd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+
+/**
+ * @author Michael Schmalle
+ */
+public class ExportWriter
+{
+ private static final String CLASSES_TYPES = "__CLASSES$TYPES__";
+
+ private static final String CLASSES_STRINGS = "__CLASSES$STRINGS__";
+
+ private static final String RUNTIME_TYPES = "__RUNTIME$TYPES__";
+
+ private static final String RUNTIME_STRINGS = "__RUNTIME$STRINGS__";
+
+ private final JSAMDEmitter emitter;
+
+ private List<Dependency> runtime = new ArrayList<Dependency>();
+
+ private List<Dependency> types = new ArrayList<Dependency>();
+
+ public ExportWriter(JSAMDEmitter emitter)
+ {
+ this.emitter = emitter;
+ }
+
+ public void queueExports(ITypeDefinition type, boolean outputString)
+ {
+ if (outputString)
+ {
+ emitter.write("[");
+ emitter.write("\"exports\"");
+ }
+
+ emitter.write(", ");
+
+ if (outputString)
+ emitter.write(RUNTIME_STRINGS);
+ else
+ emitter.write(RUNTIME_TYPES);
+
+ //emitter.write(", ");
+
+ if (outputString)
+ emitter.write(CLASSES_STRINGS);
+ else
+ emitter.write(CLASSES_TYPES);
+
+ if (outputString)
+ {
+ emitter.write("]");
+ }
+ }
+
+ public void writeExports(ITypeDefinition type, boolean outputString)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ int i = 0;
+ int len = runtime.size();
+
+ for (Dependency dependency : runtime)
+ {
+ sb.append(dependency.output(outputString, "runtime", outputString));
+
+ if (i < len - 1)
+ sb.append(", ");
+ i++;
+ }
+
+ if (outputString)
+ {
+ int start = emitter.builder().indexOf(RUNTIME_STRINGS);
+ int end = start + RUNTIME_STRINGS.length();
+ emitter.builder().replace(start, end, sb.toString());
+ }
+ else
+ {
+ int start = emitter.builder().indexOf(RUNTIME_TYPES);
+ int end = start + RUNTIME_TYPES.length();
+ emitter.builder().replace(start, end, sb.toString());
+ }
+
+ sb = new StringBuilder();
+
+ i = 0;
+ len = types.size();
+ if (len > 0)
+ sb.append(", "); // trailing comma
+
+ for (Dependency dependency : types)
+ {
+ sb.append(dependency.output(outputString, "classes", outputString));
+
+ if (i < len - 1)
+ sb.append(", ");
+ i++;
+ }
+
+ if (outputString)
+ {
+ int start = emitter.builder().indexOf(CLASSES_STRINGS);
+ int end = start + CLASSES_STRINGS.length();
+ emitter.builder().replace(start, end, sb.toString());
+ }
+ else
+ {
+ int start = emitter.builder().indexOf(CLASSES_TYPES);
+ int end = start + CLASSES_TYPES.length();
+ emitter.builder().replace(start, end, sb.toString());
+ }
+ }
+
+ void addImports(ITypeDefinition type)
+ {
+ Collection<String> imports = new ArrayList<String>();
+ type.getContainedScope().getScopeNode().getAllImports(imports);
+ for (String imp : imports)
+ {
+ String name = toBaseName(imp);
+ if (!isExcludedImport(imp))
+ addDependency(name, imp, false, false);
+ }
+ }
+
+ void addFrameworkDependencies()
+ {
+ runtime.add(new Dependency("AS3", "AS3", false, false));
+ }
+
+ protected boolean isExcludedImport(String imp)
+ {
+ return imp.startsWith("__AS3__");
+ }
+
+ public void addDependency(String baseName, String qualifiedName,
+ boolean isNative, boolean isPlugin)
+ {
+ types.add(new Dependency(baseName, qualifiedName, isNative, isPlugin));
+ }
+
+ static String toBaseName(String name)
+ {
+ if (!name.contains("."))
+ return name;
+ final String basename = name.substring(name.lastIndexOf(".") + 1);
+ return basename;
+ }
+
+ static class Dependency
+ {
+ private final String baseName;
+
+ private final String qualifiedName;
+
+ public String getQualifiedName()
+ {
+ return qualifiedName;
+ }
+
+ private final boolean isNative;
+
+ public boolean isNative()
+ {
+ return isNative;
+ }
+
+ @SuppressWarnings("unused")
+ private final boolean isPlugin;
+
+ public Dependency(String baseName, String qualifiedName,
+ boolean isNative, boolean isPlugin)
+ {
+ this.baseName = baseName;
+ this.qualifiedName = qualifiedName;
+ this.isNative = isNative;
+ this.isPlugin = isPlugin;
+ }
+
+ @Override
+ public String toString()
+ {
+ return qualifiedName; // TODO (mschmalle|AMD) native
+ }
+
+ public String output(boolean outputString, String base,
+ boolean qualified)
+ {
+ StringBuilder sb = new StringBuilder();
+ if (outputString)
+ {
+ sb.append("\"" + base + "/"
+ + qualifiedName.replaceAll("\\.", "/") + "\"");
+ }
+ else
+ {
+ if (qualified)
+ sb.append(qualifiedName);
+ else
+ sb.append(baseName);
+ }
+ return sb.toString();
+ }
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/ExportWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,38 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js.amd;
+
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.codegen.js.amd.IJSAMDDocEmitter;
+import org.apache.flex.compiler.internal.codegen.js.JSDocEmitter;
+
+/**
+ * @author Michael Schmalle
+ */
+public class JSAMDDocEmitter extends JSDocEmitter implements IJSAMDDocEmitter
+{
+
+ public JSAMDDocEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDDocEmitter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,975 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.flex.compiler.internal.codegen.js.amd;
+
+import java.io.FilterWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.flex.compiler.codegen.js.amd.IJSAMDDocEmitter;
+import org.apache.flex.compiler.codegen.js.amd.IJSAMDEmitter;
+import org.apache.flex.compiler.definitions.IAccessorDefinition;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IConstantDefinition;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.definitions.IInterfaceDefinition;
+import org.apache.flex.compiler.definitions.IPackageDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+import org.apache.flex.compiler.definitions.IVariableDefinition;
+import org.apache.flex.compiler.definitions.references.IReference;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.definitions.ClassTraitsDefinition;
+import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.scopes.IASScope;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IBlockNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
+import org.apache.flex.compiler.tree.as.ITypeNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.compiler.utils.NativeUtils;
+
+/**
+ * Concrete implementation of the 'AMD' JavaScript production.
+ *
+ * @author Michael Schmalle
+ */
+public class JSAMDEmitter extends JSEmitter implements IJSAMDEmitter
+{
+
+ private Map<String, IDefinitionNode> foundAccessors = new HashMap<String, IDefinitionNode>();
+
+ private int inheritenceLevel = -1;
+
+ private ExportWriter exportWriter;
+
+ private boolean initializingFieldsInConstructor;
+
+ private List<IDefinition> baseClassCalls = new ArrayList<IDefinition>();
+
+ StringBuilder builder()
+ {
+ return getBuilder();
+ }
+
+ IJSAMDDocEmitter getDoc()
+ {
+ return (IJSAMDDocEmitter) getDocEmitter();
+ }
+
+ public JSAMDEmitter(FilterWriter out)
+ {
+ super(out);
+
+ exportWriter = new ExportWriter(this);
+ }
+
+ @Override
+ public void emitPackageHeader(IPackageDefinition definition)
+ {
+ // TODO (mschmalle|AMD) this is a hack but I know no other way to do replacements in a Writer
+ setBufferWrite(true);
+
+ write(JSAMDEmitterTokens.DEFINE);
+ write(ASEmitterTokens.PAREN_OPEN);
+
+ IASScope containedScope = definition.getContainedScope();
+ ITypeDefinition type = findType(containedScope.getAllLocalDefinitions());
+ if (type == null)
+ return;
+
+ exportWriter.addFrameworkDependencies();
+ exportWriter.addImports(type);
+
+ exportWriter.queueExports(type, true);
+
+ writeToken(ASEmitterTokens.COMMA);
+ }
+
+ @Override
+ public void emitPackageHeaderContents(IPackageDefinition definition)
+ {
+ // nothing
+ }
+
+ @Override
+ public void emitPackageContents(IPackageDefinition definition)
+ {
+ IASScope containedScope = definition.getContainedScope();
+ ITypeDefinition type = findType(containedScope.getAllLocalDefinitions());
+ if (type == null)
+ return;
+
+ write("function($exports");
+
+ exportWriter.queueExports(type, false);
+
+ write(") {");
+ indentPush();
+ writeNewline();
+ write("\"use strict\"; ");
+ writeNewline();
+
+ ITypeNode tnode = findTypeNode(definition.getNode());
+ if (tnode != null)
+ {
+ getWalker().walk(tnode); // IClassNode | IInterfaceNode
+ }
+
+ indentPop();
+ writeNewline();
+ write("}"); // end returned function
+ }
+
+ @Override
+ public void emitPackageFooter(IPackageDefinition definition)
+ {
+ IASScope containedScope = definition.getContainedScope();
+ ITypeDefinition type = findType(containedScope.getAllLocalDefinitions());
+ if (type == null)
+ return;
+
+ exportWriter.writeExports(type, true);
+ exportWriter.writeExports(type, false);
+
+ write(");"); // end define()
+
+ // flush the buffer, writes the builder to out
+ flushBuilder();
+ }
+
+ private void emitConstructor(IFunctionNode node)
+ {
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(problems);
+
+ //IFunctionDefinition definition = node.getDefinition();
+
+ write("function ");
+ write(node.getName());
+ emitParamters(node.getParameterNodes());
+ if (!isImplicit((IContainerNode) node.getScopedNode()))
+ {
+ emitMethodScope(node.getScopedNode());
+ }
+ else
+ {
+ // we have a synthesized constructor, implict
+ }
+ }
+
+ @Override
+ public void emitInterface(IInterfaceNode node)
+ {
+ final IInterfaceDefinition definition = node.getDefinition();
+ final String interfaceName = definition.getBaseName();
+
+ write("AS3.interface_($exports, {");
+ indentPush();
+ writeNewline();
+
+ write("package_: \"");
+ write(definition.getPackageName());
+ write("\",");
+ writeNewline();
+
+ write("interface_: \"");
+ write(interfaceName);
+ write("\"");
+
+ IReference[] references = definition.getExtendedInterfaceReferences();
+ final int len = references.length;
+ if (len > 0)
+ {
+ writeNewline();
+ write("extends_: [");
+ indentPush();
+ writeNewline();
+ int i = 0;
+ for (IReference reference : references)
+ {
+ write(reference.getName());
+ if (i < len - 1)
+ {
+ write(",");
+ writeNewline();
+ }
+ i++;
+ }
+ indentPop();
+ writeNewline();
+ write("]");
+ }
+
+ indentPop();
+ writeNewline();
+ write("});"); // end compilation unit
+ }
+
+ @Override
+ public void emitClass(IClassNode node)
+ {
+ //ICompilerProject project = getWalker().getProject();
+
+ IClassDefinition definition = node.getDefinition();
+ final String className = definition.getBaseName();
+
+ write("AS3.compilationUnit($exports, function($primaryDeclaration){");
+ indentPush();
+ writeNewline();
+
+ // write constructor
+ emitConstructor((IFunctionNode) definition.getConstructor().getNode());
+ writeNewline();
+
+ // base class
+ IReference baseClassReference = definition.getBaseClassReference();
+ boolean hasSuper = baseClassReference != null
+ && !baseClassReference.getName().equals("Object");
+ if (hasSuper)
+ {
+ String baseName = baseClassReference.getName();
+ write("var Super = (" + baseName + "._ || " + baseName
+ + "._$get());");
+ writeNewline();
+ write("var super$ = Super.prototype;");
+ writeNewline();
+ }
+
+ write("$primaryDeclaration(AS3.class_({");
+ indentPush();
+ writeNewline();
+
+ // write out package
+ write("package_: \"" + definition.getPackageName() + "\",");
+ writeNewline();
+ // write class
+ write("class_: \"" + definition.getBaseName() + "\",");
+ writeNewline();
+ if (hasSuper)
+ {
+ write("extends_: Super,");
+ writeNewline();
+ }
+
+ IReference[] references = definition
+ .getImplementedInterfaceReferences();
+ int len = references.length;
+
+ // write implements
+ write("implements_:");
+ write(" [");
+
+ if (len > 0)
+ {
+ indentPush();
+ writeNewline();
+ }
+
+ int i = 0;
+ for (IReference reference : references)
+ {
+ write(reference.getName());
+ exportWriter.addDependency(reference.getName(),
+ reference.getDisplayString(), false, false);
+ if (i < len - 1)
+ {
+ write(",");
+ writeNewline();
+ }
+ i++;
+ }
+
+ if (len > 0)
+ {
+ indentPop();
+ writeNewline();
+ }
+
+ write("],");
+ writeNewline();
+
+ // write members
+ final IDefinitionNode[] members = node.getAllMemberNodes();
+
+ write("members: {");
+
+ indentPush();
+ writeNewline();
+
+ // constructor
+ write("constructor: " + className);
+ if (members.length > 0)
+ {
+ write(",");
+ writeNewline();
+ }
+
+ List<IDefinitionNode> instanceMembers = new ArrayList<IDefinitionNode>();
+ List<IDefinitionNode> staticMembers = new ArrayList<IDefinitionNode>();
+ List<IASNode> staticStatements = new ArrayList<IASNode>();
+
+ TempTools.fillInstanceMembers(members, instanceMembers);
+ TempTools.fillStaticMembers(members, staticMembers, true, false);
+ TempTools.fillStaticStatements(node, staticStatements, false);
+
+ len = instanceMembers.size();
+ i = 0;
+ for (IDefinitionNode mnode : instanceMembers)
+ {
+ if (mnode instanceof IAccessorNode)
+ {
+ if (foundAccessors.containsKey(mnode.getName()))
+ {
+ len--;
+ continue;
+ }
+
+ getWalker().walk(mnode);
+ }
+ else if (mnode instanceof IFunctionNode)
+ {
+ getWalker().walk(mnode);
+ }
+ else if (mnode instanceof IVariableNode)
+ {
+ getWalker().walk(mnode);
+ }
+ else
+ {
+ write(mnode.getName());
+ }
+
+ if (i < len - 1)
+ {
+ write(",");
+ writeNewline();
+ }
+ i++;
+ }
+
+ // base class super calls
+ len = baseClassCalls.size();
+ i = 0;
+ if (len > 0)
+ {
+ write(",");
+ writeNewline();
+ }
+
+ for (IDefinition baseCall : baseClassCalls)
+ {
+ write(baseCall.getBaseName() + "$" + inheritenceLevel + ": super$."
+ + baseCall.getBaseName());
+
+ if (i < len - 1)
+ {
+ write(",");
+ writeNewline();
+ }
+ }
+
+ // end members
+ indentPop();
+ writeNewline();
+ write("},");
+ writeNewline();
+
+ len = staticMembers.size();
+
+ write("staticMembers: {");
+
+ indentPush();
+ writeNewline();
+
+ i = 0;
+ for (IDefinitionNode mnode : staticMembers)
+ {
+ if (mnode instanceof IAccessorNode)
+ {
+ // TODO (mschmalle|AMD) havn't taken care of static accessors
+ if (foundAccessors.containsKey(mnode.getName()))
+ continue;
+
+ foundAccessors.put(mnode.getName(), mnode);
+
+ getWalker().walk(mnode);
+ }
+ else if (mnode instanceof IFunctionNode)
+ {
+ getWalker().walk(mnode);
+ }
+ else if (mnode instanceof IVariableNode)
+ {
+ getWalker().walk(mnode);
+ }
+
+ if (i < len - 1)
+ {
+ write(",");
+ writeNewline();
+ }
+ i++;
+ }
+ indentPop();
+ if (len > 0)
+ writeNewline();
+ write("}");
+
+ indentPop();
+ writeNewline();
+ write("}));");
+
+ // static statements
+ len = staticStatements.size();
+ if (len > 0)
+ writeNewline();
+
+ i = 0;
+ for (IASNode statement : staticStatements)
+ {
+ getWalker().walk(statement);
+ if (!(statement instanceof IBlockNode))
+ write(";");
+
+ if (i < len - 1)
+ writeNewline();
+
+ i++;
+ }
+
+ indentPop();
+ writeNewline();
+ write("});"); // end compilation unit
+
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ //--------------------------------------------------------------------------
+
+ @Override
+ public void emitField(IVariableNode node)
+ {
+ IVariableDefinition definition = (IVariableDefinition) node
+ .getDefinition();
+
+ if (definition.isStatic())
+ {
+ IClassDefinition parent = (IClassDefinition) definition.getParent();
+ write(parent.getBaseName());
+ write(".");
+ write(definition.getBaseName());
+ write(" = ");
+ emitFieldInitialValue(node);
+ return;
+ }
+
+ String name = toPrivateName(definition);
+ write(name);
+ write(": ");
+ write("{");
+ indentPush();
+ writeNewline();
+ // field value
+ write("value:");
+ emitFieldInitialValue(node);
+ write(",");
+ writeNewline();
+ // writable
+ write("writable:");
+ write(!(definition instanceof IConstantDefinition) ? "true" : "false");
+ indentPop();
+ writeNewline();
+ write("}");
+ }
+
+ private void emitFieldInitialValue(IVariableNode node)
+ {
+ ICompilerProject project = getWalker().getProject();
+ IVariableDefinition definition = (IVariableDefinition) node
+ .getDefinition();
+
+ IExpressionNode valueNode = node.getAssignedValueNode();
+ if (valueNode != null)
+ getWalker().walk(valueNode);
+ else
+ write(TempTools.toInitialValue(definition, project));
+ }
+
+ @Override
+ public void emitGetAccessor(IGetterNode node)
+ {
+ if (foundAccessors.containsKey(node.getName()))
+ return;
+
+ foundAccessors.put(node.getName(), node);
+
+ ICompilerProject project = getWalker().getProject();
+ IAccessorDefinition getter = (IAccessorDefinition) node.getDefinition();
+ IAccessorDefinition setter = getter
+ .resolveCorrespondingAccessor(project);
+
+ emitGetterSetterPair(getter, setter);
+ }
+
+ @Override
+ public void emitSetAccessor(ISetterNode node)
+ {
+ if (foundAccessors.containsKey(node.getName()))
+ return;
+
+ foundAccessors.put(node.getName(), node);
+
+ ICompilerProject project = getWalker().getProject();
+ IAccessorDefinition setter = (IAccessorDefinition) node.getDefinition();
+ IAccessorDefinition getter = setter
+ .resolveCorrespondingAccessor(project);
+
+ emitGetterSetterPair(getter, setter);
+ }
+
+ private void emitGetterSetterPair(IAccessorDefinition getter,
+ IAccessorDefinition setter)
+ {
+ write(getter.getBaseName());
+ write(": {");
+ indentPush();
+ writeNewline();
+
+ if (getter != null)
+ {
+ emitAccessor("get", getter);
+ }
+ if (setter != null)
+ {
+ write(",");
+ writeNewline();
+ emitAccessor("set", setter);
+ }
+
+ indentPop();
+ writeNewline();
+ write("}");
+
+ }
+
+ protected void emitAccessor(String kind, IAccessorDefinition definition)
+ {
+ IFunctionNode fnode = definition.getFunctionNode();
+
+ FunctionNode fn = (FunctionNode) fnode;
+ fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
+
+ write(kind + ": function ");
+ write(definition.getBaseName() + "$" + kind);
+ emitParamters(fnode.getParameterNodes());
+ emitMethodScope(fnode.getScopedNode());
+ }
+
+ @Override
+ public void emitMethod(IFunctionNode node)
+ {
+ if (node.isConstructor())
+ {
+ emitConstructor(node);
+ return;
+ }
+
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
+ IFunctionDefinition definition = node.getDefinition();
+
+ String name = toPrivateName(definition);
+ write(name);
+ write(":");
+ write(" function ");
+ write(node.getName());
+ emitParamters(node.getParameterNodes());
+ emitMethodScope(node.getScopedNode());
+ }
+
+ @Override
+ public void emitFunctionBlockHeader(IFunctionNode node)
+ {
+ IFunctionDefinition definition = node.getDefinition();
+
+ if (node.isConstructor())
+ {
+ initializingFieldsInConstructor = true;
+ IClassDefinition type = (IClassDefinition) definition
+ .getAncestorOfType(IClassDefinition.class);
+ // emit public fields init values
+ List<IVariableDefinition> fields = TempTools.getFields(type, true);
+ for (IVariableDefinition field : fields)
+ {
+ if (TempTools.isVariableAParameter(field,
+ definition.getParameters()))
+ continue;
+ write("this.");
+ write(field.getBaseName());
+ write(" = ");
+ emitFieldInitialValue((IVariableNode) field.getNode());
+ write(";");
+ writeNewline();
+ }
+ initializingFieldsInConstructor = false;
+ }
+
+ emitDefaultParameterCodeBlock(node);
+ }
+
+ private void emitDefaultParameterCodeBlock(IFunctionNode node)
+ {
+ // TODO (mschmalle|AMD) test for ... rest
+ // if default parameters exist, produce the init code
+ IParameterNode[] pnodes = node.getParameterNodes();
+ Map<Integer, IParameterNode> defaults = TempTools.getDefaults(pnodes);
+ if (pnodes.length == 0)
+ return;
+
+ if (defaults != null)
+ {
+ boolean hasBody = node.getScopedNode().getChildCount() > 0;
+
+ if (!hasBody)
+ {
+ indentPush();
+ write(ASEmitterTokens.INDENT);
+ }
+
+ final StringBuilder code = new StringBuilder();
+
+ List<IParameterNode> parameters = new ArrayList<IParameterNode>(
+ defaults.values());
+ Collections.reverse(parameters);
+
+ int len = defaults.size();
+ // make the header in reverse order
+ for (IParameterNode pnode : parameters)
+ {
+ if (pnode != null)
+ {
+ code.setLength(0);
+
+ code.append(ASEmitterTokens.IF.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.PAREN_OPEN.getToken());
+ code.append(JSEmitterTokens.ARGUMENTS.getToken());
+ code.append(ASEmitterTokens.MEMBER_ACCESS.getToken());
+ code.append(JSAMDEmitterTokens.LENGTH.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.LESS_THAN.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(len);
+ code.append(ASEmitterTokens.PAREN_CLOSE.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.BLOCK_OPEN.getToken());
+
+ write(code.toString());
+
+ indentPush();
+ writeNewline();
+ }
+ len--;
+ }
+
+ Collections.reverse(parameters);
+ for (int i = 0, n = parameters.size(); i < n; i++)
+ {
+ IParameterNode pnode = parameters.get(i);
+
+ if (pnode != null)
+ {
+ code.setLength(0);
+
+ code.append(pnode.getName());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.EQUAL.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(pnode.getDefaultValue());
+ code.append(ASEmitterTokens.SEMICOLON.getToken());
+ write(code.toString());
+
+ indentPop();
+ writeNewline();
+
+ write(ASEmitterTokens.BLOCK_CLOSE);
+
+ if (i == n - 1 && !hasBody)
+ indentPop();
+
+ writeNewline();
+ }
+ }
+ }
+ }
+
+ @Override
+ public void emitParameter(IParameterNode node)
+ {
+ getWalker().walk(node.getNameExpressionNode());
+ }
+
+ @Override
+ public void emitMemberAccessExpression(IMemberAccessExpressionNode node)
+ {
+ getWalker().walk(node.getLeftOperandNode());
+ if (!(node.getLeftOperandNode() instanceof ILanguageIdentifierNode))
+ write(node.getOperator().getOperatorText());
+ getWalker().walk(node.getRightOperandNode());
+ }
+
+ @Override
+ public void emitFunctionCall(IFunctionCallNode node)
+ {
+ if (node.isNewExpression())
+ {
+ write(ASEmitterTokens.NEW);
+ write(ASEmitterTokens.SPACE);
+ }
+ // IDefinition resolve = node.resolveType(project);
+ // if (NativeUtils.isNative(resolve.getBaseName()))
+ // {
+ //
+ // }
+
+ getWalker().walk(node.getNameNode());
+
+ write(ASEmitterTokens.PAREN_OPEN);
+ walkArguments(node);
+ write(ASEmitterTokens.PAREN_CLOSE.getToken());
+ }
+
+ @Override
+ protected void walkArguments(IExpressionNode[] nodes)
+ {
+ }
+
+ protected void walkArguments(IFunctionCallNode node)
+ {
+ FunctionCallNode fnode = (FunctionCallNode) node;
+ IExpressionNode[] nodes = node.getArgumentNodes();
+ int len = nodes.length;
+ if (TempTools.injectThisArgument(fnode, false))
+ {
+ write("this");
+ if (len > 0)
+ {
+ write(",");
+ write(" ");
+ }
+ }
+
+ for (int i = 0; i < len; i++)
+ {
+ IExpressionNode inode = nodes[i];
+ if (inode.getNodeID() == ASTNodeID.IdentifierID)
+ {
+ emitArgumentIdentifier((IIdentifierNode) inode);
+ }
+ else
+ {
+ getWalker().walk(inode);
+ }
+
+ if (i < len - 1)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ }
+ }
+ }
+
+ private void emitArgumentIdentifier(IIdentifierNode node)
+ {
+ ITypeDefinition type = node.resolveType(getWalker().getProject());
+ if (type instanceof ClassTraitsDefinition)
+ {
+ String qualifiedName = type.getQualifiedName();
+ write(qualifiedName);
+ }
+ else
+ {
+ // XXX A problem?
+ getWalker().walk(node);
+ }
+ }
+
+ @Override
+ public void emitIdentifier(IIdentifierNode node)
+ {
+ ICompilerProject project = getWalker().getProject();
+
+ IDefinition resolve = node.resolve(project);
+ if (TempTools.isBinding(node, project))
+ {
+ // AS3.bind( this,"secret$1");
+ // this will happen on the right side of the = sign to bind a methof/function
+ // to a variable
+
+ write("AS3.bind(this, \"" + toPrivateName(resolve) + "\")");
+ }
+ else
+ {
+ IExpressionNode leftBase = TempTools.getNode(node, false, project);
+ if (leftBase == node)
+ {
+ if (TempTools.isValidThis(node, project))
+ write("this.");
+ // in constructor and a type
+ if (initializingFieldsInConstructor
+ && resolve instanceof IClassDefinition)
+ {
+ String name = resolve.getBaseName();
+ write("(" + name + "._ || " + name + "._$get())");
+ return;
+ }
+ }
+
+ if (resolve != null)
+ {
+ // TODO (mschmalle|AMD) optimize
+ String name = toPrivateName(resolve);
+ if (NativeUtils.isNative(name))
+ exportWriter.addDependency(name, name, true, false);
+
+ if (node.getParent() instanceof IMemberAccessExpressionNode)
+ {
+ IMemberAccessExpressionNode mnode = (IMemberAccessExpressionNode) node
+ .getParent();
+ if (mnode.getLeftOperandNode().getNodeID() == ASTNodeID.SuperID)
+ {
+ IIdentifierNode lnode = (IIdentifierNode) mnode
+ .getRightOperandNode();
+
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
+
+ initializeInheritenceLevel(cnode.getDefinition());
+
+ // super.foo();
+ write("this.");
+
+ write(lnode.getName() + "$" + inheritenceLevel);
+
+ baseClassCalls.add(resolve);
+
+ return;
+ }
+ }
+ write(name);
+ }
+ else
+ {
+ // no definition, just plain ole identifer
+ write(node.getName());
+ }
+ }
+ }
+
+ @Override
+ protected void emitType(IExpressionNode node)
+ {
+ }
+
+ @Override
+ public void emitLanguageIdentifier(ILanguageIdentifierNode node)
+ {
+ if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.ANY_TYPE)
+ {
+ write("");
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.REST)
+ {
+ write("");
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.SUPER)
+ {
+ IIdentifierNode inode = (IIdentifierNode) node;
+ if (inode.getParent() instanceof IMemberAccessExpressionNode)
+ {
+
+ }
+ else
+ {
+ write("Super.call");
+ }
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS)
+ {
+ write("");
+ }
+ else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.VOID)
+ {
+ write("");
+ }
+ }
+
+ private String toPrivateName(IDefinition definition)
+ {
+ if (definition instanceof ITypeDefinition)
+ return definition.getBaseName();
+ if (!definition.isPrivate())
+ return definition.getBaseName();
+
+ initializeInheritenceLevel(definition);
+
+ return definition.getBaseName() + "$" + inheritenceLevel;
+ }
+
+ void initializeInheritenceLevel(IDefinition definition)
+ {
+ if (inheritenceLevel != -1)
+ return;
+
+ IClassDefinition cdefinition = null;
+ if (definition instanceof IClassDefinition)
+ cdefinition = (IClassDefinition) definition;
+ else
+ cdefinition = (IClassDefinition) definition
+ .getAncestorOfType(IClassDefinition.class);
+
+ ICompilerProject project = getWalker().getProject();
+ IClassDefinition[] ancestry = cdefinition.resolveAncestry(project);
+ inheritenceLevel = ancestry.length - 1;
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java Tue Mar 5 19:22:05 2013
@@ -0,0 +1,20 @@
+package org.apache.flex.compiler.internal.codegen.js.amd;
+
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+
+public enum JSAMDEmitterTokens implements IEmitterTokens
+{
+ DEFINE("define"), LENGTH("length"), ;
+
+ private String token;
+
+ private JSAMDEmitterTokens(String value)
+ {
+ token = value;
+ }
+
+ public String getToken()
+ {
+ return token;
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitterTokens.java
------------------------------------------------------------------------------
svn:eol-style = native