-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Somewhat cleaned up scope joiners. It is not perfect, but it will hav…
…e to do for now. #186
- Loading branch information
jurcovicovam
committed
Jul 1, 2014
1 parent
28d4897
commit fdbffec
Showing
5 changed files
with
107 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 0 additions & 83 deletions
83
src/main/java/com/github/sommeri/less4j/core/compiler/scopes/ScopeManipulation.java
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
src/main/java/com/github/sommeri/less4j/core/compiler/stages/CallerCalleeScopeJoiner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.github.sommeri.less4j.core.compiler.stages; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import com.github.sommeri.less4j.core.compiler.scopes.FullMixinDefinition; | ||
import com.github.sommeri.less4j.core.compiler.scopes.IScope; | ||
import com.github.sommeri.less4j.core.compiler.scopes.ScopeFactory; | ||
import com.github.sommeri.less4j.core.compiler.scopes.view.ScopeView; | ||
|
||
public class CallerCalleeScopeJoiner { | ||
|
||
public ScopeView joinIfIndependentAndPreserveContent(IScope callerScope, IScope bodyScope) { | ||
// locally defined mixin does not require any other action | ||
boolean isLocalImport = bodyScope.seesLocalDataOf(callerScope); | ||
|
||
ScopeView result = null; | ||
if (isLocalImport) { | ||
// we need to copy the whole tree, because this runs inside referenced mixin scope | ||
// snapshot and imported mixin needs to remember the scope as it is now | ||
result = ScopeFactory.createJoinedScopesView(null, bodyScope); | ||
} else { | ||
// since this is non-local import, we need to join reference scope and imported mixins scope | ||
// imported mixin needs to have access to variables defined in caller | ||
result = ScopeFactory.createJoinedScopesView(callerScope, bodyScope); | ||
} | ||
result.saveLocalDataForTheWholeWayUp(); | ||
return result; | ||
} | ||
|
||
public IScope joinIfIndependent(IScope callerScope, IScope bodyScope) { | ||
// locally defined mixin does not require any other action | ||
boolean isLocallyDefined = bodyScope.seesLocalDataOf(callerScope); | ||
|
||
if (isLocallyDefined) { | ||
return bodyScope; | ||
} | ||
|
||
//join scopes | ||
IScope result = ScopeFactory.createJoinedScopesView(callerScope, bodyScope); | ||
return result; | ||
} | ||
|
||
public List<FullMixinDefinition> mixinsToImport(IScope callerScope, IScope calleeScope, List<FullMixinDefinition> unmodifiedMixinsToImport) { | ||
List<FullMixinDefinition> result = new ArrayList<FullMixinDefinition>(); | ||
for (FullMixinDefinition mixinToImport : unmodifiedMixinsToImport) { | ||
boolean isLocalImport = mixinToImport.getScope().seesLocalDataOf(callerScope); | ||
ScopeView newScope = null; | ||
if (isLocalImport) { | ||
// we need to copy the whole tree, because this runs inside referenced mixin scope | ||
// snapshot and imported mixin needs to remember the scope as it is now | ||
newScope = ScopeFactory.createJoinedScopesView(null, mixinToImport.getScope()); | ||
newScope.saveLocalDataForTheWholeWayUp(); | ||
} else { | ||
// since this is non-local import, we need to join reference scope and imported mixins scope | ||
// imported mixin needs to have access to variables defined in caller | ||
newScope = ScopeFactory.createJoinedScopesView(calleeScope, mixinToImport.getScope()); | ||
newScope.saveLocalDataForTheWholeWayUp(); | ||
} | ||
|
||
result.add(new FullMixinDefinition(mixinToImport.getMixin(), newScope)); | ||
} | ||
return result; | ||
} | ||
|
||
public IScope createJoinedScopes(List<IScope> parents, IScope child) { | ||
// this could and maybe should check whether they are local to each other e.g., whther they see each other | ||
// if they are local, parent scope could be skipped | ||
// such logic is not implemented yet | ||
Iterator<IScope> iterator = parents.iterator(); | ||
if (!iterator.hasNext()) | ||
return child; | ||
|
||
IScope result = iterator.next(); | ||
while (iterator.hasNext()) { | ||
IScope next = iterator.next(); | ||
result = ScopeFactory.createJoinedScopesView(result, next); | ||
} | ||
result = ScopeFactory.createJoinedScopesView(result, child); | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters