diff --git a/src/org/rascalmpl/library/ParseTree.rsc b/src/org/rascalmpl/library/ParseTree.rsc index eccd3bf4d5f..9f50ba8a83a 100644 --- a/src/org/rascalmpl/library/ParseTree.rsc +++ b/src/org/rascalmpl/library/ParseTree.rsc @@ -365,7 +365,6 @@ bool subtype(\lexical(_), Symbol::\adt("Tree", [])) = true; bool subtype(\layout(_), Symbol::\adt("Tree", [])) = true; bool subtype(\keyword(_), Symbol::\adt("Tree", [])) = true; -bool subtype(\data(parameter(_,_)), adt(_,_)) = true; bool subtype(\syntax(parameter(_,_)), sort(_)) = true; bool subtype(\syntax(parameter(_,_)), \parameterized-sort(_,_)) = true; bool subtype(\lexical(parameter(_,_)), lex(_)) = true; diff --git a/src/org/rascalmpl/semantics/dynamic/SyntaxRoleModifier.java b/src/org/rascalmpl/semantics/dynamic/SyntaxRoleModifier.java index cfc5ea55a80..83189743676 100644 --- a/src/org/rascalmpl/semantics/dynamic/SyntaxRoleModifier.java +++ b/src/org/rascalmpl/semantics/dynamic/SyntaxRoleModifier.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.rascalmpl.semantics.dynamic; -import org.rascalmpl.ast.Name; import org.rascalmpl.interpreter.IEvaluator; import org.rascalmpl.interpreter.env.Environment; import org.rascalmpl.interpreter.result.Result; diff --git a/src/org/rascalmpl/types/ModifySyntaxRole.java b/src/org/rascalmpl/types/ModifySyntaxRole.java index ae3b0a907d9..d382a14285d 100644 --- a/src/org/rascalmpl/types/ModifySyntaxRole.java +++ b/src/org/rascalmpl/types/ModifySyntaxRole.java @@ -112,6 +112,11 @@ public Syntax(Type arg) { super(arg); } + @Override + public String toString() { + return "syntax[" + arg.toString() + "]"; + } + @Override public IConstructor asSymbol(IValueFactory vf, TypeStore store, ISetWriter grammar, Set done) { return vf.constructor(RascalValueFactory.Symbol_SyntaxModifier, arg.asSymbol(vf, store, grammar, done)); @@ -153,6 +158,20 @@ public boolean isSubtypeOfSyntaxModifier(RascalType type) { return type instanceof Syntax; } + @Override + protected boolean isSupertypeOf(RascalType type) { + assert isOpen(); + + if (type instanceof NonTerminalType) { + NonTerminalType nt = (NonTerminalType) type; + IConstructor sym = nt.getSymbol(); + + return SymbolAdapter.isSort(sym) || SymbolAdapter.isParameterizedSort(sym); + } + + return false; + } + @Override public boolean isSubtypeOfNonTerminal(RascalType type) { assert isOpen(); // otherwise we wouldn't be here @@ -248,6 +267,25 @@ public Lexical(Type arg) { super(arg); } + @Override + public String toString() { + return "lexical[" + arg.toString() + "]"; + } + + @Override + protected boolean isSupertypeOf(RascalType type) { + assert isOpen(); + + if (type instanceof NonTerminalType) { + NonTerminalType nt = (NonTerminalType) type; + IConstructor sym = nt.getSymbol(); + + return SymbolAdapter.isLex(sym) || SymbolAdapter.isParameterizedLex(sym); + } + + return false; + } + @Override public boolean isSubtypeOfSyntaxModifier(RascalType type) { assert isOpen(); @@ -382,12 +420,32 @@ public Layout(Type arg) { super(arg); } + @Override + public String toString() { + return "layout[" + arg.toString() + "]"; + } + @Override public boolean isSubtypeOfSyntaxModifier(RascalType type) { assert isOpen(); return type instanceof Layout; } + @Override + protected boolean isSupertypeOf(RascalType type) { + assert isOpen(); + + if (type instanceof NonTerminalType) { + NonTerminalType nt = (NonTerminalType) type; + IConstructor sym = nt.getSymbol(); + + return SymbolAdapter.isLayouts(sym); + } + + return false; + } + + @Override protected Type lubWithModifySyntax(RascalType type) { if (type instanceof Syntax) { @@ -516,6 +574,11 @@ public Keyword(Type arg) { super(arg); } + @Override + public String toString() { + return "keyword[" + arg.toString() + "]"; + } + @Override public IConstructor asSymbol(IValueFactory vf, TypeStore store, ISetWriter grammar, Set done) { return vf.constructor(RascalValueFactory.Symbol_KeywordModifier, arg.asSymbol(vf, store, grammar, done)); @@ -552,6 +615,17 @@ protected Type glbWithModifySyntax(RascalType type) { return tf.voidType(); } + @Override + protected boolean isSupertypeOf(RascalType type) { + if (type instanceof NonTerminalType) { + NonTerminalType nt = (NonTerminalType) type; + IConstructor sym = nt.getSymbol(); + + return SymbolAdapter.isKeyword(sym); + } + + return false; + } @Override public boolean isSubtypeOfSyntaxModifier(RascalType type) { @@ -644,12 +718,24 @@ public Data(Type arg) { super(arg); } + @Override + public String toString() { + return "data[" + arg.toString() + "]"; + } + @Override public boolean isSubtypeOfSyntaxModifier(RascalType type) { assert isOpen(); return type instanceof Data; } + @Override + protected boolean isSupertypeOf(RascalType type) { + assert isOpen(); + // Here is it essential that {@link NonTerminalType#isAbstractData()} returns true. + return type.isAbstractData(); + } + @Override protected Type lubWithModifySyntax(RascalType type) { if (type instanceof Syntax) { @@ -770,6 +856,11 @@ protected Type glbWithAbstractData(Type type) { } } + @Override + public boolean isOpen() { + return arg.isOpen(); + } + @Override protected Type lubWithAbstractData(Type type) { // this is for all the syntax roles that are not data. Data overrides this @@ -787,9 +878,7 @@ protected Type glbWithAbstractData(Type type) { } @Override - protected boolean isSupertypeOf(RascalType type) { - return type.isSubtypeOfSyntaxModifier(this); - } + abstract protected boolean isSupertypeOf(RascalType type); @Override protected boolean isSubtypeOfNode(Type type) { @@ -835,6 +924,9 @@ public Type asAbstractDataType() { @Override abstract public boolean match(Type matched, Map bindings) throws FactTypeUseException; + @Override + abstract public String toString(); + @Override public IValue randomValue(Random random, IValueFactory vf, TypeStore store, Map typeParameters, int maxDepth, int maxBreadth) {