mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
return alternative guard analysis if all paths are trivial
This commit is contained in:
parent
5fdb3424ac
commit
7925e2040f
1 changed files with 13 additions and 6 deletions
|
@ -16,29 +16,26 @@ import java.util.LinkedList;
|
|||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.emf.ecore.EStructuralFeature;
|
||||
import org.eclipse.xtext.AbstractElement;
|
||||
import org.eclipse.xtext.AbstractSemanticPredicate;
|
||||
import org.eclipse.xtext.Action;
|
||||
import org.eclipse.xtext.Alternatives;
|
||||
import org.eclipse.xtext.Assignment;
|
||||
import org.eclipse.xtext.GrammarUtil;
|
||||
import org.eclipse.xtext.Group;
|
||||
import org.eclipse.xtext.JavaAction;
|
||||
import org.eclipse.xtext.ParserRule;
|
||||
import org.eclipse.xtext.RuleCall;
|
||||
import org.eclipse.xtext.UnorderedGroup;
|
||||
import org.eclipse.xtext.XtextFactory;
|
||||
import org.eclipse.xtext.XtextPackage;
|
||||
import org.eclipse.xtext.util.Tuples;
|
||||
import static org.eclipse.xtext.GrammarUtil.*;
|
||||
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.AlternativeTokenSequenceGuard;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.AlternativesGuard;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.GroupGuard;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.Guard;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.HoistingGuard;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.MergedPathGuard;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.guards.PathGuard;
|
||||
|
@ -50,8 +47,6 @@ import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.pathAnalysis.Toke
|
|||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.token.Token;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.hoisting.utils.StreamUtils;
|
||||
|
||||
import com.google.common.collect.Streams;
|
||||
|
||||
/**
|
||||
* @author overflow - Initial contribution and API
|
||||
*/
|
||||
|
@ -78,6 +73,18 @@ public class HoistingProcessor {
|
|||
.map(MergedPathGuard::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (guards.stream().allMatch(Guard::isTrivial)) {
|
||||
// all paths are trivial
|
||||
|
||||
// if there is a terminal on all branches set has terminal to true
|
||||
// else we need might need to consider the following tokens in the path
|
||||
if (guards.stream().allMatch(HoistingGuard::hasTerminal)) {
|
||||
return HoistingGuard.terminal();
|
||||
} else {
|
||||
return HoistingGuard.unguarded();
|
||||
}
|
||||
}
|
||||
|
||||
log.info("path identity check");
|
||||
int size = paths.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
|
Loading…
Reference in a new issue