Fixes to binding code generation for [Bindable] getters that override getters with [Bindable]
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/b08d11d2 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/b08d11d2 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/b08d11d2 Branch: refs/heads/develop Commit: b08d11d2faf03bf72da414d34781e9751837eda2 Parents: ba7fef9 Author: Alex Harui <[email protected]> Authored: Thu Oct 24 15:50:46 2013 -0700 Committer: Alex Harui <[email protected]> Committed: Thu Oct 24 15:50:46 2013 -0700 ---------------------------------------------------------------------- .../internal/as/codegen/ABCGenerator.java | 17 +++++++------ .../internal/as/codegen/BindableHelper.java | 12 +++++++++ .../as/codegen/ClassDirectiveProcessor.java | 26 +++++++++----------- .../as/codegen/GlobalDirectiveProcessor.java | 2 +- .../internal/as/codegen/ICodeGenerator.java | 5 ++-- 5 files changed, 37 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b08d11d2/compiler/src/org/apache/flex/compiler/internal/as/codegen/ABCGenerator.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/as/codegen/ABCGenerator.java b/compiler/src/org/apache/flex/compiler/internal/as/codegen/ABCGenerator.java index a321dae..2b2db36 100644 --- a/compiler/src/org/apache/flex/compiler/internal/as/codegen/ABCGenerator.java +++ b/compiler/src/org/apache/flex/compiler/internal/as/codegen/ABCGenerator.java @@ -250,9 +250,9 @@ public class ABCGenerator implements ICodeGenerator * constructor. * @return {@link MethodInfo} created for the function. */ - public MethodInfo generateFunction (FunctionNode func, LexicalScope enclosing_scope, InstructionList instance_init_insns) + public MethodInfo generateFunction (FunctionNode func, LexicalScope enclosing_scope, InstructionList instance_init_insns, Name alternate_name) { - MethodInfo mi = createMethodInfo(enclosing_scope, func); + MethodInfo mi = createMethodInfo(enclosing_scope, func, alternate_name); if (mi.isNative()) { generateNativeMethod(func, mi, enclosing_scope); @@ -284,7 +284,7 @@ public class ABCGenerator implements ICodeGenerator */ public GenerateFunctionInParallelResult generateFunctionInParallel (ExecutorService executorService, FunctionNode func, LexicalScope enclosing_scope) { - MethodInfo mi = createMethodInfo(enclosing_scope, func); + MethodInfo mi = createMethodInfo(enclosing_scope, func, null); if (mi.isNative()) { generateNativeMethod(func, mi, enclosing_scope); @@ -523,9 +523,9 @@ public class ABCGenerator implements ICodeGenerator * @return The MethodInfo specifying the signature of the method. */ @Override - public MethodInfo createMethodInfo (LexicalScope scope, FunctionNode func) + public MethodInfo createMethodInfo (LexicalScope scope, FunctionNode func, Name alternate_name) { - return createMethodInfoWithOptionalDefaultArgumentValues(scope, func, false); + return createMethodInfoWithOptionalDefaultArgumentValues(scope, func, false, alternate_name); } /** @@ -542,13 +542,14 @@ public class ABCGenerator implements ICodeGenerator @Override public MethodInfo createMethodInfoWithDefaultArgumentValues (LexicalScope scope, FunctionNode func) { - return createMethodInfoWithOptionalDefaultArgumentValues(scope, func, true); + return createMethodInfoWithOptionalDefaultArgumentValues(scope, func, true, null); } - private static MethodInfo createMethodInfoWithOptionalDefaultArgumentValues(LexicalScope scope, FunctionNode func, boolean addDefalutValues) + private static MethodInfo createMethodInfoWithOptionalDefaultArgumentValues(LexicalScope scope, FunctionNode func, + boolean addDefalutValues, Name alternate_name) { MethodInfo mi = new MethodInfo(); - mi.setMethodName(func.getName()); + mi.setMethodName(alternate_name != null ? alternate_name.getBaseName() : func.getName()); FunctionDefinition funcDef = func.getDefinition(); // Marshal the function's arguments. http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b08d11d2/compiler/src/org/apache/flex/compiler/internal/as/codegen/BindableHelper.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/as/codegen/BindableHelper.java b/compiler/src/org/apache/flex/compiler/internal/as/codegen/BindableHelper.java index ea1e0a3..203a804 100644 --- a/compiler/src/org/apache/flex/compiler/internal/as/codegen/BindableHelper.java +++ b/compiler/src/org/apache/flex/compiler/internal/as/codegen/BindableHelper.java @@ -520,6 +520,18 @@ public class BindableHelper } /** + * Return the AET Name to use for the backing property of a bindable var. This name will have the same simple + * name as the one passed in, but will be in a special, hidden private namespace to avoid conflicts with other + * properties. + * @param propName the Name of the property to generate a hidden name for + * @return the Name of the hidden property that will actually store the value + */ + static Name getBackingPropertyName(Name propName, String suffix) + { + return new Name(CONSTANT_Qname, new Nsset(bindablePrivateNamespace), propName.getBaseName() + suffix); + } + + /** * The namespace to put compiler generated members into so that they do not conflict with any user defined * members. */ http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b08d11d2/compiler/src/org/apache/flex/compiler/internal/as/codegen/ClassDirectiveProcessor.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/as/codegen/ClassDirectiveProcessor.java b/compiler/src/org/apache/flex/compiler/internal/as/codegen/ClassDirectiveProcessor.java index 2f62f96..9af1d45 100644 --- a/compiler/src/org/apache/flex/compiler/internal/as/codegen/ClassDirectiveProcessor.java +++ b/compiler/src/org/apache/flex/compiler/internal/as/codegen/ClassDirectiveProcessor.java @@ -56,7 +56,6 @@ import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.definitions.IInterfaceDefinition; import org.apache.flex.compiler.definitions.metadata.IMetaTag; import org.apache.flex.compiler.definitions.metadata.IMetaTagAttribute; -import org.apache.flex.compiler.definitions.references.INamespaceReference; import org.apache.flex.compiler.exceptions.CodegenInterruptedException; import org.apache.flex.compiler.problems.CircularTypeReferenceProblem; import org.apache.flex.compiler.problems.ConstructorCannotHaveReturnTypeProblem; @@ -555,7 +554,7 @@ class ClassDirectiveProcessor extends DirectiveProcessor // Create the class' constructor function. if ( this.ctorFunction != null ) { - MethodInfo mi = classScope.getGenerator().generateFunction(this.ctorFunction, classScope, this.iinitInsns); + MethodInfo mi = classScope.getGenerator().generateFunction(this.ctorFunction, classScope, this.iinitInsns, null); if ( mi != null ) this.iinfo.iInit = mi; @@ -748,21 +747,20 @@ class ClassDirectiveProcessor extends DirectiveProcessor } } } + + functionSemanticChecks(func); + Name funcName = funcDef.getMName(classScope.getProject()); Name bindableName = null; boolean wasOverride = false; if (isBindable) { // move function into bindable namespace - bindableName = BindableHelper.getBackingPropertyName(funcName); - INamespaceReference ns = BindableHelper.bindableNamespaceDefinition; + bindableName = BindableHelper.getBackingPropertyName(funcName, "_" + this.classDefinition.getQualifiedName()); wasOverride = funcDef.isOverride(); - funcDef.setNamespaceReference(ns); funcDef.unsetOverride(); } - functionSemanticChecks(func); - // Save the constructor function until // we've seen all the instance variables // that might need initialization. @@ -781,17 +779,17 @@ class ClassDirectiveProcessor extends DirectiveProcessor { LexicalScope ls = funcDef.isStatic()? classStaticScope: classScope; - MethodInfo mi = classScope.getGenerator().generateFunction(func, ls, null); + MethodInfo mi = classScope.getGenerator().generateFunction(func, ls, null, bindableName); if ( mi != null ) { ITraitVisitor tv = ls.traitsVisitor.visitMethodTrait(functionTraitKind(func, TRAIT_Method), bindableName != null ? bindableName : funcName, 0, mi); - if (funcName != null) + if (funcName != null && bindableName == null) classScope.getMethodBodySemanticChecker().checkFunctionForConflictingDefinitions(func, funcDef); - if ( ! funcDef.isStatic() ) + if ( ! funcDef.isStatic() && bindableName == null) if (funcDef.getNamespaceReference() instanceof NamespaceDefinition.IProtectedNamespaceDefinition) this.iinfo.flags |= ABCConstants.CLASS_FLAG_protected; @@ -811,9 +809,9 @@ class ClassDirectiveProcessor extends DirectiveProcessor funcDef.setOverride(); if (funcDef instanceof GetterDefinition) { - DefinitionBase bindableGetter = func.buildBindableGetter(func.getName()); + DefinitionBase bindableGetter = func.buildBindableGetter(funcName.getBaseName()); ASScope funcScope = (ASScope)funcDef.getContainingScope(); - funcScope.addDefinition(bindableGetter); + bindableGetter.setContainingScope(funcScope); LexicalScope ls = funcDef.isStatic()? classStaticScope: classScope; ls.generateBindableGetter(bindableGetter, funcName, bindableName, funcDef.resolveType(project).getMName(project), getAllMetaTags(funcDef)); @@ -822,10 +820,10 @@ class ClassDirectiveProcessor extends DirectiveProcessor { TypeDefinitionBase typeDef = funcDef.resolveType(project); ASScope funcScope = (ASScope)funcDef.getContainingScope(); - DefinitionBase bindableSetter = func.buildBindableSetter(func.getName(), + DefinitionBase bindableSetter = func.buildBindableSetter(funcName.getBaseName(), funcScope, funcDef.getTypeReference()); - funcScope.addDefinition(bindableSetter); + bindableSetter.setContainingScope(funcScope); LexicalScope ls = funcDef.isStatic()? classStaticScope: classScope; ls.generateBindableSetter(bindableSetter, funcName, bindableName, typeDef.getMName(project), getAllMetaTags(funcDef)); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b08d11d2/compiler/src/org/apache/flex/compiler/internal/as/codegen/GlobalDirectiveProcessor.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/as/codegen/GlobalDirectiveProcessor.java b/compiler/src/org/apache/flex/compiler/internal/as/codegen/GlobalDirectiveProcessor.java index 0de6497..5a7c499 100644 --- a/compiler/src/org/apache/flex/compiler/internal/as/codegen/GlobalDirectiveProcessor.java +++ b/compiler/src/org/apache/flex/compiler/internal/as/codegen/GlobalDirectiveProcessor.java @@ -153,7 +153,7 @@ class GlobalDirectiveProcessor extends DirectiveProcessor else { f.parseFunctionBody(currentScope.getProblems()); - return currentScope.getGenerator().generateFunction(f, this.currentScope, null); + return currentScope.getGenerator().generateFunction(f, this.currentScope, null, null); } } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b08d11d2/compiler/src/org/apache/flex/compiler/internal/as/codegen/ICodeGenerator.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/as/codegen/ICodeGenerator.java b/compiler/src/org/apache/flex/compiler/internal/as/codegen/ICodeGenerator.java index dff5b61..b06911e 100644 --- a/compiler/src/org/apache/flex/compiler/internal/as/codegen/ICodeGenerator.java +++ b/compiler/src/org/apache/flex/compiler/internal/as/codegen/ICodeGenerator.java @@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.as.codegen; import org.apache.flex.abc.instructionlist.InstructionList; import org.apache.flex.abc.semantics.MethodInfo; +import org.apache.flex.abc.semantics.Name; import org.apache.flex.compiler.internal.tree.as.FunctionNode; import org.apache.flex.compiler.internal.units.requests.ABCBytesRequestResult; import org.apache.flex.compiler.problems.ICompilerProblem; @@ -108,7 +109,7 @@ public interface ICodeGenerator * @return {@link MethodInfo} created for the function. */ MethodInfo generateFunction(FunctionNode func, LexicalScope enclosing_scope, - InstructionList instance_init_insns); + InstructionList instance_init_insns, Name alternateName); /** * Generate code for a function declaration, using a background thread @@ -171,7 +172,7 @@ public interface ICodeGenerator * @param func - A FunctionNode representing a method declaration. * @return The MethodInfo specifying the signature of the method. */ - MethodInfo createMethodInfo (LexicalScope scope, FunctionNode func); + MethodInfo createMethodInfo (LexicalScope scope, FunctionNode func, Name alternate_name); /** * Creates a MethodInfo specifying the signature of a method
