http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDDocEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDDocEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDDocEmitter.java new file mode 100644 index 0000000..02eb3cb --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDDocEmitter.java @@ -0,0 +1,40 @@ +/* + * + * 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.codegen.js.amd; + +import org.apache.flex.compiler.codegen.js.IJSDocEmitter; + +/** + * The {@link IJSAMDDocEmitter} interface allows the abstraction of JavaScript + * document comments to be emitted per tag. + * <p> + * The purpose of the API is to clamp emitted output to JavaScript doc tags. The + * output can be multiline but is specific to one tag. This allows a full + * comment to be created without worrying about how to assemble the tags. + * <p> + * TODO (mschmalle) Might make a comment API and tag API so comments are not + * dependent on tag creation IE IJSDocEmitter and IJSDocTagEmitter + * + * @author Michael Schmalle + */ +public interface IJSAMDDocEmitter extends IJSDocEmitter +{ + +}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDEmitter.java new file mode 100644 index 0000000..2e117e6 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/amd/IJSAMDEmitter.java @@ -0,0 +1,33 @@ +/* + * + * 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.codegen.js.amd; + +import org.apache.flex.compiler.codegen.js.IJSEmitter; + +/** + * The {@link IJSAMDEmitter} interface allows abstraction between the base + * JavaScript and the AMD specific IJSAMDEmitter. + * + * @author Michael Schmalle + */ +public interface IJSAMDEmitter extends IJSEmitter +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSEmitter.java new file mode 100644 index 0000000..038c5ce --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/flexjs/IJSFlexJSEmitter.java @@ -0,0 +1,30 @@ +/* + * + * 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.codegen.js.flexjs; + +import org.apache.flex.compiler.codegen.js.goog.IJSGoogEmitter; + +/** + * @author Erik de Bruin + */ +public interface IJSFlexJSEmitter extends IJSGoogEmitter +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogDocEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogDocEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogDocEmitter.java new file mode 100644 index 0000000..7b433cd --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogDocEmitter.java @@ -0,0 +1,140 @@ +/* + * + * 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.codegen.js.goog; + +import org.apache.flex.compiler.codegen.js.IJSDocEmitter; +import org.apache.flex.compiler.definitions.IClassDefinition; +import org.apache.flex.compiler.definitions.IDefinition; +import org.apache.flex.compiler.definitions.ITypeDefinition; +import org.apache.flex.compiler.projects.ICompilerProject; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IDefinitionNode; +import org.apache.flex.compiler.tree.as.IFunctionNode; +import org.apache.flex.compiler.tree.as.IInterfaceNode; +import org.apache.flex.compiler.tree.as.IParameterNode; +import org.apache.flex.compiler.tree.as.IVariableNode; + +/** + * The {@link IJSGoogDocEmitter} interface allows the abstraction of JavaScript + * document comments to be emitted per tag. + * <p> + * The purpose of the API is to clamp emitted output to JavaScript doc tags. The + * output can be multiline but is specific to one tag. This allows a full + * comment to be created without worrying about how to assemble the tags. + * <p> + * The current tags were found at + * https://developers.google.com/closure/compiler/docs/js-for-compiler#types + * <p> + * TODO (mschmalle) Might make a comment API and tag API so comments are not + * dependent on tag creation IE IJSDocEmitter and IJSDocTagEmitter + * + * @author Michael Schmalle + */ +public interface IJSGoogDocEmitter extends IJSDocEmitter +{ + + void emitInterfaceDoc(IInterfaceNode node, ICompilerProject project); + + void emitInterfaceMemberDoc(IDefinitionNode node, ICompilerProject project); + + void emitFieldDoc(IVariableNode node, IDefinition def, ICompilerProject project); + + void emitMethodDoc(IFunctionNode node, ICompilerProject project); + + void emitVarDoc(IVariableNode node, IDefinition def, ICompilerProject project); + + /* + * https://developers.google.com/closure/compiler/docs/js-for-compiler#types + *- @const - Marks a variable as read-only. The compiler can inline @const variables + * + *- @define - Indicates a constant that can be overridden by the compiler at compile-time. + * + * @deprecated - Warns against using the marked function, method, or property should not be used. + * + *- @enum - Specifies the type of an enum. An enum is an object whose properties constitute a + * set of related constants. The @enum tag must be followed by a type expression. + * + * @export - Declares an exported property. Exported properties will have an alias set up so + * they can be accessed via [] syntax. + * + *- @extends - Marks a class or interface as inheriting from another class. A class marked + * with @extends must also be marked with either @constructor or @interface. + * + *- @implements - Used with @constructor to indicate that a class implements an interface. + * + *- @inheritDoc - tag implies the @override tag. has exactly the same documentation. + * + * @interface - Marks a function as an interface. + * + * @lends + * + * @license|@preserve - Tells the compiler to insert the associated comment before the compiled + * code for the marked file. + * + * @nosideeffects - Indicates that a call to the declared function has no side effects + * + *- @override - Indicates that a method or property of a subclass intentionally hides a method or + * property of the superclass. + * + * @param - Used with method, function and constructor definitions to specify the types of function + * arguments. + * + * @private - Marks a member as private. Only code in the same file can access global variables and + * functions marked @private. Constructors marked @private can only be instantiated by code + * in the same file and by their static and instance members. + * + * @protected - Indicates that a member or property is protected. + * + * @return - Specifies the return types of method and function definitions. The @return tag must be + * followed by a type expression. + * + * @this - Specifies the type of the object to which the keyword this refers within a function. + * The @this tag must be followed by a type expression. + * + * @type - Identifies the type of a variable, property, or expression. The @type tag must be + * followed by a type expression. + * + * @typedef - Declares an alias for a more complex type. + */ + + void emitConst(IVariableNode node); + + void emitExtends(IClassDefinition superDefinition, String packageName); + + void emitImplements(ITypeDefinition definition, String packageName); + + void emitOverride(IFunctionNode node); + + void emitParam(IParameterNode node, String packageName); + + void emitPublic(IASNode node); + + void emitPrivate(IASNode node); + + void emitProtected(IASNode node); + + void emitReturn(IFunctionNode node, String packageName); + + void emitThis(ITypeDefinition node, String packageName); + + void emitType(IASNode node, String packageName); + + void emitType(String type, String packageName); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogEmitter.java new file mode 100644 index 0000000..5e5bd50 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/goog/IJSGoogEmitter.java @@ -0,0 +1,33 @@ +/* + * + * 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.codegen.js.goog; + +import org.apache.flex.compiler.codegen.js.IJSEmitter; + +/** + * The {@link IJSGoogEmitter} interface allows abstraction between the base + * JavaScript and the 'goog' specific IJSGoogEmitter. + * + * @author Michael Schmalle + */ +public interface IJSGoogEmitter extends IJSEmitter +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/vf2js/IJSVF2JSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/vf2js/IJSVF2JSEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/vf2js/IJSVF2JSEmitter.java new file mode 100644 index 0000000..cd4cacd --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/js/vf2js/IJSVF2JSEmitter.java @@ -0,0 +1,30 @@ +/* + * + * 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.codegen.js.vf2js; + +import org.apache.flex.compiler.codegen.js.goog.IJSGoogEmitter; + +/** + * @author Erik de Bruin + */ +public interface IJSVF2JSEmitter extends IJSGoogEmitter +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java new file mode 100644 index 0000000..a8dc6dc --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java @@ -0,0 +1,140 @@ +/* + * + * 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.codegen.mxml; + +import java.io.Writer; + +import org.apache.flex.compiler.codegen.IEmitter; +import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode; +import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode; +import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode; +import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDataBindingNode; +import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode; +import org.apache.flex.compiler.tree.mxml.IMXMLEmbedNode; +import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLFactoryNode; +import org.apache.flex.compiler.tree.mxml.IMXMLFileNode; +import org.apache.flex.compiler.tree.mxml.IMXMLImplementsNode; +import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode; +import org.apache.flex.compiler.tree.mxml.IMXMLIntNode; +import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode; +import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode; +import org.apache.flex.compiler.tree.mxml.IMXMLNumberNode; +import org.apache.flex.compiler.tree.mxml.IMXMLObjectNode; +import org.apache.flex.compiler.tree.mxml.IMXMLPropertySpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStringNode; +import org.apache.flex.compiler.tree.mxml.IMXMLStyleSpecifierNode; +import org.apache.flex.compiler.tree.mxml.IMXMLUintNode; +import org.apache.flex.compiler.tree.mxml.IMXMLVectorNode; +import org.apache.flex.compiler.visitor.IASNodeStrategy; +import org.apache.flex.compiler.visitor.IBlockWalker; + +/** + * The {@link IMXMLEmitter} interface allows abstraction between the + * {@link IASNodeStrategy} and the current output buffer {@link Writer}. + * + * @author Michael Schmalle + * @author Erik de Bruin + */ +public interface IMXMLEmitter extends IEmitter +{ + + IBlockWalker getMXMLWalker(); + + String postProcess(String output); + + void setMXMLWalker(IBlockWalker mxmlBlockWalker); + + //-------------------------------------------------------------------------- + + void emitDocumentHeader(IMXMLFileNode node); + + void emitDocumentFooter(IMXMLFileNode node); + + //-------------------------------------------------------------------------- + + void emitClass(IMXMLClassDefinitionNode node); + + //-------------------------------------------------------------------------- + + void emitEventSpecifier(IMXMLEventSpecifierNode node); + + void emitInstance(IMXMLInstanceNode node); + + void emitPropertySpecifier(IMXMLPropertySpecifierNode node); + + void emitScript(IMXMLScriptNode node); + + void emitStyleSpecifier(IMXMLStyleSpecifierNode node); + + //-------------------------------------------------------------------------- + + void emitArray(IMXMLArrayNode node); + + void emitBoolean(IMXMLBooleanNode node); + + void emitInt(IMXMLIntNode node); + + void emitNumber(IMXMLNumberNode node); + + void emitObject(IMXMLObjectNode node); + + void emitString(IMXMLStringNode node); + + void emitUint(IMXMLUintNode node); + + //-------------------------------------------------------------------------- + + void emitLiteral(IMXMLLiteralNode node); + + //-------------------------------------------------------------------------- + + void emitPropertySpecifiers(IMXMLPropertySpecifierNode[] nodes, + boolean emitAttributes); + + void emitFactory(IMXMLFactoryNode node); + + void emitComponent(IMXMLComponentNode node); + + void emitDeclarations(IMXMLDeclarationsNode node); + + //-------------------------------------------------------------------------- + + void emitMetadata(IMXMLMetadataNode node); + + //-------------------------------------------------------------------------- + + void emitEmbed(IMXMLEmbedNode node); + + //-------------------------------------------------------------------------- + + void emitImplements(IMXMLImplementsNode node); + + //-------------------------------------------------------------------------- + + void emitVector(IMXMLVectorNode node); + + //-------------------------------------------------------------------------- + + void emitDatabinding(IMXMLDataBindingNode node); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/flexjs/IMXMLFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/flexjs/IMXMLFlexJSEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/flexjs/IMXMLFlexJSEmitter.java new file mode 100644 index 0000000..333aa00 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/codegen/mxml/flexjs/IMXMLFlexJSEmitter.java @@ -0,0 +1,39 @@ +/* + * + * 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.codegen.mxml.flexjs; + +import java.io.Writer; + +import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter; +import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode; +import org.apache.flex.compiler.visitor.IASNodeStrategy; + +/** + * The {@link IMXMLFlexJSEmitter} interface allows abstraction between the + * {@link IASNodeStrategy} and the current output buffer {@link Writer}. + * + * @author Erik de Bruin + */ +public interface IMXMLFlexJSEmitter extends IMXMLEmitter +{ + + void emitDocument(IMXMLDocumentNode node); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IApplication.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IApplication.java b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IApplication.java new file mode 100644 index 0000000..3654806 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IApplication.java @@ -0,0 +1,31 @@ +/* + * + * 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.driver; + +/** + * The ActionScript model interface used when implementing build targets that + * create javascript applications cross compiled from actionscript. + * + * @author Michael Schmalle + */ +public interface IApplication +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IBackend.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IBackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IBackend.java new file mode 100644 index 0000000..4ec1fa7 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IBackend.java @@ -0,0 +1,124 @@ +/* + * + * 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.driver; + +import java.io.File; +import java.io.FilterWriter; +import java.util.List; + +import org.apache.flex.compiler.clients.MXMLJSC; +import org.apache.flex.compiler.codegen.IDocEmitter; +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.codegen.as.IASWriter; +import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter; +import org.apache.flex.compiler.config.Configuration; +import org.apache.flex.compiler.config.Configurator; +import org.apache.flex.compiler.internal.codegen.as.ASFilterWriter; +import org.apache.flex.compiler.internal.projects.ISourceFileHandler; +import org.apache.flex.compiler.internal.targets.JSTarget; +import org.apache.flex.compiler.problems.ICompilerProblem; +import org.apache.flex.compiler.projects.IASProject; +import org.apache.flex.compiler.projects.ICompilerProject; +import org.apache.flex.compiler.targets.ITarget; +import org.apache.flex.compiler.targets.ITargetProgressMonitor; +import org.apache.flex.compiler.targets.ITargetSettings; +import org.apache.flex.compiler.units.ICompilationUnit; +import org.apache.flex.compiler.visitor.IBlockWalker; +import org.apache.flex.compiler.visitor.as.IASBlockWalker; +import org.apache.flex.compiler.visitor.mxml.IMXMLBlockWalker; + +/** + * The backend strategy for the {@link MXMLJSC} javascript compiler. + * + * @author Michael Schmalle + */ +public interface IBackend +{ + + /** + * Returns the instance that is used to manage what type of + * {@link ICompilationUnit} is created during parsing. + * + * @return The implemented {@link ISourceFileHandler}. + */ + ISourceFileHandler getSourceFileHandlerInstance(); + + /** + * Returns the {@link File} extension used when saving compiled code. + */ + String getOutputExtension(); + + /** + * Creates a {@link Configurator} for the specific compile session. + */ + Configurator createConfigurator(); + + /** + * Creates a javascript target that will be used to build the compiled + * javascript source file. + * + * @param project The current {@link ICompilerProject}. + * @param settings The target's custom settings. + * @param monitor The compilation monitor used during asynchronous parsing + * of {@link ICompilationUnit}s. + * @return A new {@link JSTarget} used during compilation. + */ + ITarget createTarget(IASProject project, ITargetSettings settings, + ITargetProgressMonitor monitor); + + IDocEmitter createDocEmitter(IASEmitter emitter); + + IASEmitter createEmitter(FilterWriter writer); + + IMXMLEmitter createMXMLEmitter(FilterWriter writer); + + ASFilterWriter createWriterBuffer(IASProject project); + + IASWriter createWriter(IASProject project, List<ICompilerProblem> errors, + ICompilationUnit compilationUnit, boolean enableDebug); + + IASWriter createMXMLWriter(IASProject project, + List<ICompilerProblem> errors, ICompilationUnit compilationUnit, + boolean enableDebug); + + IASBlockWalker createWalker(IASProject project, + List<ICompilerProblem> errors, IASEmitter emitter); + + IPublisher createPublisher(IASProject project, + List<ICompilerProblem> errors, Configuration config); + + /** + * Creates an AST walker capable of traversing MXML AST and calling back to + * the {@link IASBlockWalker} for ActionScript source code production. + * <p> + * Use the {@link #createWalker(IASProject, List, ASFilterWriter)} method + * first and pass that instance into this method's <code>walker</code> + * parameter. + * + * @param project The current {@link IASProject}. + * @param errors The current {@link ICompilerProblem} list. + * @param emitter The current {@link IASEmitter} that is used for it's + * emitter and is available for callbacks to it's visit methods. + */ + IMXMLBlockWalker createMXMLWalker(IASProject project, + List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter, + IASEmitter asEmitter, IBlockWalker asBlockWalker); + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IPublisher.java new file mode 100644 index 0000000..a2535bd --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/IPublisher.java @@ -0,0 +1,25 @@ +/* + * + * 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.driver; + +public interface IPublisher +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSApplication.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSApplication.java b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSApplication.java new file mode 100644 index 0000000..c61aa90 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSApplication.java @@ -0,0 +1,33 @@ +/* + * + * 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.driver.js; + +import org.apache.flex.compiler.driver.IApplication; + +/** + * The JavaScript model interface used when implementing build targets that + * create javascript applications cross compiled from actionscript. + * + * @author Michael Schmalle + */ +public interface IJSApplication extends IApplication +{ + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSBackend.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSBackend.java b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSBackend.java new file mode 100644 index 0000000..eb0f4e2 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/driver/js/IJSBackend.java @@ -0,0 +1,29 @@ +/* + * + * 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.driver.js; + +import org.apache.flex.compiler.codegen.ISourceMapEmitter; +import org.apache.flex.compiler.codegen.js.IJSEmitter; +import org.apache.flex.compiler.driver.IBackend; + +public interface IJSBackend extends IBackend +{ + ISourceMapEmitter createSourceMapEmitter(IJSEmitter emitter); +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/Emitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/Emitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/Emitter.java new file mode 100644 index 0000000..c399d73 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/Emitter.java @@ -0,0 +1,235 @@ +/* + * + * 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; + +import java.io.FilterWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.flex.compiler.codegen.IEmitter; +import org.apache.flex.compiler.codegen.IEmitterTokens; +import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens; +import org.apache.flex.compiler.problems.ICompilerProblem; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.visitor.as.IASBlockWalker; + +/** + * The base implementation for an ActionScript emitter. + * + * @author Michael Schmalle + */ +public class Emitter implements IEmitter +{ + private final FilterWriter out; + + private boolean bufferWrite; + + protected boolean isBufferWrite() + { + return bufferWrite; + } + + protected void setBufferWrite(boolean value) + { + bufferWrite = value; + } + + private StringBuilder builder; + + protected StringBuilder getBuilder() + { + return builder; + } + + protected void flushBuilder() + { + setBufferWrite(false); + write(builder.toString()); + builder.setLength(0); + } + + protected List<ICompilerProblem> problems; + + // (mschmalle) think about how this should be implemented, we can add our + // own problems to this, they don't just have to be parse problems + public List<ICompilerProblem> getProblems() + { + return problems; + } + + // private IDocEmitter docEmitter; + // + // @Override + // public IDocEmitter getDocEmitter() + // { + // return docEmitter; + // } + // + // @Override + // public void setDocEmitter(IDocEmitter value) + // { + // docEmitter = value; + // } + + private int currentIndent = 0; + + protected int getCurrentIndent() + { + return currentIndent; + } + + private IASBlockWalker walker; + + public IASBlockWalker getWalker() + { + return walker; + } + + public void setWalker(IASBlockWalker value) + { + walker = value; + } + + public Emitter(FilterWriter out) + { + this.out = out; + builder = new StringBuilder(); + problems = new ArrayList<ICompilerProblem>(); + } + + @Override + public void write(IEmitterTokens value) + { + write(value.getToken()); + } + + @Override + public void write(String value) + { + try + { + if (!bufferWrite) + out.write(value); + else + builder.append(value); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + + protected String getIndent(int numIndent) + { + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < numIndent; i++) + sb.append(ASEmitterTokens.INDENT.getToken()); + return sb.toString(); + } + + @Override + public void indentPush() + { + currentIndent++; + } + + @Override + public void indentPop() + { + if (currentIndent > 0) + currentIndent--; + } + + @Override + public void writeNewline() + { + write(ASEmitterTokens.NEW_LINE); + write(getIndent(currentIndent)); + } + + @Override + public void writeNewline(IEmitterTokens value) + { + writeNewline(value.getToken()); + } + + @Override + public void writeNewline(String value) + { + write(value); + writeNewline(); + } + + @Override + public void writeNewline(IEmitterTokens value, boolean pushIndent) + { + writeNewline(value.getToken(), pushIndent); + } + + @Override + public void writeNewline(String value, boolean pushIndent) + { + if (pushIndent) + indentPush(); + else + indentPop(); + write(value); + writeNewline(); + } + + public void writeSymbol(String value) + { + write(value); + } + + @Override + public void writeToken(IEmitterTokens value) + { + writeToken(value.getToken()); + } + + @Override + public void writeToken(String value) + { + write(value); + write(ASEmitterTokens.SPACE); + } + + /** + * Takes the node argument and created a String representation if it using + * the buffer temporarily. + * <p> + * Note; This method is still beta, it need more logic if an emitter is + * actually using the buffer! + * + * @param node The node walk and create a String for. + * @return The node's output. + */ + public String stringifyNode(IASNode node) + { + setBufferWrite(true); + getWalker().walk(node); + String result = getBuilder().toString(); + getBuilder().setLength(0); + setBufferWrite(false); + return result; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java new file mode 100644 index 0000000..1ac85f7 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java @@ -0,0 +1,77 @@ +/* + * + * 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.IEmitter; +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.codegen.js.IJSEmitter; +import org.apache.flex.compiler.tree.ASTNodeID; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType; +import org.apache.flex.compiler.visitor.IASNodeStrategy; + +/** + * A concrete implementation of the {@link IASNodeStrategy} that allows + * {@link IASNode} processing after the current node handler. + * <p> + * The class has access to the current {@link IJSEmitter} instance being used to + * output source code to the current output buffer. + * + * @author Michael Schmalle + */ +public class ASAfterNodeStrategy implements IASNodeStrategy +{ + private final IASEmitter emitter; + + public ASAfterNodeStrategy(IASEmitter emitter) + { + this.emitter = emitter; + } + + @Override + public void handle(IASNode node) + { + if (node.getNodeID() == ASTNodeID.BlockID) + { + IContainerNode container = (IContainerNode) node; + ContainerType type = container.getContainerType(); + if (type != ContainerType.IMPLICIT + && type != ContainerType.SYNTHESIZED) + { + if (node.getChildCount() != 0) + { + emitter.indentPop(); + ((IEmitter) emitter).writeNewline(); + } + + ((IEmitter) emitter).write(ASEmitterTokens.BLOCK_CLOSE); + } + else if (type == ContainerType.IMPLICIT + || type == ContainerType.SYNTHESIZED) + { + if (node.getChildCount() != 0) + { + emitter.indentPop(); + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java new file mode 100644 index 0000000..d481573 --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java @@ -0,0 +1,74 @@ +/* + * + * 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.IEmitter; +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.tree.ASTNodeID; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType; +import org.apache.flex.compiler.visitor.IASNodeStrategy; + +/** + * A concrete implementation of the {@link IASNodeStrategy} that allows + * {@link IASNode} processing before the current node handler. + * + * @author Michael Schmalle + */ +public class ASBeforeNodeStrategy implements IASNodeStrategy +{ + private final IASEmitter emitter; + + public ASBeforeNodeStrategy(IASEmitter emitter) + { + this.emitter = emitter; + } + + @Override + public void handle(IASNode node) + { + if (node.getNodeID() == ASTNodeID.BlockID) + { + IASNode parent = node.getParent(); + IContainerNode container = (IContainerNode) node; + ContainerType type = container.getContainerType(); + + if (parent.getNodeID() != ASTNodeID.LabledStatementID) + { + if (node.getChildCount() != 0) + emitter.indentPush(); + } + + // switch cases are SYNTHESIZED + if (type != ContainerType.IMPLICIT + && type != ContainerType.SYNTHESIZED) + { + ((IEmitter) emitter).write(ASEmitterTokens.BLOCK_OPEN); + } + + if (parent.getNodeID() != ASTNodeID.LabledStatementID) + { + ((IEmitter) emitter).writeNewline(); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java new file mode 100644 index 0000000..aa29f4d --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java @@ -0,0 +1,660 @@ +/* + * + * 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.util.List; + +import org.apache.flex.compiler.codegen.as.IASEmitter; +import org.apache.flex.compiler.definitions.IPackageDefinition; +import org.apache.flex.compiler.internal.semantics.SemanticUtils; +import org.apache.flex.compiler.internal.tree.as.LabeledStatementNode; +import org.apache.flex.compiler.problems.ICompilerProblem; +import org.apache.flex.compiler.projects.IASProject; +import org.apache.flex.compiler.tree.ASTNodeID; +import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IBinaryOperatorNode; +import org.apache.flex.compiler.tree.as.IBlockNode; +import org.apache.flex.compiler.tree.as.ICatchNode; +import org.apache.flex.compiler.tree.as.IClassNode; +import org.apache.flex.compiler.tree.as.IContainerNode; +import org.apache.flex.compiler.tree.as.IDefaultXMLNamespaceNode; +import org.apache.flex.compiler.tree.as.IDynamicAccessNode; +import org.apache.flex.compiler.tree.as.IEmbedNode; +import org.apache.flex.compiler.tree.as.IExpressionNode; +import org.apache.flex.compiler.tree.as.IFileNode; +import org.apache.flex.compiler.tree.as.IForLoopNode; +import org.apache.flex.compiler.tree.as.IForLoopNode.ForLoopKind; +import org.apache.flex.compiler.tree.as.IFunctionCallNode; +import org.apache.flex.compiler.tree.as.IFunctionNode; +import org.apache.flex.compiler.tree.as.IFunctionObjectNode; +import org.apache.flex.compiler.tree.as.IGetterNode; +import org.apache.flex.compiler.tree.as.IIdentifierNode; +import org.apache.flex.compiler.tree.as.IIfNode; +import org.apache.flex.compiler.tree.as.IImportNode; +import org.apache.flex.compiler.tree.as.IInterfaceNode; +import org.apache.flex.compiler.tree.as.IIterationFlowNode; +import org.apache.flex.compiler.tree.as.IKeywordNode; +import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode; +import org.apache.flex.compiler.tree.as.ILiteralContainerNode; +import org.apache.flex.compiler.tree.as.ILiteralNode; +import org.apache.flex.compiler.tree.as.ILiteralNode.LiteralType; +import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode; +import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode; +import org.apache.flex.compiler.tree.as.INamespaceNode; +import org.apache.flex.compiler.tree.as.INumericLiteralNode; +import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode; +import org.apache.flex.compiler.tree.as.IPackageNode; +import org.apache.flex.compiler.tree.as.IParameterNode; +import org.apache.flex.compiler.tree.as.IReturnNode; +import org.apache.flex.compiler.tree.as.ISetterNode; +import org.apache.flex.compiler.tree.as.ISwitchNode; +import org.apache.flex.compiler.tree.as.ITerminalNode; +import org.apache.flex.compiler.tree.as.ITernaryOperatorNode; +import org.apache.flex.compiler.tree.as.IThrowNode; +import org.apache.flex.compiler.tree.as.ITryNode; +import org.apache.flex.compiler.tree.as.ITypedExpressionNode; +import org.apache.flex.compiler.tree.as.IUnaryOperatorNode; +import org.apache.flex.compiler.tree.as.IUseNamespaceNode; +import org.apache.flex.compiler.tree.as.IVariableExpressionNode; +import org.apache.flex.compiler.tree.as.IVariableNode; +import org.apache.flex.compiler.tree.as.IWhileLoopNode; +import org.apache.flex.compiler.tree.as.IWhileLoopNode.WhileLoopKind; +import org.apache.flex.compiler.tree.as.IWithNode; +import org.apache.flex.compiler.tree.metadata.IMetaTagNode; +import org.apache.flex.compiler.tree.metadata.IMetaTagsNode; +import org.apache.flex.compiler.units.ICompilationUnit; +import org.apache.flex.compiler.utils.DefinitionUtils; +import org.apache.flex.compiler.visitor.IASNodeStrategy; +import org.apache.flex.compiler.visitor.as.IASBlockVisitor; +import org.apache.flex.compiler.visitor.as.IASBlockWalker; + +/** + * A base implementation of the {@link IASBlockVisitor} that will walk the + * {@link ICompilationUnit}s AST {@link IASNode} hierarchy. + * + * @author Michael Schmalle + */ +public class ASBlockWalker implements IASBlockVisitor, IASBlockWalker +{ + boolean isDebug; + + private IASEmitter emitter; + + @Override + public IASEmitter getEmitter() + { + return emitter; + } + + private final List<ICompilerProblem> errors; + + public List<ICompilerProblem> getErrors() + { + return errors; + } + + //---------------------------------- + // strategy + //---------------------------------- + + private IASNodeStrategy strategy; + + public IASNodeStrategy getStrategy() + { + return strategy; + } + + public void setStrategy(IASNodeStrategy value) + { + strategy = value; + } + + //---------------------------------- + // project + //---------------------------------- + + private IASProject project; + + @Override + public IASProject getProject() + { + return project; + } + + public ASBlockWalker(List<ICompilerProblem> errors, IASProject project, + IASEmitter emitter) + { + this.errors = errors; + this.project = project; + this.emitter = emitter; + emitter.setWalker(this); + } + + //-------------------------------------------------------------------------- + // File level + //-------------------------------------------------------------------------- + + @Override + public void walk(IASNode node) + { + getStrategy().handle(node); + } + + @Override + public void visitCompilationUnit(ICompilationUnit unit) + { + debug("visitCompilationUnit()"); + IFileNode node = null; + try + { + node = (IFileNode) unit.getSyntaxTreeRequest().get().getAST(); + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + + walk(node); + } + + @Override + public void visitFile(IFileNode node) + { + debug("visitFile()"); + + boolean foundPackage = false; + int nodeCount = node.getChildCount(); + for (int i = 0; i < nodeCount; i++) + { + IASNode pnode = node.getChild(i); + + // ToDo (erikdebruin): handle other types of root node, such as when + // there is no wrapping Package or Class, like + // in mx.core.Version + if (pnode != null) + { + boolean isPackage = pnode instanceof IPackageNode; + boolean isAllowedAfterPackage = false; + if(isPackage) + { + foundPackage = true; + } + else if(foundPackage) + { + isAllowedAfterPackage = pnode instanceof IInterfaceNode + || pnode instanceof IClassNode + || pnode instanceof IFunctionNode + || pnode instanceof INamespaceNode + || pnode instanceof IVariableNode; + } + if(isPackage || isAllowedAfterPackage) + { + walk(pnode); + + if (i < nodeCount - 1) + { + emitter.writeNewline(); + emitter.writeNewline(); + emitter.writeNewline(); + } + } + } + } + } + + @Override + public void visitPackage(IPackageNode node) + { + debug("visitPackage()"); + IPackageDefinition definition = (IPackageDefinition) node + .getDefinition(); + emitter.emitPackageHeader(definition); + emitter.emitPackageHeaderContents(definition); + emitter.emitPackageContents(definition); + emitter.emitPackageFooter(definition); + } + + //-------------------------------------------------------------------------- + // Type level + //-------------------------------------------------------------------------- + + @Override + public void visitClass(IClassNode node) + { + debug("visitClass()"); + emitter.emitClass(node); + } + + @Override + public void visitInterface(IInterfaceNode node) + { + debug("visitInterface()"); + emitter.emitInterface(node); + } + + @Override + public void visitVariable(IVariableNode node) + { + debug("visitVariable()"); + if (SemanticUtils.isPackageDefinition(node.getDefinition()) || + SemanticUtils.isMemberDefinition(node.getDefinition()) || + node.getParent() instanceof IFileNode) + { + emitter.emitField(node); + } + else + { + emitter.emitVarDeclaration(node); + } + } + + @Override + public void visitFunction(IFunctionNode node) + { + debug("visitFunction()"); + if (SemanticUtils.isPackageDefinition(node.getDefinition()) || + DefinitionUtils.isMemberDefinition(node.getDefinition()) || + node.getParent() instanceof IFileNode) + { + emitter.emitMethod(node); + } + else + { + emitter.emitLocalNamedFunction(node); + } + } + + @Override + public void visitParameter(IParameterNode node) + { + debug("visitParameter()"); + emitter.emitParameter(node); + } + + @Override + public void visitGetter(IGetterNode node) + { + debug("visitGetter()"); + emitter.emitGetAccessor(node); + } + + @Override + public void visitSetter(ISetterNode node) + { + debug("visitSetter()"); + emitter.emitSetAccessor(node); + } + + @Override + public void visitNamespace(INamespaceNode node) + { + debug("visitNamespace()"); + emitter.emitNamespace(node); + } + + @Override + public void visitFunctionCall(IFunctionCallNode node) + { + debug("visitFunctionCall()"); + emitter.emitFunctionCall(node); + } + + @Override + public void visitBlock(IBlockNode node) + { + debug("visitBlock()"); + ASTNodeID pnodeId = node.getParent().getNodeID(); + // (erikdebruin) 'goog' also needs access to the block header for + // accessor function blocks + if (pnodeId == ASTNodeID.FunctionID || pnodeId == ASTNodeID.GetterID + || pnodeId == ASTNodeID.SetterID) + { + emitter.emitFunctionBlockHeader((IFunctionNode) node.getParent()); + } + + final int len = node.getChildCount(); + for (int i = 0; i < len; i++) + { + emitter.emitStatement(node.getChild(i)); + } + } + + @Override + public void visitIf(IIfNode node) + { + debug("visitIf()"); + emitter.emitIf(node); + } + + @Override + public void visitForLoop(IForLoopNode node) + { + debug("visitForLoop(" + node.getKind() + ")"); + if (node.getKind() == ForLoopKind.FOR) + visitFor(node); + else if (node.getKind() == ForLoopKind.FOR_EACH) + visitForEach(node); + } + + protected void visitForEach(IForLoopNode node) + { + debug("visitForEach()"); + emitter.emitForEachLoop(node); + } + + protected void visitFor(IForLoopNode node) + { + debug("visitFor()"); + emitter.emitForLoop(node); + } + + @Override + public void visitSwitch(ISwitchNode node) + { + debug("visitSwitch()"); + emitter.emitSwitch(node); + } + + @Override + public void visitWhileLoop(IWhileLoopNode node) + { + debug("visitWhileLoopNode()"); + if (node.getKind() == WhileLoopKind.WHILE) + { + emitter.emitWhileLoop(node); + } + else if (node.getKind() == WhileLoopKind.DO) + { + emitter.emitDoLoop(node); + } + } + + @Override + public void visitWith(IWithNode node) + { + debug("visitWith()"); + emitter.emitWith(node); + } + + @Override + public void visitThrow(IThrowNode node) + { + debug("visitThrow()"); + emitter.emitThrow(node); + } + + @Override + public void visitTry(ITryNode node) + { + debug("visitTry()"); + emitter.emitTry(node); + } + + @Override + public void visitCatch(ICatchNode node) + { + debug("visitCatch()"); + emitter.emitCatch(node); + } + + @Override + public void visitIterationFlow(IIterationFlowNode node) + { + debug("visitIterationFlow()"); + emitter.emitIterationFlow(node); + } + + @Override + public void visitIdentifier(IIdentifierNode node) + { + debug("visitIdentifier(" + node.getName() + ")"); + emitter.emitIdentifier(node); + } + + @Override + public void visitNumericLiteral(INumericLiteralNode node) + { + debug("visitNumericLiteral(" + node.getNumericValue() + ")"); + emitter.emitNumericLiteral(node); + } + + @Override + public void visitDefaultXMLNamespace(IDefaultXMLNamespaceNode node) + { + debug("visitDefaultXMLNamespace()"); + walk(node.getKeywordNode()); // default xml namespace + walk(node.getExpressionNode()); // "http://ns.whatever.com" + } + + @Override + public void visitKeyword(IKeywordNode node) + { + debug("visitKeyword(" + node.getNodeID().getParaphrase() + ")"); + emitter.emitKeyword(node); + } + + @Override + public void visitLiteral(ILiteralNode node) + { + debug("visitLiteral(" + node.getValue() + ")"); + if (node.getLiteralType() == LiteralType.NUMBER + || node.getLiteralType() == LiteralType.BOOLEAN + || node.getLiteralType() == LiteralType.NULL + || node.getLiteralType() == LiteralType.NUMBER + || node.getLiteralType() == LiteralType.REGEXP + || node.getLiteralType() == LiteralType.STRING + || node.getLiteralType() == LiteralType.XML + || node.getLiteralType() == LiteralType.VOID) + { + emitter.emitLiteral(node); + } + else if (node.getLiteralType() == LiteralType.ARRAY + || node.getLiteralType() == LiteralType.OBJECT + || node.getLiteralType() == LiteralType.VECTOR + || node.getLiteralType() == LiteralType.XMLLIST) + { + emitter.emitLiteralContainer((ILiteralContainerNode) node); + } + } + + @Override + public void visitMemberAccessExpression(IMemberAccessExpressionNode node) + { + debug("visitMemberAccessExpression()"); + emitter.emitMemberAccessExpression(node); + } + + @Override + public void visitNamespaceAccessExpression( + INamespaceAccessExpressionNode node) + { + debug("visitNamespaceAccessExpression()"); + emitter.emitNamespaceAccessExpression(node); + } + + @Override + public void visitDynamicAccess(IDynamicAccessNode node) + { + debug("visitDynamicAccess()"); + emitter.emitDynamicAccess(node); + } + + @Override + public void visitTypedExpression(ITypedExpressionNode node) + { + debug("visitITypedExpression()"); + emitter.emitTypedExpression(node); + } + + @Override + public void visitAsOperator(IBinaryOperatorNode node) + { + debug("visitAsOperator()"); + emitter.emitAsOperator(node); + } + + @Override + public void visitIsOperator(IBinaryOperatorNode node) + { + debug("visitIsOperator()"); + emitter.emitIsOperator(node); + } + + @Override + public void visitBinaryOperator(IBinaryOperatorNode node) + { + debug("visitBinaryOperator(" + node.getOperator().getOperatorText() + + ")"); + emitter.emitBinaryOperator(node); + } + + @Override + public void visitUnaryOperator(IUnaryOperatorNode node) + { + debug("visitUnaryOperator()"); + emitter.emitUnaryOperator(node); + } + + @Override + public void visitTerminal(ITerminalNode node) + { + debug("visitTerminal(" + node.getKind() + ")"); + walk(node.getStatementContentsNode()); + } + + @Override + public void visitFunctionObject(IFunctionObjectNode node) + { + emitter.emitFunctionObject((IFunctionObjectNode) node); + } + + @Override + public void visitVariableExpression(IVariableExpressionNode node) + { + debug("visitVariableExpression()"); + emitter.emitVariableExpression(node); + } + + @Override + public void visitExpression(IExpressionNode node) + { + debug("visitExpression()"); + // XXX (mschmalle) anything getting past here? + } + + @Override + public void visitImport(IImportNode node) + { + debug("visitImport()"); + emitter.emitImport(node); + } + + @Override + public void visitMetaTags(IMetaTagsNode node) + { + debug("visitMetaTags()"); + IMetaTagNode[] tags = node.getAllTags(); + for (IMetaTagNode tag : tags) + { + walk(tag); + } + } + + @Override + public void visitMetaTag(IMetaTagNode node) + { + debug("visitMetaTag(" + node.getTagName() + ")"); + emitter.emitMetaTag(node); + } + + @Override + public void visitUseNamespace(IUseNamespaceNode node) + { + debug("visitUseNamespace(" + node.getTargetNamespace() + ")"); + emitter.emitUseNamespace(node); + } + + @Override + public void visitEmbed(IEmbedNode node) + { + debug("visitEmbed(" + node.getAttributes()[0].getValue() + ")"); + // TODO (mschmalle) visitEmbed() + } + + @Override + public void visitContainer(IContainerNode node) + { + debug("visitContainer()"); + emitter.emitContainer(node); + } + + @Override + public void visitE4XFilter(IMemberAccessExpressionNode node) + { + debug("visitE4XFilter()"); + emitter.emitE4XFilter(node); + } + + @Override + public void visitReturn(IReturnNode node) + { + debug("visitReturn()"); + emitter.emitReturn(node); + } + + @Override + public void visitTernaryOperator(ITernaryOperatorNode node) + { + debug("visitTernaryOperator()"); + emitter.emitTernaryOperator(node); + } + + @Override + public void visitLabeledStatement(LabeledStatementNode node) + { + debug("visitLabeledStatement()"); + emitter.emitLabelStatement(node); + } + + @Override + public void visitObjectLiteralValuePair(IObjectLiteralValuePairNode node) + { + debug("visitIObjectLiteralValuePair()"); + emitter.emitObjectLiteralValuePair(node); + } + + @Override + public void visitLanguageIdentifierNode(ILanguageIdentifierNode node) + { + emitter.emitLanguageIdentifier(node); + } + + //-------------------------------------------------------------------------- + // + //-------------------------------------------------------------------------- + + protected void debug(String message) + { + if (isDebug) + { + System.out.println(message); + } + } +}