Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ public class CompilerDiagnosticsConstants
public static final int COMPC_PHASES = 16384;
public static final int GOOG_DEPS = 32768;

public static void println(int type, String message)
{
if ((diagnostics & type) == type)
{
System.out.println(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,15 @@ public IMetaTag[] getAllMetaTags()
return metaTags;
}

protected void addMetaTag(IMetaTag metaTag)
protected synchronized void addMetaTag(IMetaTag metaTag)
{
IMetaTag[] newMetaTags = new IMetaTag[metaTags.length + 1];
System.arraycopy(metaTags, 0, newMetaTags, 0, metaTags.length);
newMetaTags[metaTags.length] = metaTag;
setMetaTags(newMetaTags);
}

public void setMetaTags(IMetaTag[] newMetaTags)
public synchronized void setMetaTags(IMetaTag[] newMetaTags)
{
if (newMetaTags == null)
{
Expand Down Expand Up @@ -1326,9 +1326,18 @@ public boolean matches(DefinitionBase node)
{
return true; //we can't verify path because we might be a definition from a library
}
else if (leftScope instanceof ASFileScope && rightScope instanceof ASFileScope)
if (leftScope instanceof ASFileScope && rightScope instanceof ASFileScope)
{
if (((ASFileScope)leftScope).getContainingPath().compareTo(((ASFileScope)rightScope).getContainingPath()) != 0)
String leftPath = ((ASFileScope)leftScope).getContainingPath();
String rightPath = ((ASFileScope)rightScope).getContainingPath();
if (leftPath != null && rightPath != null)
{
if (leftPath.compareTo(rightPath) != 0)
{
return false;
}
}
else if (leftPath != rightPath)
{
return false;
}
Expand Down Expand Up @@ -1826,7 +1835,7 @@ public boolean isInProject(ICompilerProject project)
return false;
}

protected void addFunctionTypeMeta(IFunctionTypeExpressionNode funcTypeExprNode, String paramName, ICompilerProject project)
protected synchronized void addFunctionTypeMeta(IFunctionTypeExpressionNode funcTypeExprNode, String paramName, ICompilerProject project)
{
int existingIndex = -1;
for (int i = 0; i < metaTags.length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public boolean useStrictXML() {

private final IWorkspace workspace;

ConfigProcessor(IWorkspace workspace, BaseASParser parser)
public ConfigProcessor(IWorkspace workspace, BaseASParser parser)
{
this.parser = parser;
configNames = new HashSet<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,20 @@ public void updatePublicAndInternalDefinitions(Collection<ICompilationUnit> unit
scopeRequests.add(unit.getFileScopeRequest());
}

scopeCaches.invalidateAll();
initThreadLocalCaches();
invalidateAllScopeCaches();

projectScope.addAllExternallyVisibleDefinitions(scopeRequests);
}

/**
* Invalidates all scope caches for this project, including thread-local caches.
*/
public void invalidateAllScopeCaches()
{
scopeCaches.invalidateAll();
initThreadLocalCaches();
}

/**
* Adds compilation units to the project and updates the public and private
* definitions. Eventually this method should be removed, but it is
Expand Down Expand Up @@ -535,8 +543,7 @@ public void clean()
compilationUnit.clean(null, cusToUpdate, true);
}

scopeCaches.invalidateAll();
initThreadLocalCaches();
invalidateAllScopeCaches();
}
finally
{
Expand Down Expand Up @@ -715,14 +722,41 @@ public void resetScopeCacheForCompilationUnit(ICompilationUnit compilationUnit)
resetScopeCaches(relatedScopes);
}

private void resetScopeCaches(Iterable<IASScope> scopes)
/**
* Resets all the {@link ASScopeCache}s associated with the specified
* {@link IASScope}s.
*
* @param scopes {@link IASScope}s whose scope caches should be cleared
*/
public void resetScopeCaches(Iterable<IASScope> scopes)
{
assert scopes != null;
for (IASScope scope : scopes)
boolean invalidated = false;
// Optimization: if it's a single scope, avoid overhead of iterator or complex checks
if (scopes instanceof Collection && ((Collection<?>)scopes).size() == 1)
{
scopeCaches.invalidate(scope);
IASScope scope = scopes.iterator().next();
if (scopeCaches.asMap().containsKey(scope))
{
scopeCaches.invalidate(scope);
invalidated = true;
}
}
else
{
for (IASScope scope : scopes)
{
if (scopeCaches.asMap().containsKey(scope))
{
scopeCaches.invalidate(scope);
invalidated = true;
}
}
}
if (invalidated)
{
initThreadLocalCaches();
}
initThreadLocalCaches();
}

public void addGlobalUsedNamespacesToNamespaceSet(Set<INamespaceDefinition> nsSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,8 @@ public String getActualPackageName(String packageName)
@Override
public IDefinition doubleCheckAmbiguousDefinition(IASScope scope, String name, IDefinition def1, IDefinition def2)
{
if (scope == null)
return null;
IScopedDefinition scopeDef = ((ASScope)scope).getContainingDefinition();
String thisPackage = null;
if (scopeDef != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected boolean isEditableFile()
* For debugging only.
*/
@Override
protected String toStringHeader()
public String toStringHeader()
{
StringBuilder sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.apache.royale.compiler.definitions.IClassDefinition;
import org.apache.royale.compiler.definitions.IDefinition;
import org.apache.royale.compiler.definitions.INamespaceDefinition;
import org.apache.royale.compiler.definitions.INamespaceDefinition.IProtectedNamespaceDefinition;
import org.apache.royale.compiler.definitions.INamespaceDefinition.IStaticProtectedNamespaceDefinition;
import org.apache.royale.compiler.definitions.IQualifiers;
import org.apache.royale.compiler.definitions.IScopedDefinition;
import org.apache.royale.compiler.definitions.references.INamespaceReference;
Expand Down Expand Up @@ -286,12 +288,23 @@ public ASScope getContainingScope()
public void reconnectScopeNode(IScopedNode node)
{
scopedNodeRef.reconnectNode(node);
IWorkspace w = getWorkspace();
if (w instanceof Workspace)
{
CompilerProject[] projects = ((Workspace)w).getProjects();
for (CompilerProject project : projects)
{
project.resetScopeCaches(Collections.singleton(this));
}
}
}

@Override
public IScopedNode getScopeNode()
{
IWorkspace w = getWorkspace();
if (w == null)
return null;
return (IScopedNode)scopedNodeRef.getNode(w, this);
}

Expand All @@ -317,7 +330,7 @@ public void setContainingDefinition(ScopedDefinitionBase value)
* For debugging only.
*/
@Override
protected String toStringHeader()
public String toStringHeader()
{
StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -961,7 +974,7 @@ private IDefinition getPropertyFromDef(CompilerProject project,
*/
protected void getPropertyForScopeChain(CompilerProject project, Collection<IDefinition> defs, String baseName, NamespaceSetPredicate namespaceSet, boolean findAll)
{
getLocalProperty(project, defs, baseName, true);
getPropertyForMemberAccess(project, defs, baseName, namespaceSet, findAll);
}

protected String resolveBaseNameFromAlias(String possibleAlias)
Expand Down Expand Up @@ -1757,7 +1770,8 @@ public ASFileScope getFileScope()
*/
public IWorkspace getWorkspace()
{
return getFileScope().getWorkspace();
ASFileScope fileScope = getFileScope();
return fileScope != null ? fileScope.getWorkspace() : null;
}

public String getContainingSourcePath(String qName, ICompilerProject project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,14 @@ private void buildStringRecursive(StringBuilder sb, int level)
// for a project scope this would actualize every DefinitionPromise.
IDefinitionSet set = definitionStore.getDefinitionSetByName(name);

if (set == null)
{
indent(sb, level);
sb.append(" <ERROR: null definition set for ");
sb.append(name);
sb.append(">\n");
return;
}
int n = set.getSize();
for (int i = 0; i < n; i++)
{
Expand Down Expand Up @@ -502,7 +510,7 @@ private void buildStringRecursive(StringBuilder sb, int level)
* For debugging only. Called by toString() to return the header that is
* displayed at the beginning.
*/
protected String toStringHeader()
public String toStringHeader()
{
return getClass().getSimpleName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.royale.compiler.config.CompilerDiagnosticsConstants;
import org.apache.royale.compiler.constants.IASLanguageConstants;
import org.apache.royale.compiler.definitions.IDefinition;
import org.apache.royale.compiler.definitions.IFunctionDefinition;
import org.apache.royale.compiler.definitions.IInterfaceDefinition;
import org.apache.royale.compiler.definitions.INamespaceDefinition;
import org.apache.royale.compiler.definitions.ITypeDefinition;
Expand Down Expand Up @@ -125,12 +124,9 @@ public ASScopeCache(CompilerProject project, ASScope scope)

/**
* Version of findProperty that uses a cache. Checks the cache first, and
* only queries the scope if the we don't have a cached result.
* only queries the scope if we don't have a cached result.
*
* @param scope The scope to perform the lookup in
* @param name Name of the property to find
* @param cache ASDefinitionCache to use for the lookup - this is only used
* to get at the ICompilerProject
* @param dt Which type of dependency to introduce when we do the lookup
* @return The IDefinition for the property, or null if it wasn't found
*/
Expand All @@ -142,19 +138,24 @@ IDefinition findProperty(String name, DependencyType dt, boolean favorTypes)
if (result != null)
{
// We found a cached result - we're done
// after making sure it has a dependency
if (result instanceof ITypeDefinition)
{
ICompilationUnit from = scope.getFileScope().getCompilationUnit();
assert result.isInProject(project);

String qname = result.getQualifiedName();
ICompilationUnit to = ((ASProjectScope)project.getScope()).getCompilationUnitForDefinition(result);
if (to == null && !(qname.contentEquals("void") || qname.contentEquals("*")))
System.err.println("No compilation unit for " + qname);
if (to != null)
project.addDependency(from, to, dt, qname);
}
// after making sure it has a dependency
if (result instanceof ITypeDefinition)
{
ASFileScope fileScope = scope.getFileScope();
//if it is null, it might be partially detached or in the process of reconnection
if (fileScope != null)
{
ICompilationUnit from = fileScope.getCompilationUnit();
assert result.isInProject(project);

String qname = result.getQualifiedName();
ICompilationUnit to = ((ASProjectScope)project.getScope()).getCompilationUnitForDefinition(result);
if (to == null && !(qname.contentEquals("void") || qname.contentEquals("*")))
System.err.println("No compilation unit for " + qname);
if (to != null)
project.addDependency(from, to, dt, qname);
}
}
return result;
}

Expand All @@ -180,7 +181,7 @@ IDefinition findProperty(String name, DependencyType dt, boolean favorTypes)
assert def.isInProject(project);
break;
default:
wasAmbiguous = true;
wasAmbiguous = true;
IDefinition d = AmbiguousDefinition.resolveAmbiguities(project, defs, favorTypes);
if (d != null)
def = d;
Expand All @@ -189,7 +190,9 @@ IDefinition findProperty(String name, DependencyType dt, boolean favorTypes)
{
def = project.doubleCheckAmbiguousDefinition(scope, name, defs.get(0), defs.get(1));
if (def != null)
{
return def;
}
}
def = AmbiguousDefinition.get();
}
Expand All @@ -215,7 +218,6 @@ IDefinition findProperty(String name, DependencyType dt, boolean favorTypes)
}
}
return result;

}

private ConcurrentMap<String, IDefinition> getScopeChainMap()
Expand Down Expand Up @@ -266,12 +268,10 @@ private ConcurrentMap<QName, IDefinition> getQualifiedScopeChainMap()

/**
* Version of findPropertyQualified that uses a cache. Checks the cache
* first, and only queries the scope if the we don't have a cached result.
* first, and only queries the scope if we don't have a cached result.
*
* @param scope The scope to perform the lookup in
* @param qualifier The namespace qualifier
* @param name Name of the property to find
* @param cache ASDefinitionCache to use for the lookup - this is only used
* to get at the ICompilerProject
* @param dt Which type of dependency to introduce when we do the lookup
* @return The IDefinition for the property, or null if it wasn't found
*/
Expand Down Expand Up @@ -360,7 +360,9 @@ public IDefinition findPropertyMultiname(IResolvedQualifiersReference ref, Depen
ConcurrentMap<IResolvedQualifiersReference, IDefinition> cache = getMultinameLookupMap();
IDefinition result = cache.get(ref);
if (result != null)
{
return result;
}

IDefinition def;

Expand Down Expand Up @@ -728,5 +730,11 @@ public boolean equals(Object o)
}
return false;
}

@Override
public String toString()
{
return ns.toString() + "::" + name;
}
}
}
Loading