Updated Branches: refs/heads/develop 2fd6d47eb -> c52fa0545
fix enough FalconJS bugs to satisfy customer Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/a5b691ae Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/a5b691ae Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/a5b691ae Branch: refs/heads/develop Commit: a5b691ae7b3143d86b0e1b4d851d38d5efff3410 Parents: 2fd6d47 Author: Alex Harui <aha...@apache.org> Authored: Fri Mar 29 15:17:48 2013 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Fri Mar 29 15:21:07 2013 -0700 ---------------------------------------------------------------------- .../as/codegen/JSClassDirectiveProcessor.java | 5 + .../compiler/internal/as/codegen/JSEmitter.java | 101 +++++++++------ .../internal/as/codegen/JSGeneratingReducer.java | 93 ++++++++++---- .../compiler/internal/as/codegen/JSGenerator.java | 8 +- .../internal/as/codegen/JSMXMLEmitter.java | 18 ++- .../compiler/internal/graph/GoogDepsWriter.java | 23 ++++ .../compiler/internal/projects/FlexJSProject.java | 18 +++- 7 files changed, 199 insertions(+), 67 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSClassDirectiveProcessor.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSClassDirectiveProcessor.java b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSClassDirectiveProcessor.java index b6c4a8c..ebf8998 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSClassDirectiveProcessor.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSClassDirectiveProcessor.java @@ -139,7 +139,12 @@ public class JSClassDirectiveProcessor extends ClassDirectiveProcessor if (!this.looseInsns.isEmpty()) cinitInsns.addAll(looseInsns); + // base class injects ABC if not empty and then NPEs. + // save our insns and give it an empty list then restore + InstructionList cinitHack = cinitInsns; + cinitInsns = new InstructionList(); super.finishClassDefinition(); + cinitInsns = cinitHack; m_generator.getReducer().setClassDefinition(null, null); } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSEmitter.java b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSEmitter.java index 3088e00..367a0cc 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSEmitter.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSEmitter.java @@ -111,7 +111,7 @@ public class JSEmitter implements IABCVisitor // private ICompilationUnit.Operation m_buildPhase; private IABCVisitor m_visitor = null; protected ICompilerProject m_project = null; - private JSGenerator m_generator = null; + protected JSGenerator m_generator = null; private IASScope m_currentScope = null; protected Map<MethodInfo, FunctionDefinition> m_methodInfoToDefinition = new HashMap<MethodInfo, FunctionDefinition>(); protected Map<FunctionDefinition, MethodInfo> m_definitionToMethodInfo = new HashMap<FunctionDefinition, MethodInfo>(); @@ -1168,7 +1168,7 @@ public class JSEmitter implements IABCVisitor final Name name = t.getNameAttr("name"); Namespace ns = name.getSingleQualifier(); - if (ns.getKind() != CONSTANT_PrivateNs) + if (ns.getKind() != CONSTANT_PrivateNs && isInstanceTraits) break; final String baseName = JSGeneratingReducer.getBasenameFromName(name); @@ -1199,10 +1199,16 @@ public class JSEmitter implements IABCVisitor if (emitVar) { writeString("\n"); - + String slotValue = (String)t.getAttr(Trait.SLOT_VALUE); + if (slotValue == null) + slotValue = ""; + else + { + slotValue = " = " + slotValue; + } boolean methodNeedsSkinPartProcessing = emitVariable(t, baseName, packageName, className, superClassName, - methodPrefix, assignmentOp, separator, indent); + methodPrefix, slotValue, separator, indent); needsSkinPartProcessing = needsSkinPartProcessing || methodNeedsSkinPartProcessing; // print warning in cases where FJS-24 is being hit @@ -1321,6 +1327,7 @@ public class JSEmitter implements IABCVisitor } } + String proto = isInstanceTraits ? ".prototype." : "."; // 4. emit all other methods (ctor already emitted) for (Trait t : traits) { @@ -1347,8 +1354,8 @@ public class JSEmitter implements IABCVisitor // cleaning up static inits. // Static initializer is generated but not called for classes without explicit constructor - if ((!isInstanceTraits || ctor == null) && JSSharedData.instance.hasClassInit(fullName)) - m_methodPrologue += " " + fullName + "." + JSSharedData.STATIC_INIT + "();\n"; + //if ((!isInstanceTraits || ctor == null) && JSSharedData.instance.hasClassInit(fullName)) + // m_methodPrologue += " " + fullName + "." + JSSharedData.STATIC_INIT + "();\n"; if (!isExtern) { @@ -1368,8 +1375,8 @@ public class JSEmitter implements IABCVisitor // actually emit the JS code emitMethod(t, mi, isFramework, isExtern, isInterface, isPackageFunction, fullName, baseName, xetter, - (packageName == "") ? className + ".prototype." : - packageName + "." + className + ".prototype." , "=", "", ""); + (packageName == "") ? className + proto : + packageName + "." + className + proto , "=", "", ""); // print warning in cases where FJS-24 is being hit warnIfPrivateNameCollision(baseClass, filter, baseName, fullName, "Method"); @@ -3209,37 +3216,7 @@ public class JSEmitter implements IABCVisitor writeString("goog.provide('" + classQName + "');\n\n"); FlexJSProject project = (FlexJSProject)m_project; ArrayList<String> deps = project.getRequires(m_generator.m_compilationUnit); - Collections.sort(deps); - String lastOne = ""; - for (String imp : deps) - { - if (imp.indexOf("__AS3__") != -1) - continue; - if (imp.equals(classQName)) - continue; - if (imp.equals("Array")) - continue; - if (imp.equals("Boolean")) - continue; - if (imp.equals("Error")) - continue; - if (imp.equals("Function")) - continue; - if (imp.equals("Number")) - continue; - if (imp.equals("int")) - continue; - if (imp.equals("Object")) - continue; - if (imp.equals("String")) - continue; - if (imp.equals("uint")) - continue; - if (imp != lastOne) - writeString("goog.require('" + imp + "');\n"); - lastOne = imp; - } - writeString("\n"); + emitRequires(deps, classQName); } else writeString("goog.provide('" + className + "');\n"); @@ -3314,6 +3291,52 @@ public class JSEmitter implements IABCVisitor writeString("\n"); } + protected void emitRequires(ArrayList<String> deps, String classQName) + { + HashMap<String, String> already = new HashMap<String, String>(); + for (String imp : deps) + { + if (imp.indexOf("__AS3__") != -1) + continue; + if (imp.equals(classQName)) + continue; + if (imp.equals("Array")) + continue; + if (imp.equals("Boolean")) + continue; + if (imp.equals("decodeURI")) + continue; + if (imp.equals("decodeURIComponent")) + continue; + if (imp.equals("encodeURI")) + continue; + if (imp.equals("encodeURIComponent")) + continue; + if (imp.equals("Error")) + continue; + if (imp.equals("Function")) + continue; + if (imp.equals("JSON")) + continue; + if (imp.equals("Number")) + continue; + if (imp.equals("int")) + continue; + if (imp.equals("Object")) + continue; + if (imp.equals("RegExp")) + continue; + if (imp.equals("String")) + continue; + if (imp.equals("uint")) + continue; + if (!already.containsKey(imp)) + writeString("goog.require('" + imp + "');\n"); + already.put(imp, imp); + } + writeString("\n"); + } + private Boolean hasTrait(Traits traits, String baseName, int kind) { for (Trait t : traits) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java index b3fde25..f1ffd63 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGeneratingReducer.java @@ -165,6 +165,8 @@ public class JSGeneratingReducer */ static final int ERROR_TRAP = 268435456; + private static final Name NAME_Vector = new Name(IASLanguageConstants.Vector); + /** * A struct for the decoded pieces of a catch block. */ @@ -621,6 +623,10 @@ public class JSGeneratingReducer return reduce_inExpr(iNode, l, r); } + if (l == null) + l = "null"; + if (r == null) + r = "null"; final String operator = opToString(iNode, opcode); String result = createInstruction(iNode, l.length() + r.length() + 1); result += binaryOp(l.toString(), r.toString(), operator); @@ -645,6 +651,10 @@ public class JSGeneratingReducer String binaryOp(String l, String r, String operator) { + if (l == null) + l = "null"; + if (r == null) + r = "null"; String result = "(" + stripTabs(stripNS(l.toString())) + " " + operator + " " + stripTabs(stripNS(r.toString())) + ")"; return result; } @@ -1221,6 +1231,8 @@ public class JSGeneratingReducer return result; } + HashMap<IASNode, Boolean> nestedFunctions = new HashMap<IASNode, Boolean>(); + /** * generateFunctionBody() wrapper suitable for calling from the BURM. See * JBurg ENHRQ <N> : the grammar that accepts the BURM's parameters to a @@ -1249,7 +1261,8 @@ public class JSGeneratingReducer if (return_type != null) usedTypes.add(getBasenameFromName(return_type)); - // AJH removed use of 'self' + final Boolean isNestedFunction = nestedFunctions.containsKey(iNode); + /* * !isAnonymousFunction is necessary. AS and JS are different in the way * "this" is being treated in anonymous functions. i.e. public function @@ -1262,17 +1275,17 @@ public class JSGeneratingReducer * localFunction : Function = funciton():void { // NOT EMITTED: var self * = this; self.callMe(); }; }; */ - //if (!JSSharedData.m_useSelfParameter && !isAnonymousFunction && - // /* TODO: !needsSelfParameter(createFullClassName(false)) && */function_body.contains(JSSharedData.THIS)) - //{ + if (//!JSSharedData.m_useSelfParameter && !isAnonymousFunction && + /* TODO: !needsSelfParameter(createFullClassName(false)) && */ !isNestedFunction && function_body.contains("self.")) + { // final Binding fullClassName = makeBinding(createFullClassName(false)); // this.registerLocalVariable(currentScope, makeBinding("self"), fullClassName, fullClassName); - // final Binding fullClassName = new Binding(iNode, makeName(createFullClassName(false)), null); - // this.registerLocalVariable(currentScope, new Binding(iNode, makeName("self"), null), fullClassName, fullClassName); - // result += indentBlock("/** @type {" + createFullClassName(true) + "} */" + endl(), 1); - // result += indentBlock("var " + JSSharedData.THIS + " = this;" + endl(), 1); - //} + final Binding fullClassName = new Binding(iNode, makeName(createFullClassName(false)), null); + this.registerLocalVariable(currentScope, new Binding(iNode, makeName("self"), null), fullClassName, fullClassName); + result += indentBlock("/** @type {" + createFullClassName(true) + "} */" + endl(), 1); + result += indentBlock("var self = this;" + endl(), 1); + } // Constructor-specific processing: add the instance initializers, // add a constructsuper call if none exists. @@ -1341,6 +1354,8 @@ public class JSGeneratingReducer */ private String generateNestedFunction(IASNode iNode, Binding func_name, Name return_type, String function_body) { + nestedFunctions.put(iNode, true); + final Boolean isAnonymousFunction = func_name == null && iNode instanceof FunctionObjectNode; // only the outer function of a nested function should be converted to @@ -1535,6 +1550,11 @@ public class JSGeneratingReducer } } + // nested functions use "self" to get at instance vars + if (result.contains("this.")) + { + result = result.replace("this.", "self."); + } return result; } @@ -2546,6 +2566,9 @@ public class JSGeneratingReducer * result.addInstruction(OP_setproperty, member.getName()); */ + if (r == null) + r = "null"; + String result = createInstruction(iNode, stem.length() + r.length() + 1); // Assignment to a more general lvalue // Pattern assignToMemberExpr, void_expression @@ -3442,10 +3465,11 @@ public class JSGeneratingReducer else { result += indent() + "for(" + getVarSnippet(iNode, baseName) + " in "; - if (getCurrentClassName().equals(JSSharedData.JS_FRAMEWORK_NAME)) + // AJH disable for now + // if (getCurrentClassName().equals(JSSharedData.JS_FRAMEWORK_NAME)) result += container; - else - result += "adobe.getOwnProperties(" + container + ")"; + // else + // result += "adobe.getOwnProperties(" + container + ")"; result += ")" + endl(); result += "{" + endl(); @@ -3503,7 +3527,9 @@ public class JSGeneratingReducer if (isDataClass(currentScope.getProject(), def)) currentScope.addProblem(new JSDataClassMethodError(iNode)); + // AJH disable for now // dynamic classes need to call adobe.callProperty +/* if (!isCurrentFramework() && (def == null || def.isDynamic())) { registerAccessedPropertyName(iNode, name); @@ -3513,6 +3539,7 @@ public class JSGeneratingReducer } else { +*/ // result += getRootName() + "."; if (m_convertToStatic) { @@ -3536,7 +3563,7 @@ public class JSGeneratingReducer result += "("; result += collectCallParameters(iNode, stem, memberBinding, args, JSSharedData.m_useSelfParameter, extraParams); result += ")"; - } +/* AJH } */ return result; } @@ -3577,6 +3604,8 @@ public class JSGeneratingReducer if (isDataClass(currentScope.getProject(), def)) currentScope.addProblem(new JSDataClassMethodError(iNode)); + // AJH disable +/* // dynamic classes need to call adobe.callProperty if (!isCurrentFramework() && (def == null || def.isDynamic())) { @@ -3587,6 +3616,7 @@ public class JSGeneratingReducer } else { +*/ result += indent(); // result += getRootName() + "."; @@ -3611,7 +3641,7 @@ public class JSGeneratingReducer result += "("; result += collectCallParameters(iNode, stem, method_name, args, JSSharedData.m_useSelfParameter, ""); result += ")"; - } +/* AJH } */ return result; } @@ -3676,6 +3706,8 @@ public class JSGeneratingReducer if (!m_hasSideEffects && hasSideEffects(def)) m_hasSideEffects = true; + // AJH disable for now +/* if (mname.contains(".") && !isCurrentFramework() && (def == null || def.isDynamic())) { final String stem = mname.substring(0, mname.lastIndexOf(".")); @@ -3687,6 +3719,7 @@ public class JSGeneratingReducer } else { +*/ if (JSSharedData.m_useClosureLib) { String fname = ""; @@ -3722,7 +3755,7 @@ public class JSGeneratingReducer result = indent() + mname + "("; result += collectCallParameters(iNode, "", method_name, args, JSSharedData.m_useSelfParameter, extraParams); result += ")"; - } +/* AJH } */ if (!need_result) result += ";" + endl(); @@ -5037,6 +5070,8 @@ public class JSGeneratingReducer // Implicit coercion of a value of type Date to an unrelated type Class. // currentScope.getMethodBodySemanticChecker().checkReturnValue(iNode); + if (value == null) + value = "null"; String result = createInstruction(iNode, value.length() + 1); /* @@ -5363,6 +5398,10 @@ public class JSGeneratingReducer public String reduce_ternaryExpr(IASNode iNode, String test, String when_true, String when_false) { + if (when_true == null) + when_true = "null"; + if (when_false == null) + when_false = "null"; String result = createInstruction(iNode, test.length() + when_true.length() + when_false.length() + 2); /* @@ -5531,6 +5570,8 @@ public class JSGeneratingReducer public String reduce_typedVariableDeclWithConstantInitializer(IASNode iNode, Name var_name, Binding var_type, Object var_initializer, Vector<String> chained_decls) { + if (var_initializer == null) + var_initializer = "null"; return reduce_typedVariableDeclWithInitializer(iNode, var_name, var_type, var_initializer.toString(), chained_decls); } @@ -8502,7 +8543,7 @@ public class JSGeneratingReducer Binding var = currentScope.resolveName((IdentifierNode)var_node.getNameExpressionNode()); scope.makeVariable(var, type, null); - this.registerMember(var_node, var_node.getDefinition(), b_returnType.getDefinition()); + this.registerMember(var_node, var_node.getDefinition(), b_type.getDefinition()); /* * Name _name = new Name( new Nsset( new @@ -9198,6 +9239,7 @@ public class JSGeneratingReducer */ private String addDynamicCastToValue(IASNode iNode, String value) { + /* AJH disable for now // m_numMemberAsUint = num; needs to be converted. // Tamarin tests trigger NPE in JSGeneratingReducer.addDynamicCastToValue() if (getCurrentClassName() != null && @@ -9261,7 +9303,7 @@ public class JSGeneratingReducer value = "adobe.dynamicCastAs(" + value + ", UIntClass)"; // "(((~~(" + value + ")) < 0 ) ? (4294967296+(~~(" + value + "))) : (~~(" + value +")) / * Coerce to uint * /)"; } } - } + }*/ return value; } @@ -9601,9 +9643,10 @@ public class JSGeneratingReducer // TODO: If the current function is not a static function and a member of the same class // and we have a ctor, then we know that __staticInit() has been called, because the ctor calls init. - final String pre = "(" + fullName + "." + JSSharedData.STATIC_INIT + "(), "; - final String post = ")"; - return pre + code + post; + // final String pre = "(" + fullName + "." + JSSharedData.STATIC_INIT + "(), "; + // final String post = ")"; + // return pre + code + post; + return code; // AJH remove static inits } } else if (!m_hasSideEffects && fdef.isStatic()) @@ -9702,6 +9745,7 @@ public class JSGeneratingReducer ret = memberName; else { + /* AJH disable for now if (needsRuntimeLookup(iNode, instanceName, member)) { String quote = ""; @@ -9723,7 +9767,7 @@ public class JSGeneratingReducer registerAccessedPropertyName(iNode, memberName); ret = JSSharedData.JS_FRAMEWORK_NAME + ".getProperty(" + self + ", " + instanceName + ", " + quote + memberName + quote + ")"; } - else if (useBrackets) + else */if (useBrackets) ret = instanceName + "[" + memberName + "]"; else ret = instanceName + "." + memberName; @@ -10635,8 +10679,10 @@ public class JSGeneratingReducer String result = ""; // final Boolean useNew = getCurrentClassName().equals(JSSharedData.JS_FRAMEWORK_NAME) || isDataType(_class) || !m_sharedData.hasClass(removeRootName(_class)); /*|| !needsSelfParameter(_class)*/; - final Boolean useNew = JSSharedData.m_useClosureLib || getCurrentClassName().equals(JSSharedData.JS_FRAMEWORK_NAME) || isDataType(_class); // || !m_sharedData.hasClass(removeRootName(_class)); /*|| !needsSelfParameter(_class)*/; + Boolean useNew = JSSharedData.m_useClosureLib || getCurrentClassName().equals(JSSharedData.JS_FRAMEWORK_NAME) || isDataType(_class); // || !m_sharedData.hasClass(removeRootName(_class)); /*|| !needsSelfParameter(_class)*/; + if (!useNew) + useNew = args.size() > 1; if (useNew) result += "(new " + _class + "("; else @@ -11623,7 +11669,8 @@ public class JSGeneratingReducer public Binding reduce_parameterizedName(IASNode node, Binding base, Binding param) { - return null; + return reduce_parameterizedTypeName(node, base, param); + //return null; } public String reduce_vectorLiteral(IASNode node, Binding type_param, Vector<String> elements) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGenerator.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGenerator.java b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGenerator.java index 9221178..154a70c 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGenerator.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSGenerator.java @@ -150,7 +150,7 @@ public class JSGenerator implements ICodeGenerator { m_needsSecondPass = false; if (root_node instanceof MXMLFileNode) - m_emitter = new JSMXMLEmitter(JSSharedData.instance, m_buildPhase, project); + m_emitter = new JSMXMLEmitter(JSSharedData.instance, m_buildPhase, project, this); else m_emitter = JSSharedData.backend.createEmitter(m_buildPhase, project, this); m_emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10); @@ -484,6 +484,12 @@ public class JSGenerator implements ICodeGenerator function_scope.methodBodyVisitor = mbv; function_scope.traitsVisitor = mbv.visitTraits(); function_scope.setMethodInfo(mi); + + System.out.println(mi.getMethodName()); + if (mi.getMethodName().contains("loginInternal")) + { + System.out.println("got it"); + } InstructionList insns = null; if (node == null) http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSMXMLEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSMXMLEmitter.java b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSMXMLEmitter.java index 377a2f2..54e4cc8 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSMXMLEmitter.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/as/codegen/JSMXMLEmitter.java @@ -12,15 +12,19 @@ import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.definitions.IPackageDefinition; import org.apache.flex.compiler.internal.as.codegen.JSEmitter.EmitterClassVisitor; import org.apache.flex.compiler.internal.definitions.ClassDefinition; +import org.apache.flex.compiler.internal.projects.FlexJSProject; +import org.apache.flex.compiler.internal.scopes.ASProjectScope; import org.apache.flex.compiler.projects.ICompilerProject; +import org.apache.flex.compiler.scopes.IASScope; +import org.apache.flex.compiler.units.ICompilationUnit; import org.apache.flex.compiler.units.ICompilationUnit.Operation; class JSMXMLEmitter extends JSEmitter { public JSMXMLEmitter(JSSharedData sharedData, Operation buildPhase, - ICompilerProject project) { - super(sharedData, buildPhase, project, null); + ICompilerProject project, JSGenerator generator) { + super(sharedData, buildPhase, project, generator); // TODO Auto-generated constructor stub } @@ -48,8 +52,10 @@ class JSMXMLEmitter extends JSEmitter { ClassDefinition definition = cdp.classDefinition; IClassDefinition superClass = (ClassDefinition)definition.resolveBaseClass(cdp.getProject()); - writeString("goog.provide('" + definition.getQualifiedName() + "');" + NEWLINE); + String classQName = definition.getQualifiedName(); + writeString("goog.provide('" + classQName + "');" + NEWLINE); writeString(NEWLINE); + /* String[] list = definition.getImplicitImports(); ArrayList<String> imps = new ArrayList<String>(Arrays.asList(list)); imps.add(superClass.getQualifiedName()); @@ -62,6 +68,12 @@ class JSMXMLEmitter extends JSEmitter writeString(NEWLINE); } writeString(NEWLINE); + */ + FlexJSProject project = (FlexJSProject)m_project; + ASProjectScope projectScope = (ASProjectScope) m_project.getScope(); + ICompilationUnit cu = projectScope.getCompilationUnitForDefinition(definition); + ArrayList<String> deps = project.getRequires(cu); + emitRequires(deps, classQName); writeString("/**" + NEWLINE); writeString(" * @constructor" + NEWLINE); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java b/compiler.js/src/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java index 497a8d4..6a601fc 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/graph/GoogDepsWriter.java @@ -16,6 +16,7 @@ import java.util.Map; import java.util.Scanner; import java.util.Set; +import org.apache.commons.io.FileUtils; import org.apache.flex.compiler.internal.projects.DependencyGraph; import org.apache.flex.compiler.units.ICompilationUnit; @@ -25,6 +26,10 @@ public class GoogDepsWriter { { this.mainCU = mainCU; this.outputFolderPath = outputFolder.getAbsolutePath(); + this.sourceFolderPath = mainCU.getAbsoluteFilename(); + File sourceFile = new File(sourceFolderPath); + sourceFile = sourceFile.getParentFile(); + this.sourceFolderPath = sourceFile.getAbsolutePath(); String flexJSHome = System.getenv("FLEXJS_HOME"); if (flexJSHome == null || flexJSHome.length() == 0) System.out.println("FLEXJS_HOME not defined. Should point to root of FlexJS source."); @@ -33,6 +38,7 @@ public class GoogDepsWriter { private ICompilationUnit mainCU; private String outputFolderPath; + private String sourceFolderPath; private HashMap<String,GoogDep> depMap = new HashMap<String,GoogDep>(); @@ -195,6 +201,22 @@ public class GoogDepsWriter { File f = new File(fn); if (f.exists()) return fn; + fn = sourceFolderPath + File.separator + classPath + ".js"; + f = new File(fn); + if (f.exists()) + { + fn = outputFolderPath + File.separator + classPath + ".js"; + File destFile = new File(fn); + // copy source to output + try { + FileUtils.copyFile(f, destFile); + System.out.println("Copying file for class: " + className); + } catch (IOException e) { + // TODO Auto-generated catch block + System.out.println("Error copying file for class: " + className); + } + return fn; + } fn = outputFolderPath + File.separator + classPath + ".js"; f = new File(fn); if (f.exists()) @@ -207,6 +229,7 @@ public class GoogDepsWriter { if (f.exists()) return fn; } + System.out.println("Could not find file for class: " + className); return ""; } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/a5b691ae/compiler.js/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java ---------------------------------------------------------------------- diff --git a/compiler.js/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java b/compiler.js/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java index 0af7041..8bf9d46 100644 --- a/compiler.js/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java +++ b/compiler.js/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java @@ -42,7 +42,23 @@ public class FlexJSProject extends FlexProject reqs = new ArrayList<String>(); requires.put(from, reqs); } - if (dt != DependencyType.SIGNATURE) + // if the from unit is already in the requires list for the to compilation unit + // then don't add as requires otherwise we get circularities + // that the closure compiler can't handle + boolean circular = false; + if (requires.containsKey(to)) + { + try { + List<String> qnames = from.getQualifiedNames(); + ArrayList<String> targetReqs = requires.get(to); + if (targetReqs.contains(qnames.get(0))) + circular = true; + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + if (!circular) reqs.add(qname); super.addDependency(from, to, dt, qname); }