mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
revert ef25bcbe4c
, no performance increase
This commit is contained in:
parent
bff7b4ec65
commit
053a1c5069
4 changed files with 12 additions and 46 deletions
|
@ -208,12 +208,10 @@ public class ContextPDAProvider implements IContextPDAProvider {
|
|||
} else {
|
||||
try {
|
||||
SerializerPDA rulePda = extract(pda.getStop());
|
||||
rulePda.setGrammar(grammar);
|
||||
result.put(contexts, rulePda);
|
||||
for (ISerState state : actions) {
|
||||
Action action = (Action) state.getGrammarElement();
|
||||
SerializerPDA actionPda = extract(state);
|
||||
actionPda.setGrammar(grammar);
|
||||
actionPdas.put(action, actionPda);
|
||||
actionContexts.putAll(action, contexts);
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ public class ContextPDAProvider implements IContextPDAProvider {
|
|||
}
|
||||
}
|
||||
for (Map.Entry<Action, Collection<SerializerPDA>> action : actionPdas.asMap().entrySet()) {
|
||||
SerializerPDA merged = merge(grammar, new ActionContext(null, action.getKey()), action.getValue());
|
||||
SerializerPDA merged = merge(new ActionContext(null, action.getKey()), action.getValue());
|
||||
Set<Set<Parameter>> parameterPermutations = Sets.newLinkedHashSet();
|
||||
for (ISerializationContext container : actionContexts.get(action.getKey())) {
|
||||
parameterPermutations.add(container.getEnabledBooleanParameters());
|
||||
|
@ -240,13 +238,12 @@ public class ContextPDAProvider implements IContextPDAProvider {
|
|||
return result.create();
|
||||
}
|
||||
|
||||
protected SerializerPDA merge(Grammar grammar, ISerializationContext context, Collection<SerializerPDA> pdas) {
|
||||
protected SerializerPDA merge(ISerializationContext context, Collection<SerializerPDA> pdas) {
|
||||
if (pdas.isEmpty())
|
||||
throw new IllegalStateException();
|
||||
if (pdas.size() == 1)
|
||||
return pdas.iterator().next();
|
||||
SerializerPDA merged = factory.create(null, null);
|
||||
merged.setGrammar(grammar);
|
||||
Map<ISerState, SerializerPDAState> oldToNew = Maps.newHashMap();
|
||||
for (Pda<ISerState, RuleCall> pda : pdas) {
|
||||
oldToNew.put(pda.getStop(), merged.getStop());
|
||||
|
|
|
@ -242,11 +242,9 @@ public class ContextTypePDAProvider implements IContextTypePDAProvider {
|
|||
return collector.getTypes();
|
||||
}
|
||||
|
||||
protected Pda<ISerState, RuleCall> filterByType(Grammar grammar, Pda<ISerState, RuleCall> contextPda, EClass type,
|
||||
Map<ISerState, Integer> distances) {
|
||||
protected Pda<ISerState, RuleCall> filterByType(Pda<ISerState, RuleCall> contextPda, EClass type, Map<ISerState, Integer> distances) {
|
||||
TypeFilter typeFilter = newTypeFilter(type);
|
||||
SerializerPDA pda = pdaUtil.filterEdges(contextPda, typeFilter, distances, factory);
|
||||
pda.setGrammar(grammar);
|
||||
return pda;
|
||||
}
|
||||
|
||||
|
@ -271,7 +269,7 @@ public class ContextTypePDAProvider implements IContextTypePDAProvider {
|
|||
}
|
||||
} else {
|
||||
for (EClass type : types) {
|
||||
Pda<ISerState, RuleCall> filtered = filterByType(grammar, contextPDA, type, distances);
|
||||
Pda<ISerState, RuleCall> filtered = filterByType(contextPDA, type, distances);
|
||||
for (ISerializationContext parent : parents) {
|
||||
TypeContext typeContext = new TypeContext(parent, type);
|
||||
builder.put(typeContext, filtered);
|
||||
|
|
|
@ -168,7 +168,6 @@ public class GrammarPDAProvider implements IGrammarPDAProvider {
|
|||
SerializerParserRuleCfg cfg = new SerializerParserRuleCfg(flattened, entryRule);
|
||||
SerializerParserRuleFollowerFunction ff = new SerializerParserRuleFollowerFunction(cfg);
|
||||
SerializerPDA pda = pdaUtil.create(cfg, ff, new ToOriginal(factory));
|
||||
pda.setGrammar(flattened);
|
||||
// SerializerPDA pda = pdaUtil.create(cfg, ff, factory);
|
||||
return pda;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ package org.eclipse.xtext.serializer.analysis;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.AbstractElement;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.GrammarUtil;
|
||||
import org.eclipse.xtext.RuleCall;
|
||||
import org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch;
|
||||
|
@ -148,7 +147,7 @@ public class SerializerPDA implements Pda<ISerState, RuleCall> {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (grammarElement != null ? grammarElement.hashCode() : 1) + type.ordinal();
|
||||
return (grammarElement != null ? grammarElement.hashCode() : 1) * type.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,8 +182,6 @@ public class SerializerPDA implements Pda<ISerState, RuleCall> {
|
|||
|
||||
protected SerializerPDA.SerializerPDAState start;
|
||||
protected SerializerPDA.SerializerPDAState stop;
|
||||
private String identity = null;
|
||||
private Grammar grammar = null;
|
||||
|
||||
public SerializerPDA(SerializerPDA.SerializerPDAState start, SerializerPDA.SerializerPDAState stop) {
|
||||
super();
|
||||
|
@ -196,8 +193,7 @@ public class SerializerPDA implements Pda<ISerState, RuleCall> {
|
|||
public boolean equals(Object obj) {
|
||||
if (obj == null || obj.getClass() != getClass())
|
||||
return false;
|
||||
SerializerPDA other = (SerializerPDA) obj;
|
||||
return getIdentity().equals(other.getIdentity());
|
||||
return new NfaUtil().equalsIgnoreOrder(this, (SerializerPDA) obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,39 +222,15 @@ public class SerializerPDA implements Pda<ISerState, RuleCall> {
|
|||
public SerializerPDAState getStop() {
|
||||
return stop;
|
||||
}
|
||||
|
||||
public Grammar getGrammar() {
|
||||
return grammar;
|
||||
}
|
||||
|
||||
public void setGrammar(Grammar grammar) {
|
||||
this.grammar = grammar;
|
||||
}
|
||||
|
||||
protected String getIdentity() {
|
||||
if (identity != null) {
|
||||
return identity;
|
||||
}
|
||||
if (grammar == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
final GrammarElementDeclarationOrder order = GrammarElementDeclarationOrder.get(grammar);
|
||||
identity = new NfaUtil().identityString(this, new Function<ISerState, String>() {
|
||||
@Override
|
||||
public String apply(ISerState input) {
|
||||
AbstractElement grammarElement = input.getGrammarElement();
|
||||
if (grammarElement != null) {
|
||||
return order.getElementID(grammarElement) + "_" + input.getType().name();
|
||||
}
|
||||
return input.getType().name();
|
||||
}
|
||||
});
|
||||
return identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getIdentity().hashCode();
|
||||
int r = 0;
|
||||
if (start != null && start.followers != null)
|
||||
for (ISerState s : start.followers)
|
||||
if (s != null)
|
||||
r += s.hashCode();
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue